private function renderViewOptionsDropdown(DifferentialChangesetDetailView $detail, $ref, DifferentialChangeset $changeset)
 {
     $meta = array();
     $qparams = array('ref' => $ref, 'whitespace' => $this->whitespace);
     if ($this->standaloneURI) {
         $uri = new PhutilURI($this->standaloneURI);
         $uri->setQueryParams($uri->getQueryParams() + $qparams);
         $meta['standaloneURI'] = (string) $uri;
     }
     $repository = $this->repository;
     if ($repository) {
         try {
             $meta['diffusionURI'] = (string) $repository->getDiffusionBrowseURIForPath($this->user, $changeset->getAbsoluteRepositoryPath($repository, $this->diff), idx($changeset->getMetadata(), 'line:first'), $this->getBranch());
         } catch (DiffusionSetupException $e) {
             // Ignore
         }
     }
     $change = $changeset->getChangeType();
     if ($this->leftRawFileURI) {
         if ($change != DifferentialChangeType::TYPE_ADD) {
             $uri = new PhutilURI($this->leftRawFileURI);
             $uri->setQueryParams($uri->getQueryParams() + $qparams);
             $meta['leftURI'] = (string) $uri;
         }
     }
     if ($this->rightRawFileURI) {
         if ($change != DifferentialChangeType::TYPE_DELETE && $change != DifferentialChangeType::TYPE_MULTICOPY) {
             $uri = new PhutilURI($this->rightRawFileURI);
             $uri->setQueryParams($uri->getQueryParams() + $qparams);
             $meta['rightURI'] = (string) $uri;
         }
     }
     $user = $this->user;
     if ($user && $repository) {
         $path = ltrim($changeset->getAbsoluteRepositoryPath($repository, $this->diff), '/');
         $line = idx($changeset->getMetadata(), 'line:first', 1);
         $callsign = $repository->getCallsign();
         $editor_link = $user->loadEditorLink($path, $line, $callsign);
         if ($editor_link) {
             $meta['editor'] = $editor_link;
         } else {
             $meta['editorConfigure'] = '/settings/panel/display/';
         }
     }
     $meta['containerID'] = $detail->getID();
     $caret = phutil_tag('span', array('class' => 'caret'), '');
     return javelin_tag('a', array('class' => 'button grey small dropdown', 'meta' => $meta, 'href' => idx($meta, 'detailURI', '#'), 'target' => '_blank', 'sigil' => 'differential-view-options'), array(pht('View Options'), $caret));
 }
 private function buildRawFileResponse(DifferentialChangeset $changeset, $is_new)
 {
     $viewer = $this->getViewer();
     if ($is_new) {
         $key = 'raw:new:phid';
     } else {
         $key = 'raw:old:phid';
     }
     $metadata = $changeset->getMetadata();
     $file = null;
     $phid = idx($metadata, $key);
     if ($phid) {
         $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($phid))->execute();
         if ($file) {
             $file = head($file);
         }
     }
     if (!$file) {
         // This is just building a cache of the changeset content in the file
         // tool, and is safe to run on a read pathway.
         $unguard = AphrontWriteGuard::beginScopedUnguardedWrites();
         if ($is_new) {
             $data = $changeset->makeNewFile();
         } else {
             $data = $changeset->makeOldFile();
         }
         $file = PhabricatorFile::newFromFileData($data, array('name' => $changeset->getFilename(), 'mime-type' => 'text/plain'));
         $metadata[$key] = $file->getPHID();
         $changeset->setMetadata($metadata);
         $changeset->save();
         unset($unguard);
     }
     return $file->getRedirectResponse();
 }
 private function renderViewOptionsDropdown(DifferentialChangesetDetailView $detail, $ref, DifferentialChangeset $changeset)
 {
     $viewer = $this->getViewer();
     $meta = array();
     $qparams = array('ref' => $ref, 'whitespace' => $this->whitespace);
     if ($this->standaloneURI) {
         $uri = new PhutilURI($this->standaloneURI);
         $uri->setQueryParams($uri->getQueryParams() + $qparams);
         $meta['standaloneURI'] = (string) $uri;
     }
     $repository = $this->repository;
     if ($repository) {
         try {
             $meta['diffusionURI'] = (string) $repository->getDiffusionBrowseURIForPath($viewer, $changeset->getAbsoluteRepositoryPath($repository, $this->diff), idx($changeset->getMetadata(), 'line:first'), $this->getBranch());
         } catch (DiffusionSetupException $e) {
             // Ignore
         }
     }
     $change = $changeset->getChangeType();
     if ($this->leftRawFileURI) {
         if ($change != DifferentialChangeType::TYPE_ADD) {
             $uri = new PhutilURI($this->leftRawFileURI);
             $uri->setQueryParams($uri->getQueryParams() + $qparams);
             $meta['leftURI'] = (string) $uri;
         }
     }
     if ($this->rightRawFileURI) {
         if ($change != DifferentialChangeType::TYPE_DELETE && $change != DifferentialChangeType::TYPE_MULTICOPY) {
             $uri = new PhutilURI($this->rightRawFileURI);
             $uri->setQueryParams($uri->getQueryParams() + $qparams);
             $meta['rightURI'] = (string) $uri;
         }
     }
     if ($viewer && $repository) {
         $path = ltrim($changeset->getAbsoluteRepositoryPath($repository, $this->diff), '/');
         $line = idx($changeset->getMetadata(), 'line:first', 1);
         $editor_link = $viewer->loadEditorLink($path, $line, $repository);
         if ($editor_link) {
             $meta['editor'] = $editor_link;
         } else {
             $meta['editorConfigure'] = '/settings/panel/display/';
         }
     }
     $meta['containerID'] = $detail->getID();
     return id(new PHUIButtonView())->setTag('a')->setText(pht('View Options'))->setIcon('fa-bars')->setColor(PHUIButtonView::GREY)->setHref(idx($meta, 'detailURI', '#'))->setMetadata($meta)->addSigil('differential-view-options');
 }