@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve actions for binary files and images in Diffusion

Summary: We currently render something kind of goofy; integrate these with the other actions.

Test Plan: Viewed `aphlict.swf`, some PNG in Diffusion.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7052

+41 -50
+41 -50
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 2 2 3 3 final class DiffusionBrowseFileController extends DiffusionBrowseController { 4 4 5 - private $corpusType = 'text'; 6 - 7 5 private $lintCommit; 8 6 private $lintMessages; 9 7 ··· 71 69 72 70 $this->loadLintMessages(); 73 71 74 - // Build the content of the file. 75 - $corpus = $this->buildCorpus( 76 - $show_blame, 77 - $show_color, 78 - $file_content, 79 - $needs_blame, 80 - $drequest, 81 - $path, 82 - $data); 72 + $binary_uri = null; 73 + if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { 74 + $file = $this->loadFileForData($path, $data); 75 + $file_uri = $file->getBestURI(); 76 + 77 + if ($file->isViewableImage()) { 78 + $corpus = $this->buildImageCorpus($file_uri); 79 + } else { 80 + $corpus = $this->buildBinaryCorpus($file_uri, $data); 81 + $binary_uri = $file_uri; 82 + } 83 + } else { 84 + // Build the content of the file. 85 + $corpus = $this->buildCorpus( 86 + $show_blame, 87 + $show_color, 88 + $file_content, 89 + $needs_blame, 90 + $drequest, 91 + $path, 92 + $data); 93 + } 83 94 84 95 if ($request->isAjax()) { 85 96 return id(new AphrontAjaxResponse())->setContent($corpus); ··· 96 107 $view, 97 108 $drequest, 98 109 $show_blame, 99 - $show_color); 110 + $show_color, 111 + $binary_uri); 100 112 $content[] = $this->buildPropertyView($drequest); 101 113 102 114 $follow = $request->getStr('follow'); ··· 190 202 $path, 191 203 $data) { 192 204 193 - if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { 194 - $file = $this->loadFileForData($path, $data); 195 - $file_uri = $file->getBestURI(); 196 - 197 - if ($file->isViewableImage()) { 198 - $this->corpusType = 'image'; 199 - return $this->buildImageCorpus($file_uri); 200 - } else { 201 - $this->corpusType = 'binary'; 202 - return $this->buildBinaryCorpus($file_uri, $data); 203 - } 204 - } 205 - 206 205 if (!$show_color) { 207 206 $style = 208 207 "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; ··· 309 308 PhabricatorActionListView $view, 310 309 DiffusionRequest $drequest, 311 310 $show_blame, 312 - $show_color) { 311 + $show_color, 312 + $binary_uri) { 313 313 314 314 $viewer = $this->getRequest()->getUser(); 315 315 $base_uri = $this->getRequest()->getRequestURI(); ··· 361 361 ->setUser($viewer) 362 362 ->setRenderAsForm(true)); 363 363 364 - 365 364 $href = null; 366 365 if ($this->getRequest()->getStr('lint') !== null) { 367 366 $lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages)); ··· 386 385 ->setIcon('warning') 387 386 ->setDisabled(!$href)); 388 387 389 - $view->addAction( 390 - id(new PhabricatorActionView()) 391 - ->setName(pht('View Raw File')) 392 - ->setHref($base_uri->alter('view', 'raw')) 393 - ->setIcon('file')); 388 + if ($binary_uri) { 389 + $view->addAction( 390 + id(new PhabricatorActionView()) 391 + ->setName(pht('Download Raw File')) 392 + ->setHref($binary_uri) 393 + ->setIcon('download')); 394 + } else { 395 + $view->addAction( 396 + id(new PhabricatorActionView()) 397 + ->setName(pht('View Raw File')) 398 + ->setHref($base_uri->alter('view', 'raw')) 399 + ->setIcon('file')); 400 + } 394 401 395 402 $view->addAction($this->createEditAction()); 396 403 ··· 820 827 'src' => $file_uri, 821 828 ))); 822 829 823 - $actions = id(new PhabricatorActionListView()) 824 - ->setUser($this->getRequest()->getUser()) 825 - ->setObjectURI($this->getRequest()->getRequestURI()) 826 - ->addAction($this->createEditAction()); 827 - 828 - return array($actions, $properties); 830 + return $properties; 829 831 } 830 832 831 833 private function buildBinaryCorpus($file_uri, $data) { ··· 837 839 'This is a binary file. It is %s byte(s) in length.', 838 840 new PhutilNumber($size))); 839 841 840 - $actions = id(new PhabricatorActionListView()) 841 - ->setUser($this->getRequest()->getUser()) 842 - ->setObjectURI($this->getRequest()->getRequestURI()) 843 - ->addAction($this->createEditAction()) 844 - ->addAction( 845 - id(new PhabricatorActionView()) 846 - ->setName(pht('Download Binary File...')) 847 - ->setIcon('download') 848 - ->setHref($file_uri)); 849 - 850 - return array($actions, $properties); 851 - 842 + return $properties; 852 843 } 853 844 854 845 private function buildBeforeResponse($before) {