@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

Provide a stable URI for getting raw paste content

Summary: Fixes T9312. This is a bit fluff, but does simplify the view controller slightly and seems reasonable/useful in general.

Test Plan: Clicked "View Raw File" on a paste, got redirected to the raw file via a stable URI.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9312

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

+48 -14
+2
src/__phutil_library_map__.php
··· 2510 2510 'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php', 2511 2511 'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php', 2512 2512 'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php', 2513 + 'PhabricatorPasteRawController' => 'applications/paste/controller/PhabricatorPasteRawController.php', 2513 2514 'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php', 2514 2515 'PhabricatorPasteSchemaSpec' => 'applications/paste/storage/PhabricatorPasteSchemaSpec.php', 2515 2516 'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php', ··· 6545 6546 'PhabricatorPasteListController' => 'PhabricatorPasteController', 6546 6547 'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType', 6547 6548 'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6549 + 'PhabricatorPasteRawController' => 'PhabricatorPasteController', 6548 6550 'PhabricatorPasteRemarkupRule' => 'PhabricatorObjectRemarkupRule', 6549 6551 'PhabricatorPasteSchemaSpec' => 'PhabricatorConfigSchemaSpec', 6550 6552 'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
+1
src/applications/paste/application/PhabricatorPasteApplication.php
··· 40 40 '(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController', 41 41 'create/' => 'PhabricatorPasteEditController', 42 42 'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController', 43 + 'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController', 43 44 'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController', 44 45 ), 45 46 );
+39
src/applications/paste/controller/PhabricatorPasteRawController.php
··· 1 + <?php 2 + 3 + /** 4 + * Redirect to the current raw contents of a Paste. 5 + * 6 + * This controller provides a stable URI for getting the current contents of 7 + * a paste, and slightly simplifies the view controller. 8 + */ 9 + final class PhabricatorPasteRawController 10 + extends PhabricatorPasteController { 11 + 12 + public function shouldAllowPublic() { 13 + return true; 14 + } 15 + 16 + public function handleRequest(AphrontRequest $request) { 17 + $viewer = $request->getViewer(); 18 + $id = $request->getURIData('id'); 19 + 20 + $paste = id(new PhabricatorPasteQuery()) 21 + ->setViewer($viewer) 22 + ->withIDs(array($id)) 23 + ->executeOne(); 24 + if (!$paste) { 25 + return new Aphront404Response(); 26 + } 27 + 28 + $file = id(new PhabricatorFileQuery()) 29 + ->setViewer($viewer) 30 + ->withPHIDs(array($paste->getFilePHID())) 31 + ->executeOne(); 32 + if (!$file) { 33 + return new Aphront400Response(); 34 + } 35 + 36 + return $file->getRedirectResponse(); 37 + } 38 + 39 + }
+6 -14
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 42 42 return new Aphront404Response(); 43 43 } 44 44 45 - $file = id(new PhabricatorFileQuery()) 46 - ->setViewer($viewer) 47 - ->withPHIDs(array($paste->getFilePHID())) 48 - ->executeOne(); 49 - if (!$file) { 50 - return new Aphront400Response(); 51 - } 52 - 53 45 $forks = id(new PhabricatorPasteQuery()) 54 46 ->setViewer($viewer) 55 47 ->withParentPHIDs(array($paste->getPHID())) ··· 57 49 $fork_phids = mpull($forks, 'getPHID'); 58 50 59 51 $header = $this->buildHeaderView($paste); 60 - $actions = $this->buildActionView($viewer, $paste, $file); 52 + $actions = $this->buildActionView($viewer, $paste); 61 53 $properties = $this->buildPropertyView($paste, $fork_phids, $actions); 62 54 63 55 $object_box = id(new PHUIObjectBoxView()) ··· 139 131 140 132 private function buildActionView( 141 133 PhabricatorUser $viewer, 142 - PhabricatorPaste $paste, 143 - PhabricatorFile $file) { 134 + PhabricatorPaste $paste) { 144 135 145 136 $can_edit = PhabricatorPolicyFilter::hasCapability( 146 137 $viewer, ··· 148 139 PhabricatorPolicyCapability::CAN_EDIT); 149 140 150 141 $can_fork = $viewer->isLoggedIn(); 151 - $fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID()); 142 + $id = $paste->getID(); 143 + $fork_uri = $this->getApplicationURI('/create/?parent='.$id); 152 144 153 145 return id(new PhabricatorActionListView()) 154 146 ->setUser($viewer) ··· 160 152 ->setIcon('fa-pencil') 161 153 ->setDisabled(!$can_edit) 162 154 ->setWorkflow(!$can_edit) 163 - ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/'))) 155 + ->setHref($this->getApplicationURI("edit/{$id}/"))) 164 156 ->addAction( 165 157 id(new PhabricatorActionView()) 166 158 ->setName(pht('Fork This Paste')) ··· 172 164 id(new PhabricatorActionView()) 173 165 ->setName(pht('View Raw File')) 174 166 ->setIcon('fa-file-text-o') 175 - ->setHref($file->getBestURI())); 167 + ->setHref($this->getApplicationURI("raw/{$id}/"))); 176 168 } 177 169 178 170 private function buildPropertyView(