@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.

Modernize most somewhat-weird Diffusion controllers

Summary: Ref T4245. This gets everything else except serving HTTP requests (complicated) and lint (quite weird).

Test Plan:
- Viewed a diff.
- Viewed externals.
- Viewed history table to see last modified.
- Did path completion and validation in Owners.
- Did tree path search in Diffusion.
- Viewed a repository.
- Created a new repository.
- Looked up symbols.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

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

+110 -114
+17 -5
src/applications/diffusion/controller/DiffusionController.php
··· 67 67 $request = $this->getRequest(); 68 68 $viewer = $this->getViewer(); 69 69 70 - $identifier = $request->getURIData('repositoryCallsign'); 71 - if (!strlen($identifier)) { 72 - $identifier = (int)$request->getURIData('repositoryID'); 73 - } 70 + $identifier = $this->getRepositoryIdentifierFromRequest($request); 74 71 75 72 $params = $options + array( 76 73 'repository' => $identifier, 77 74 'user' => $viewer, 78 - 'blob' => $request->getURIData('dblob'), 75 + 'blob' => $this->getDiffusionBlobFromRequest($request), 79 76 'commit' => $request->getURIData('commit'), 80 77 'path' => $request->getURIData('path'), 81 78 'line' => $request->getURIData('line'), ··· 92 89 $this->diffusionRequest = $drequest; 93 90 94 91 return null; 92 + } 93 + 94 + protected function getDiffusionBlobFromRequest(AphrontRequest $request) { 95 + return $request->getURIData('dblob'); 96 + } 97 + 98 + protected function getRepositoryIdentifierFromRequest( 99 + AphrontRequest $request) { 100 + 101 + $identifier = $request->getURIData('repositoryCallsign'); 102 + if (strlen($identifier)) { 103 + return $identifier; 104 + } 105 + 106 + return (int)$request->getURIData('repositoryID'); 95 107 } 96 108 97 109 protected function processDiffusionRequest(AphrontRequest $request) {
+7 -16
src/applications/diffusion/controller/DiffusionDiffController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function shouldLoadDiffusionRequest() { 10 - return false; 9 + protected function getDiffusionBlobFromRequest(AphrontRequest $request) { 10 + return $request->getStr('ref'); 11 11 } 12 12 13 - protected function processDiffusionRequest(AphrontRequest $request) { 14 - $data = $request->getURIMap(); 15 - $data = $data + array( 16 - 'dblob' => $this->getRequest()->getStr('ref'), 17 - ); 18 - try { 19 - $drequest = DiffusionRequest::newFromAphrontRequestDictionary( 20 - $data, 21 - $request); 22 - } catch (Exception $ex) { 23 - return id(new Aphront404Response()) 24 - ->setRequest($request); 13 + public function handleRequest(AphrontRequest $request) { 14 + $response = $this->loadDiffusionContext(); 15 + if ($response) { 16 + return $response; 25 17 } 26 - $this->setDiffusionRequest($drequest); 27 18 28 - $drequest = $this->getDiffusionRequest(); 29 19 $viewer = $this->getViewer(); 20 + $drequest = $this->getDiffusionRequest(); 30 21 31 22 if (!$request->isAjax()) { 32 23
+12 -14
src/applications/diffusion/controller/DiffusionExternalController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function shouldLoadDiffusionRequest() { 10 - return false; 11 - } 12 - 13 - protected function processDiffusionRequest(AphrontRequest $request) { 14 - 9 + public function handleRequest(AphrontRequest $request) { 15 10 $uri = $request->getStr('uri'); 16 11 $id = $request->getStr('id'); 17 12 ··· 64 59 65 60 if (empty($commits)) { 66 61 $desc = null; 67 - if ($uri) { 68 - $desc = $uri.', at '; 62 + if (strlen($uri)) { 63 + $desc = pht('"%s", at "%s"', $uri, $id); 64 + } else { 65 + $desc = pht('"%s"', $id); 69 66 } 70 - $desc .= $id; 71 67 72 68 $content = id(new PHUIInfoView()) 73 69 ->setTitle(pht('Unknown External')) ··· 135 131 $content->setTable($table); 136 132 } 137 133 138 - return $this->buildApplicationPage( 139 - $content, 140 - array( 141 - 'title' => pht('Unresolvable External'), 142 - )); 134 + $crumbs = $this->buildApplicationCrumbs(); 135 + $crumbs->addTextCrumb(pht('External')); 136 + 137 + return $this->newPage() 138 + ->setTitle(pht('Unresolvable External')) 139 + ->setCrumbs($crumbs) 140 + ->appendChild($content); 143 141 } 144 142 145 143 }
+7 -2
src/applications/diffusion/controller/DiffusionLastModifiedController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 9 + public function handleRequest(AphrontRequest $request) { 10 + $response = $this->loadDiffusionContext(); 11 + if ($response) { 12 + return $response; 13 + } 14 + 15 + $viewer = $this->getViewer(); 10 16 $drequest = $this->getDiffusionRequest(); 11 - $viewer = $request->getUser(); 12 17 13 18 $paths = $request->getStr('paths'); 14 19 try {
+11 -20
src/applications/diffusion/controller/DiffusionPathCompleteController.php
··· 2 2 3 3 final class DiffusionPathCompleteController extends DiffusionController { 4 4 5 - protected function shouldLoadDiffusionRequest() { 6 - return false; 5 + protected function getRepositoryIdentifierFromRequest( 6 + AphrontRequest $request) { 7 + return $request->getStr('repositoryPHID'); 7 8 } 8 9 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 + public function handleRequest(AphrontRequest $request) { 11 + $response = $this->loadDiffusionContext(); 12 + if ($response) { 13 + return $response; 14 + } 10 15 11 - $repository_phid = $request->getStr('repositoryPHID'); 12 - $repository = id(new PhabricatorRepositoryQuery()) 13 - ->setViewer($request->getUser()) 14 - ->withPHIDs(array($repository_phid)) 15 - ->executeOne(); 16 - if (!$repository) { 17 - return new Aphront400Response(); 18 - } 16 + $viewer = $this->getViewer(); 17 + $drequest = $this->getDiffusionRequest(); 19 18 20 19 $query_path = $request->getStr('q'); 21 20 if (preg_match('@/$@', $query_path)) { ··· 25 24 } 26 25 $query_dir = ltrim($query_dir, '/'); 27 26 28 - $drequest = DiffusionRequest::newFromDictionary( 29 - array( 30 - 'user' => $request->getUser(), 31 - 'repository' => $repository, 32 - 'path' => $query_dir, 33 - )); 34 - $this->setDiffusionRequest($drequest); 35 - 36 27 $browse_results = DiffusionBrowseResultSet::newFromConduit( 37 28 $this->callConduitWithDiffusionRequest( 38 29 'diffusion.browsequery', 39 30 array( 40 - 'path' => $drequest->getPath(), 31 + 'path' => $query_dir, 41 32 'commit' => $drequest->getCommit(), 42 33 ))); 43 34 $paths = $browse_results->getPaths();
+8 -2
src/applications/diffusion/controller/DiffusionPathTreeController.php
··· 2 2 3 3 final class DiffusionPathTreeController extends DiffusionController { 4 4 5 - protected function processDiffusionRequest(AphrontRequest $request) { 5 + public function handleRequest(AphrontRequest $request) { 6 + $response = $this->loadDiffusionContext(); 7 + if ($response) { 8 + return $response; 9 + } 10 + 6 11 $drequest = $this->getDiffusionRequest(); 12 + $repository = $drequest->getRepository(); 7 13 8 - if (!$drequest->getRepository()->canUsePathTree()) { 14 + if (!$repository->canUsePathTree()) { 9 15 return new Aphront404Response(); 10 16 } 11 17
+12 -20
src/applications/diffusion/controller/DiffusionPathValidateController.php
··· 2 2 3 3 final class DiffusionPathValidateController extends DiffusionController { 4 4 5 - protected function shouldLoadDiffusionRequest() { 6 - return false; 5 + protected function getRepositoryIdentifierFromRequest( 6 + AphrontRequest $request) { 7 + return $request->getStr('repositoryPHID'); 7 8 } 8 9 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - 11 - $repository_phid = $request->getStr('repositoryPHID'); 12 - $repository = id(new PhabricatorRepositoryQuery()) 13 - ->setViewer($request->getUser()) 14 - ->withPHIDs(array($repository_phid)) 15 - ->executeOne(); 16 - if (!$repository) { 17 - return new Aphront400Response(); 10 + public function handleRequest(AphrontRequest $request) { 11 + $response = $this->loadDiffusionContext(); 12 + if ($response) { 13 + return $response; 18 14 } 19 15 16 + $viewer = $this->getViewer(); 17 + $drequest = $this->getDiffusionRequest(); 18 + $repository = $drequest->getRepository(); 19 + 20 20 $path = $request->getStr('path'); 21 21 $path = ltrim($path, '/'); 22 22 23 - $drequest = DiffusionRequest::newFromDictionary( 24 - array( 25 - 'user' => $request->getUser(), 26 - 'repository' => $repository, 27 - 'path' => $path, 28 - )); 29 - $this->setDiffusionRequest($drequest); 30 - 31 23 $browse_results = DiffusionBrowseResultSet::newFromConduit( 32 24 $this->callConduitWithDiffusionRequest( 33 25 'diffusion.browsequery', 34 26 array( 35 - 'path' => $drequest->getPath(), 27 + 'path' => $path, 36 28 'commit' => $drequest->getCommit(), 37 29 'needValidityOnly' => true, 38 30 )));
+14 -8
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $viewer = $request->getUser(); 9 + public function handleRequest(AphrontRequest $request) { 10 + $response = $this->loadDiffusionContext(); 11 + if ($response) { 12 + return $response; 13 + } 11 14 15 + $viewer = $this->getViewer(); 12 16 $drequest = $this->getDiffusionRequest(); 13 17 $repository = $drequest->getRepository(); 14 18 15 19 $content = array(); 16 20 17 21 $crumbs = $this->buildCrumbs(); 18 - $content[] = $crumbs; 19 22 20 23 $content[] = $this->buildPropertiesTable($drequest->getRepository()); 21 24 ··· 73 76 ->setErrors(array($empty_message)); 74 77 } 75 78 76 - return $this->buildApplicationPage( 77 - $content, 78 - array( 79 - 'title' => $drequest->getRepository()->getName(), 80 - )); 79 + return $this->newPage() 80 + ->setTitle( 81 + array( 82 + $repository->getName(), 83 + $repository->getDisplayName(), 84 + )) 85 + ->setCrumbs($crumbs) 86 + ->appendChild($content); 81 87 } 82 88 83 89
+6 -10
src/applications/diffusion/controller/DiffusionRepositoryNewController.php
··· 2 2 3 3 final class DiffusionRepositoryNewController extends DiffusionController { 4 4 5 - protected function processDiffusionRequest(AphrontRequest $request) { 6 - $viewer = $request->getUser(); 5 + public function handleRequest(AphrontRequest $request) { 6 + $viewer = $this->getViewer(); 7 7 8 8 $this->requireApplicationCapability( 9 9 DiffusionCreateRepositoriesCapability::CAPABILITY); ··· 70 70 ->setHeaderText(pht('Create or Import Repository')) 71 71 ->setForm($form); 72 72 73 - return $this->buildApplicationPage( 74 - array( 75 - $crumbs, 76 - $form_box, 77 - ), 78 - array( 79 - 'title' => pht('New Repository'), 80 - )); 73 + return $this->newPage() 74 + ->setTitle(pht('New Repository')) 75 + ->setCrumbs($crumbs) 76 + ->appendChild($form_box); 81 77 } 82 78 83 79 }
+16 -17
src/applications/diffusion/controller/DiffusionSymbolController.php
··· 2 2 3 3 final class DiffusionSymbolController extends DiffusionController { 4 4 5 - private $name; 6 - 7 - protected function processDiffusionRequest(AphrontRequest $request) { 8 - $user = $request->getUser(); 9 - $this->name = $request->getURIData('name'); 5 + public function handleRequest(AphrontRequest $request) { 6 + $viewer = $this->getViewer(); 7 + $name = $request->getURIData('name'); 10 8 11 9 $query = id(new DiffusionSymbolQuery()) 12 - ->setViewer($user) 13 - ->setName($this->name); 10 + ->setViewer($viewer) 11 + ->setName($name); 14 12 15 13 if ($request->getStr('context')) { 16 14 $query->setContext($request->getStr('context')); ··· 48 46 $symbols = $query->execute(); 49 47 50 48 51 - 52 49 $external_query = id(new DiffusionExternalSymbolQuery()) 53 - ->withNames(array($this->name)); 50 + ->withNames(array($name)); 54 51 55 52 if ($request->getStr('context')) { 56 53 $external_query->withContexts(array($request->getStr('context'))); ··· 137 134 $table->setNoDataString( 138 135 pht('No matching symbol could be found in any indexed repository.')); 139 136 140 - $panel = new PHUIObjectBoxView(); 141 - $panel->setHeaderText(pht('Similar Symbols')); 142 - $panel->setTable($table); 137 + $panel = id(new PHUIObjectBoxView()) 138 + ->setHeaderText(pht('Similar Symbols')) 139 + ->setTable($table); 143 140 144 - return $this->buildApplicationPage( 145 - $panel, 146 - array( 147 - 'title' => pht('Find Symbol'), 148 - )); 141 + $crumbs = $this->buildApplicationCrumbs(); 142 + $crumbs->addTextCrumb(pht('Find Symbol')); 143 + 144 + return $this->newPage() 145 + ->setTitle(pht('Find Symbol')) 146 + ->setCrumbs($crumbs) 147 + ->appendChild($panel); 149 148 } 150 149 151 150 }