@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

Modernize more Diffusion controllers

Summary: Ref T4245. Standardize how context is read, minor updates / modernizations / consistency tweaks.

Test Plan:
- Viewed a change.
- Viewed brnaches.
- Edited a commit.
- Viewed tags.
- Viewed history.
- Added, edited and deleted a mirror.
- Viewed push events.
- Viewed a particular event.
- Viewed ref disambiguation.
- Viewed repository list.
- Ran automation test.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

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

+144 -149
+20 -12
src/applications/diffusion/controller/DiffusionChangeController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $drequest = $this->diffusionRequest; 11 - $viewer = $request->getUser(); 9 + public function handleRequest(AphrontRequest $request) { 10 + $response = $this->loadDiffusionContext(); 11 + if ($response) { 12 + return $response; 13 + } 14 + 15 + $viewer = $this->getViewer(); 16 + $drequest = $this->getDiffusionRequest(); 12 17 13 18 $content = array(); 14 19 ··· 89 94 ->setHeader($header) 90 95 ->addPropertyList($properties); 91 96 92 - return $this->buildApplicationPage( 93 - array( 94 - $crumbs, 95 - $object_box, 96 - $content, 97 - ), 98 - array( 99 - 'title' => pht('Change'), 100 - )); 97 + return $this->newPage() 98 + ->setTitle( 99 + array( 100 + basename($drequest->getPath()), 101 + $repository->getDisplayName(), 102 + )) 103 + ->setCrumbs($crumbs) 104 + ->appendChild( 105 + array( 106 + $object_box, 107 + $content, 108 + )); 101 109 } 102 110 103 111 private function buildActionView(DiffusionRequest $drequest) {
+6 -1
src/applications/diffusion/controller/DiffusionCommitBranchesController.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 + 10 15 $drequest = $this->getDiffusionRequest(); 11 16 $repository = $drequest->getRepository(); 12 17
+30 -29
src/applications/diffusion/controller/DiffusionCommitEditController.php
··· 2 2 3 3 final class DiffusionCommitEditController extends DiffusionController { 4 4 5 - protected function processDiffusionRequest(AphrontRequest $request) { 6 - $user = $request->getUser(); 7 - $drequest = $this->getDiffusionRequest(); 5 + public function handleRequest(AphrontRequest $request) { 6 + $response = $this->loadDiffusionContext(); 7 + if ($response) { 8 + return $response; 9 + } 10 + 11 + $viewer = $this->getViewer(); 12 + $drequest = $this->getDiffusionRequest(); 8 13 $repository = $drequest->getRepository(); 9 - $commit = $drequest->loadCommit(); 10 - $data = $commit->loadCommitData(); 11 - $page_title = pht('Edit Diffusion Commit'); 14 + $commit = $drequest->loadCommit(); 12 15 13 16 if (!$commit) { 14 17 return new Aphront404Response(); 15 18 } 16 19 20 + $data = $commit->loadCommitData(); 21 + $page_title = pht('Edit Diffusion Commit'); 22 + 17 23 $commit_phid = $commit->getPHID(); 18 24 $edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 19 25 $current_proj_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( ··· 27 33 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 28 34 ->setMetadataValue('edge:type', $edge_type) 29 35 ->setNewValue(array('=' => array_fuse($proj_phids))); 36 + 30 37 $editor = id(new PhabricatorAuditEditor()) 31 - ->setActor($user) 38 + ->setActor($viewer) 32 39 ->setContinueOnNoEffect(true) 33 40 ->setContentSourceFromRequest($request); 34 - $xactions = $editor->applyTransactions($commit, $xactions); 41 + 42 + $editor->applyTransactions($commit, $xactions); 43 + 35 44 return id(new AphrontRedirectResponse()) 36 45 ->setURI($commit->getURI()); 37 46 } 38 47 39 48 $tokenizer_id = celerity_generate_unique_node_id(); 40 49 $form = id(new AphrontFormView()) 41 - ->setUser($user) 50 + ->setUser($viewer) 42 51 ->setAction($request->getRequestURI()->getPath()) 43 52 ->appendControl( 44 53 id(new AphrontFormTokenizerControl()) ··· 87 96 ->setValue(array($desc, " \xC2\xB7 ", $doc_link))); 88 97 } 89 98 99 + $form->appendControl( 100 + id(new AphrontFormSubmitControl()) 101 + ->setValue(pht('Save')) 102 + ->addCancelButton($commit->getURI())); 90 103 91 - Javelin::initBehavior('project-create', array( 92 - 'tokenizerID' => $tokenizer_id, 93 - )); 94 - 95 - $submit = id(new AphrontFormSubmitControl()) 96 - ->setValue(pht('Save')) 97 - ->addCancelButton($commit->getURI()); 98 - $form->appendChild($submit); 99 - 100 - $crumbs = $this->buildCrumbs(array( 101 - 'commit' => true, 102 - )); 104 + $crumbs = $this->buildCrumbs( 105 + array( 106 + 'commit' => true, 107 + )); 103 108 $crumbs->addTextCrumb(pht('Edit')); 104 109 105 110 $form_box = id(new PHUIObjectBoxView()) 106 111 ->setHeaderText($page_title) 107 112 ->setForm($form); 108 113 109 - return $this->buildApplicationPage( 110 - array( 111 - $crumbs, 112 - $form_box, 113 - ), 114 - array( 115 - 'title' => $page_title, 116 - )); 114 + return $this->newPage() 115 + ->setTitle($page_title) 116 + ->setCrumbs($crumbs) 117 + ->appendChild($form_box); 117 118 } 118 119 119 120 }
+6 -1
src/applications/diffusion/controller/DiffusionCommitTagsController.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 + 10 15 $drequest = $this->getDiffusionRequest(); 11 16 $repository = $drequest->getRepository(); 12 17
+26 -28
src/applications/diffusion/controller/DiffusionHistoryController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $drequest = $this->diffusionRequest; 11 - $viewer = $request->getUser(); 9 + public function handleRequest(AphrontRequest $request) { 10 + $response = $this->loadDiffusionContext(); 11 + if ($response) { 12 + return $response; 13 + } 14 + 15 + $viewer = $this->getViewer(); 16 + $drequest = $this->getDiffusionRequest(); 12 17 $repository = $drequest->getRepository(); 13 18 14 - $page_size = $request->getInt('pagesize', 100); 15 - $offset = $request->getInt('offset', 0); 19 + $pager = id(new PHUIPagerView()) 20 + ->readFromRequest($request); 16 21 17 22 $params = array( 18 23 'commit' => $drequest->getCommit(), 19 24 'path' => $drequest->getPath(), 20 - 'offset' => $offset, 21 - 'limit' => $page_size + 1, 25 + 'offset' => $pager->getOffset(), 26 + 'limit' => $pager->getPageSize() + 1, 22 27 ); 23 28 24 29 if (!$request->getBool('copies')) { ··· 32 37 $history = DiffusionPathChange::newFromConduit( 33 38 $history_results['pathChanges']); 34 39 35 - $pager = new PHUIPagerView(); 36 - $pager->setPageSize($page_size); 37 - $pager->setOffset($offset); 38 40 $history = $pager->sliceResults($history); 39 - 40 - $pager->setURI($request->getRequestURI(), 'offset'); 41 41 42 42 $show_graph = !strlen($drequest->getPath()); 43 43 $content = array(); ··· 51 51 52 52 if ($show_graph) { 53 53 $history_table->setParents($history_results['parents']); 54 - $history_table->setIsHead($offset == 0); 54 + $history_table->setIsHead(!$pager->getOffset()); 55 55 } 56 56 57 57 $history_panel = new PHUIObjectBoxView(); ··· 79 79 'view' => 'history', 80 80 )); 81 81 82 - $pager = id(new PHUIBoxView()) 83 - ->addClass('ml') 84 - ->appendChild($pager); 82 + $pager_box = $this->renderTablePagerBox($pager); 85 83 86 - return $this->buildApplicationPage( 87 - array( 88 - $crumbs, 89 - $object_box, 90 - $content, 91 - $pager, 92 - ), 93 - array( 94 - 'title' => array( 84 + return $this->newPage() 85 + ->setTitle( 86 + array( 95 87 pht('History'), 96 - $drequest->getRepository()->getDisplayName(), 97 - ), 98 - )); 88 + $repository->getDisplayName(), 89 + )) 90 + ->setCrumbs($crumbs) 91 + ->appendChild( 92 + array( 93 + $object_box, 94 + $content, 95 + $pager_box, 96 + )); 99 97 } 100 98 101 99 private function buildActionView(DiffusionRequest $drequest) {
+8 -3
src/applications/diffusion/controller/DiffusionMirrorDeleteController.php
··· 3 3 final class DiffusionMirrorDeleteController 4 4 extends DiffusionController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContext(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 16 $mirror = id(new PhabricatorRepositoryMirrorQuery())
+8 -3
src/applications/diffusion/controller/DiffusionMirrorEditController.php
··· 3 3 final class DiffusionMirrorEditController 4 4 extends DiffusionController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContext(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 16 PhabricatorPolicyFilter::requireCapability(
+11 -12
src/applications/diffusion/controller/DiffusionPushEventViewController.php
··· 7 7 return true; 8 8 } 9 9 10 - protected function processDiffusionRequest(AphrontRequest $request) { 11 - $viewer = $request->getUser(); 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $this->getViewer(); 12 12 13 13 $event = id(new PhabricatorRepositoryPushEventQuery()) 14 14 ->setViewer($viewer) ··· 57 57 ->setHeaderText(pht('All Pushed Updates')) 58 58 ->setTable($updates_table); 59 59 60 - return $this->buildApplicationPage( 61 - array( 62 - $crumbs, 63 - $detail_box, 64 - $commits_box, 65 - $update_box, 66 - ), 67 - array( 68 - 'title' => $title, 69 - )); 60 + return $this->newPage() 61 + ->setTitle($title) 62 + ->setCrumbs($crumbs) 63 + ->appendChild( 64 + array( 65 + $detail_box, 66 + $commits_box, 67 + $update_box, 68 + )); 70 69 } 71 70 72 71 private function buildPropertyList(PhabricatorRepositoryPushEvent $event) {
+4 -23
src/applications/diffusion/controller/DiffusionPushLogListController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $request = $this->getRequest(); 11 - $controller = id(new PhabricatorApplicationSearchController()) 12 - ->setQueryKey($request->getURIData('queryKey')) 13 - ->setSearchEngine(new PhabricatorRepositoryPushLogSearchEngine()) 14 - ->setNavigation($this->buildSideNavView()); 15 - 16 - return $this->delegateToController($controller); 17 - } 18 - 19 - public function buildSideNavView($for_app = false) { 20 - $viewer = $this->getRequest()->getUser(); 21 - 22 - $nav = new AphrontSideNavFilterView(); 23 - $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 24 - 25 - id(new PhabricatorRepositoryPushLogSearchEngine()) 26 - ->setViewer($viewer) 27 - ->addNavigationItems($nav->getMenu()); 28 - 29 - $nav->selectFilter(null); 30 - 31 - return $nav; 9 + public function handleRequest(AphrontRequest $request) { 10 + return id(new PhabricatorRepositoryPushLogSearchEngine()) 11 + ->setController($this) 12 + ->buildResponse(); 32 13 } 33 14 34 15 }
+14 -13
src/applications/diffusion/controller/DiffusionRefTableController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $viewer = $this->getViewer(); 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 ··· 132 136 $crumbs = $this->buildCrumbs(array()); 133 137 $crumbs->addTextCrumb(pht('Refs')); 134 138 135 - return $this->buildApplicationPage( 136 - array( 137 - $crumbs, 138 - $content, 139 - ), 140 - array( 141 - 'title' => array( 142 - pht('Refs'), 143 - $repository->getMonogram(), 139 + return $this->newPage() 140 + ->setTitle( 141 + array( 144 142 $ref_name, 145 - ), 146 - )); 143 + pht('Ref'), 144 + $repository->getDisplayName(), 145 + )) 146 + ->setCrumbs($crumbs) 147 + ->appendChild($content); 147 148 } 148 149 149 150 }
+4 -22
src/applications/diffusion/controller/DiffusionRepositoryListController.php
··· 6 6 return true; 7 7 } 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 10 - $controller = id(new PhabricatorApplicationSearchController()) 11 - ->setQueryKey($request->getURIData('queryKey')) 12 - ->setSearchEngine(new PhabricatorRepositorySearchEngine()) 13 - ->setNavigation($this->buildSideNavView()); 14 - 15 - return $this->delegateToController($controller); 16 - } 17 - 18 - public function buildSideNavView($for_app = false) { 19 - $viewer = $this->getRequest()->getUser(); 20 - 21 - $nav = new AphrontSideNavFilterView(); 22 - $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 23 - 24 - id(new PhabricatorRepositorySearchEngine()) 25 - ->setViewer($viewer) 26 - ->addNavigationItems($nav->getMenu()); 27 - 28 - $nav->selectFilter(null); 29 - 30 - return $nav; 9 + public function handleRequest(AphrontRequest $request) { 10 + return id(new PhabricatorRepositorySearchEngine()) 11 + ->setController($this) 12 + ->buildResponse(); 31 13 } 32 14 33 15 protected function buildApplicationCrumbs() {
+7 -2
src/applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php
··· 3 3 final class DiffusionRepositoryTestAutomationController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContext(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 7 12 $viewer = $this->getViewer(); 8 - $drequest = $this->diffusionRequest; 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 16 $repository = id(new PhabricatorRepositoryQuery())