@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 organization of Diffusion browse controllers

Summary:
Currently we have this:

- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)

Instead, do this:

- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)

Feels a lot cleaner.

Test Plan: Looked at directories, searches, and files.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

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

+389 -353
+7 -1
src/__phutil_library_map__.php
··· 433 433 'DiffusionBranchTableController' => 'applications/diffusion/controller/DiffusionBranchTableController.php', 434 434 'DiffusionBranchTableView' => 'applications/diffusion/view/DiffusionBranchTableView.php', 435 435 'DiffusionBrowseController' => 'applications/diffusion/controller/DiffusionBrowseController.php', 436 + 'DiffusionBrowseDirectoryController' => 'applications/diffusion/controller/DiffusionBrowseDirectoryController.php', 436 437 'DiffusionBrowseFileController' => 'applications/diffusion/controller/DiffusionBrowseFileController.php', 438 + 'DiffusionBrowseMainController' => 'applications/diffusion/controller/DiffusionBrowseMainController.php', 437 439 'DiffusionBrowseResultSet' => 'applications/diffusion/data/DiffusionBrowseResultSet.php', 440 + 'DiffusionBrowseSearchController' => 'applications/diffusion/controller/DiffusionBrowseSearchController.php', 438 441 'DiffusionBrowseTableView' => 'applications/diffusion/view/DiffusionBrowseTableView.php', 439 442 'DiffusionChangeController' => 'applications/diffusion/controller/DiffusionChangeController.php', 440 443 'DiffusionCommentListView' => 'applications/diffusion/view/DiffusionCommentListView.php', ··· 2498 2501 'DiffusionBranchTableController' => 'DiffusionController', 2499 2502 'DiffusionBranchTableView' => 'DiffusionView', 2500 2503 'DiffusionBrowseController' => 'DiffusionController', 2501 - 'DiffusionBrowseFileController' => 'DiffusionController', 2504 + 'DiffusionBrowseDirectoryController' => 'DiffusionBrowseController', 2505 + 'DiffusionBrowseFileController' => 'DiffusionBrowseController', 2506 + 'DiffusionBrowseMainController' => 'DiffusionBrowseController', 2507 + 'DiffusionBrowseSearchController' => 'DiffusionBrowseController', 2502 2508 'DiffusionBrowseTableView' => 'DiffusionView', 2503 2509 'DiffusionChangeController' => 'DiffusionController', 2504 2510 'DiffusionCommentListView' => 'AphrontView',
+1 -1
src/applications/diffusion/application/PhabricatorApplicationDiffusion.php
··· 50 50 'repository/(?P<dblob>.*)' => 'DiffusionRepositoryController', 51 51 'change/(?P<dblob>.*)' => 'DiffusionChangeController', 52 52 'history/(?P<dblob>.*)' => 'DiffusionHistoryController', 53 - 'browse/(?P<dblob>.*)' => 'DiffusionBrowseController', 53 + 'browse/(?P<dblob>.*)' => 'DiffusionBrowseMainController', 54 54 'lastmodified/(?P<dblob>.*)' => 'DiffusionLastModifiedController', 55 55 'diff/' => 'DiffusionDiffController', 56 56 'tags/(?P<dblob>.*)' => 'DiffusionTagListController',
+100 -217
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 1 1 <?php 2 2 3 - final class DiffusionBrowseController extends DiffusionController { 4 - 5 - public function processRequest() { 6 - $drequest = $this->diffusionRequest; 7 - $is_file = false; 8 - 9 - if ($this->getRequest()->getStr('before')) { 10 - $is_file = true; 11 - } else if ($this->getRequest()->getStr('grep') == '') { 12 - $results = DiffusionBrowseResultSet::newFromConduit( 13 - $this->callConduitWithDiffusionRequest( 14 - 'diffusion.browsequery', 15 - array( 16 - 'path' => $drequest->getPath(), 17 - 'commit' => $drequest->getCommit(), 18 - ))); 19 - $reason = $results->getReasonForEmptyResultSet(); 20 - $is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE); 21 - } 22 - 23 - if ($is_file) { 24 - $controller = new DiffusionBrowseFileController($this->getRequest()); 25 - $controller->setDiffusionRequest($drequest); 26 - $controller->setCurrentApplication($this->getCurrentApplication()); 27 - return $this->delegateToController($controller); 28 - } 29 - 30 - $content = array(); 31 - 32 - $content[] = $this->buildHeaderView($drequest); 33 - $content[] = $this->buildBrowseActionView($drequest); 34 - $content[] = $this->buildPropertyView($drequest); 35 - 36 - $content[] = $this->renderSearchForm(); 37 - 38 - if ($this->getRequest()->getStr('grep') != '') { 39 - $content[] = $this->renderSearchResults(); 40 - } else { 41 - if (!$results->isValidResults()) { 42 - $empty_result = new DiffusionEmptyResultView(); 43 - $empty_result->setDiffusionRequest($drequest); 44 - $empty_result->setDiffusionBrowseResultSet($results); 45 - $empty_result->setView($this->getRequest()->getStr('view')); 46 - $content[] = $empty_result; 47 - } else { 48 - $phids = array(); 49 - foreach ($results->getPaths() as $result) { 50 - $data = $result->getLastCommitData(); 51 - if ($data) { 52 - if ($data->getCommitDetail('authorPHID')) { 53 - $phids[$data->getCommitDetail('authorPHID')] = true; 54 - } 55 - } 56 - } 57 - 58 - $phids = array_keys($phids); 59 - $handles = $this->loadViewerHandles($phids); 60 - 61 - $browse_table = new DiffusionBrowseTableView(); 62 - $browse_table->setDiffusionRequest($drequest); 63 - $browse_table->setHandles($handles); 64 - $browse_table->setPaths($results->getPaths()); 65 - $browse_table->setUser($this->getRequest()->getUser()); 66 - 67 - $browse_panel = new AphrontPanelView(); 68 - $browse_panel->appendChild($browse_table); 69 - $browse_panel->setNoBackground(); 70 - 71 - $content[] = $browse_panel; 72 - } 73 - 74 - $content[] = $this->buildOpenRevisions(); 3 + abstract class DiffusionBrowseController extends DiffusionController { 75 4 76 - $readme = $this->callConduitWithDiffusionRequest( 77 - 'diffusion.readmequery', 78 - array( 79 - 'paths' => $results->getPathDicts(), 80 - )); 81 - if ($readme) { 82 - $box = new PHUIBoxView(); 83 - $box->setShadow(true); 84 - $box->appendChild($readme); 85 - $box->addPadding(PHUI::PADDING_LARGE); 86 - $box->addMargin(PHUI::MARGIN_LARGE); 87 - 88 - $header = id(new PHUIHeaderView()) 89 - ->setHeader(pht('README')); 90 - 91 - $content[] = array( 92 - $header, 93 - $box, 94 - ); 95 - } 96 - } 97 - 98 - $crumbs = $this->buildCrumbs( 99 - array( 100 - 'branch' => true, 101 - 'path' => true, 102 - 'view' => 'browse', 103 - )); 104 - 105 - return $this->buildApplicationPage( 106 - array( 107 - $crumbs, 108 - $content, 109 - ), 110 - array( 111 - 'device' => true, 112 - 'title' => array( 113 - nonempty(basename($drequest->getPath()), '/'), 114 - $drequest->getRepository()->getCallsign().' Repository', 115 - ), 116 - )); 117 - } 118 - 119 - 120 - private function renderSearchForm() { 5 + protected function renderSearchForm($collapsed) { 121 6 $drequest = $this->getDiffusionRequest(); 122 7 $form = id(new AphrontFormView()) 123 8 ->setUser($this->getRequest()->getUser()) ··· 145 30 $filter = new AphrontListFilterView(); 146 31 $filter->appendChild($form); 147 32 148 - if (!strlen($this->getRequest()->getStr('grep'))) { 33 + if ($collapsed) { 149 34 $filter->setCollapsed( 150 35 pht('Show Search'), 151 36 pht('Hide Search'), ··· 156 41 return $filter; 157 42 } 158 43 159 - private function renderSearchResults() { 160 - $drequest = $this->getDiffusionRequest(); 161 - $repository = $drequest->getRepository(); 162 - $results = array(); 163 - $no_data = pht('No results found.'); 164 - 165 - $limit = 100; 166 - $page = $this->getRequest()->getInt('page', 0); 167 - $pager = new AphrontPagerView(); 168 - $pager->setPageSize($limit); 169 - $pager->setOffset($page); 170 - $pager->setURI($this->getRequest()->getRequestURI(), 'page'); 171 - 172 - try { 173 - 174 - $results = $this->callConduitWithDiffusionRequest( 175 - 'diffusion.searchquery', 176 - array( 177 - 'grep' => $this->getRequest()->getStr('grep'), 178 - 'stableCommitName' => $drequest->getStableCommitName(), 179 - 'path' => $drequest->getPath(), 180 - 'limit' => $limit + 1, 181 - 'offset' => $page)); 182 - 183 - } catch (ConduitException $ex) { 184 - $err = $ex->getErrorDescription(); 185 - if ($err != '') { 186 - return id(new AphrontErrorView()) 187 - ->setTitle(pht('Search Error')) 188 - ->appendChild($err); 189 - } 190 - } 191 - 192 - $results = $pager->sliceResults($results); 193 - 194 - require_celerity_resource('syntax-highlighting-css'); 195 - 196 - // NOTE: This can be wrong because we may find the string inside the 197 - // comment. But it's correct in most cases and highlighting the whole file 198 - // would be too expensive. 199 - $futures = array(); 200 - $engine = PhabricatorSyntaxHighlighter::newEngine(); 201 - foreach ($results as $result) { 202 - list($path, $line, $string) = $result; 203 - $futures["{$path}:{$line}"] = $engine->getHighlightFuture( 204 - $engine->getLanguageFromFilename($path), 205 - ltrim($string)); 206 - } 207 - 208 - try { 209 - Futures($futures)->limit(8)->resolveAll(); 210 - } catch (PhutilSyntaxHighlighterException $ex) { 211 - } 212 - 213 - $rows = array(); 214 - foreach ($results as $result) { 215 - list($path, $line, $string) = $result; 216 - 217 - $href = $drequest->generateURI(array( 218 - 'action' => 'browse', 219 - 'path' => $path, 220 - 'line' => $line, 221 - )); 222 - 223 - try { 224 - $string = $futures["{$path}:{$line}"]->resolve(); 225 - } catch (PhutilSyntaxHighlighterException $ex) { 226 - } 227 - 228 - $string = phutil_tag( 229 - 'pre', 230 - array('class' => 'PhabricatorMonospaced'), 231 - $string); 232 - 233 - $path = Filesystem::readablePath($path, $drequest->getPath()); 234 - 235 - $rows[] = array( 236 - phutil_tag('a', array('href' => $href), $path), 237 - $line, 238 - $string, 239 - ); 240 - } 241 - 242 - $table = id(new AphrontTableView($rows)) 243 - ->setClassName('remarkup-code') 244 - ->setHeaders(array(pht('Path'), pht('Line'), pht('String'))) 245 - ->setColumnClasses(array('', 'n', 'wide')) 246 - ->setNoDataString($no_data); 247 - 248 - return id(new AphrontPanelView()) 249 - ->setNoBackground(true) 250 - ->appendChild($table) 251 - ->appendChild($pager); 252 - } 253 - 254 - 255 - private function markupText($text) { 44 + protected function markupText($text) { 256 45 $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine(); 257 46 $engine->setConfig('viewer', $this->getRequest()->getUser()); 258 47 $text = $engine->markupText($text); ··· 267 56 return $text; 268 57 } 269 58 270 - private function buildHeaderView(DiffusionRequest $drequest) { 59 + protected function buildHeaderView(DiffusionRequest $drequest) { 271 60 $viewer = $this->getRequest()->getUser(); 272 61 273 62 $header = id(new PHUIHeaderView()) ··· 278 67 return $header; 279 68 } 280 69 281 - private function buildPropertyView(DiffusionRequest $drequest) { 70 + protected function buildActionView(DiffusionRequest $drequest) { 71 + $viewer = $this->getRequest()->getUser(); 72 + 73 + $view = id(new PhabricatorActionListView()) 74 + ->setUser($viewer); 75 + 76 + $history_uri = $drequest->generateURI( 77 + array( 78 + 'action' => 'history', 79 + )); 80 + 81 + $view->addAction( 82 + id(new PhabricatorActionView()) 83 + ->setName(pht('View History')) 84 + ->setHref($history_uri) 85 + ->setIcon('perflab')); 86 + 87 + $behind_head = $drequest->getRawCommit(); 88 + $head_uri = $drequest->generateURI( 89 + array( 90 + 'commit' => '', 91 + 'action' => 'browse', 92 + )); 93 + $view->addAction( 94 + id(new PhabricatorActionView()) 95 + ->setName(pht('Jump to HEAD')) 96 + ->setHref($head_uri) 97 + ->setIcon('home') 98 + ->setDisabled(!$behind_head)); 99 + 100 + // TODO: Ideally, this should live in Owners and be event-triggered, but 101 + // there's no reasonable object for it to react to right now. 102 + 103 + $owners_uri = id(new PhutilURI('/owners/view/search/')) 104 + ->setQueryParams( 105 + array( 106 + 'repository' => $drequest->getCallsign(), 107 + 'path' => '/'.$drequest->getPath(), 108 + )); 109 + 110 + $view->addAction( 111 + id(new PhabricatorActionView()) 112 + ->setName(pht('Find Owners')) 113 + ->setHref((string)$owners_uri) 114 + ->setIcon('preview')); 115 + 116 + return $view; 117 + } 118 + 119 + protected function buildPropertyView(DiffusionRequest $drequest) { 282 120 $viewer = $this->getRequest()->getUser(); 283 121 284 122 $view = id(new PhabricatorPropertyListView()) ··· 310 148 } 311 149 312 150 return $view; 151 + } 152 + 153 + protected function buildOpenRevisions() { 154 + $user = $this->getRequest()->getUser(); 155 + 156 + $drequest = $this->getDiffusionRequest(); 157 + $repository = $drequest->getRepository(); 158 + $path = $drequest->getPath(); 159 + 160 + $path_map = id(new DiffusionPathIDQuery(array($path)))->loadPathIDs(); 161 + $path_id = idx($path_map, $path); 162 + if (!$path_id) { 163 + return null; 164 + } 165 + 166 + $revisions = id(new DifferentialRevisionQuery()) 167 + ->setViewer($user) 168 + ->withPath($repository->getID(), $path_id) 169 + ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 170 + ->setOrder(DifferentialRevisionQuery::ORDER_PATH_MODIFIED) 171 + ->setLimit(10) 172 + ->needRelationships(true) 173 + ->execute(); 174 + 175 + if (!$revisions) { 176 + return null; 177 + } 178 + 179 + $view = id(new DifferentialRevisionListView()) 180 + ->setRevisions($revisions) 181 + ->setFields(DifferentialRevisionListView::getDefaultFields($user)) 182 + ->setUser($user) 183 + ->loadAssets(); 184 + 185 + $phids = $view->getRequiredHandlePHIDs(); 186 + $handles = $this->loadViewerHandles($phids); 187 + $view->setHandles($handles); 188 + 189 + $header = id(new PHUIHeaderView()) 190 + ->setHeader(pht('Pending Differential Revisions')); 191 + 192 + return array( 193 + $header, 194 + $view, 195 + ); 313 196 } 314 197 315 198 }
+108
src/applications/diffusion/controller/DiffusionBrowseDirectoryController.php
··· 1 + <?php 2 + 3 + final class DiffusionBrowseDirectoryController 4 + extends DiffusionBrowseController { 5 + 6 + private $browseQueryResults; 7 + 8 + public function setBrowseQueryResults(DiffusionBrowseResultSet $results) { 9 + $this->browseQueryResults = $results; 10 + return $this; 11 + } 12 + 13 + public function getBrowseQueryResults() { 14 + return $this->browseQueryResults; 15 + } 16 + 17 + public function processRequest() { 18 + $drequest = $this->diffusionRequest; 19 + 20 + $results = $this->getBrowseQueryResults(); 21 + $reason = $results->getReasonForEmptyResultSet(); 22 + 23 + $content = array(); 24 + 25 + $content[] = $this->buildHeaderView($drequest); 26 + $content[] = $this->buildActionView($drequest); 27 + $content[] = $this->buildPropertyView($drequest); 28 + 29 + $content[] = $this->renderSearchForm($collapsed = true); 30 + 31 + if (!$results->isValidResults()) { 32 + $empty_result = new DiffusionEmptyResultView(); 33 + $empty_result->setDiffusionRequest($drequest); 34 + $empty_result->setDiffusionBrowseResultSet($results); 35 + $empty_result->setView($this->getRequest()->getStr('view')); 36 + $content[] = $empty_result; 37 + } else { 38 + $phids = array(); 39 + foreach ($results->getPaths() as $result) { 40 + $data = $result->getLastCommitData(); 41 + if ($data) { 42 + if ($data->getCommitDetail('authorPHID')) { 43 + $phids[$data->getCommitDetail('authorPHID')] = true; 44 + } 45 + } 46 + } 47 + 48 + $phids = array_keys($phids); 49 + $handles = $this->loadViewerHandles($phids); 50 + 51 + $browse_table = new DiffusionBrowseTableView(); 52 + $browse_table->setDiffusionRequest($drequest); 53 + $browse_table->setHandles($handles); 54 + $browse_table->setPaths($results->getPaths()); 55 + $browse_table->setUser($this->getRequest()->getUser()); 56 + 57 + $browse_panel = new AphrontPanelView(); 58 + $browse_panel->appendChild($browse_table); 59 + $browse_panel->setNoBackground(); 60 + 61 + $content[] = $browse_panel; 62 + } 63 + 64 + $content[] = $this->buildOpenRevisions(); 65 + 66 + $readme = $this->callConduitWithDiffusionRequest( 67 + 'diffusion.readmequery', 68 + array( 69 + 'paths' => $results->getPathDicts(), 70 + )); 71 + if ($readme) { 72 + $box = new PHUIBoxView(); 73 + $box->setShadow(true); 74 + $box->appendChild($readme); 75 + $box->addPadding(PHUI::PADDING_LARGE); 76 + $box->addMargin(PHUI::MARGIN_LARGE); 77 + 78 + $header = id(new PHUIHeaderView()) 79 + ->setHeader(pht('README')); 80 + 81 + $content[] = array( 82 + $header, 83 + $box, 84 + ); 85 + } 86 + 87 + $crumbs = $this->buildCrumbs( 88 + array( 89 + 'branch' => true, 90 + 'path' => true, 91 + 'view' => 'browse', 92 + )); 93 + 94 + return $this->buildApplicationPage( 95 + array( 96 + $crumbs, 97 + $content, 98 + ), 99 + array( 100 + 'device' => true, 101 + 'title' => array( 102 + nonempty(basename($drequest->getPath()), '/'), 103 + $drequest->getRepository()->getCallsign().' Repository', 104 + ), 105 + )); 106 + } 107 + 108 + }
+2 -39
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 1 1 <?php 2 2 3 - final class DiffusionBrowseFileController extends DiffusionController { 3 + final class DiffusionBrowseFileController extends DiffusionBrowseController { 4 4 5 5 private $corpusType = 'text'; 6 6 ··· 8 8 private $lintMessages; 9 9 10 10 public function processRequest() { 11 - 12 11 $request = $this->getRequest(); 13 12 $drequest = $this->getDiffusionRequest(); 14 13 ··· 75 74 $content = array(); 76 75 77 76 $content[] = $this->buildHeaderView($drequest); 78 - $view = $this->buildBrowseActionView($drequest); 77 + $view = $this->buildActionView($drequest); 79 78 $content[] = $this->enrichActionView($view, $drequest, $selected); 80 79 $content[] = $this->buildPropertyView($drequest); 81 80 ··· 966 965 'commit' => $commit)); 967 966 968 967 return head($parents); 969 - } 970 - 971 - private function buildHeaderView(DiffusionRequest $drequest) { 972 - $viewer = $this->getRequest()->getUser(); 973 - 974 - $header = id(new PHUIHeaderView()) 975 - ->setUser($viewer) 976 - ->setHeader($this->renderPathLinks($drequest)) 977 - ->setPolicyObject($drequest->getRepository()); 978 - 979 - return $header; 980 - } 981 - 982 - private function buildPropertyView(DiffusionRequest $drequest) { 983 - $viewer = $this->getRequest()->getUser(); 984 - 985 - $view = id(new PhabricatorPropertyListView()) 986 - ->setUser($viewer); 987 - 988 - $stable_commit = $drequest->getStableCommitName(); 989 - $callsign = $drequest->getRepository()->getCallsign(); 990 - 991 - $view->addProperty( 992 - pht('Commit'), 993 - phutil_tag( 994 - 'a', 995 - array( 996 - 'href' => $drequest->generateURI( 997 - array( 998 - 'action' => 'commit', 999 - 'commit' => $stable_commit, 1000 - )), 1001 - ), 1002 - $drequest->getRepository()->formatCommitName($stable_commit))); 1003 - 1004 - return $view; 1005 968 } 1006 969 1007 970 }
+39
src/applications/diffusion/controller/DiffusionBrowseMainController.php
··· 1 + <?php 2 + 3 + final class DiffusionBrowseMainController extends DiffusionBrowseController { 4 + 5 + public function processRequest() { 6 + $drequest = $this->diffusionRequest; 7 + $request = $this->getRequest(); 8 + 9 + // Figure out if we're browsing a directory, a file, or a search result 10 + // list. Then delegate to the appropriate controller. 11 + 12 + $search = $request->getStr('grep'); 13 + if (strlen($search)) { 14 + $controller = new DiffusionBrowseSearchController($request); 15 + } else { 16 + $results = DiffusionBrowseResultSet::newFromConduit( 17 + $this->callConduitWithDiffusionRequest( 18 + 'diffusion.browsequery', 19 + array( 20 + 'path' => $drequest->getPath(), 21 + 'commit' => $drequest->getCommit(), 22 + ))); 23 + $reason = $results->getReasonForEmptyResultSet(); 24 + $is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE); 25 + 26 + if ($is_file) { 27 + $controller = new DiffusionBrowseFileController($request); 28 + } else { 29 + $controller = new DiffusionBrowseDirectoryController($request); 30 + $controller->setBrowseQueryResults($results); 31 + } 32 + } 33 + 34 + $controller->setDiffusionRequest($drequest); 35 + $controller->setCurrentApplication($this->getCurrentApplication()); 36 + return $this->delegateToController($controller); 37 + } 38 + 39 + }
+132
src/applications/diffusion/controller/DiffusionBrowseSearchController.php
··· 1 + <?php 2 + 3 + final class DiffusionBrowseSearchController extends DiffusionBrowseController { 4 + 5 + public function processRequest() { 6 + $drequest = $this->diffusionRequest; 7 + 8 + $content = array(); 9 + 10 + $content[] = $this->buildHeaderView($drequest); 11 + $content[] = $this->buildActionView($drequest); 12 + $content[] = $this->buildPropertyView($drequest); 13 + $content[] = $this->renderSearchForm($collapsed = false); 14 + $content[] = $this->renderSearchResults(); 15 + 16 + $crumbs = $this->buildCrumbs( 17 + array( 18 + 'branch' => true, 19 + 'path' => true, 20 + 'view' => 'browse', 21 + )); 22 + 23 + return $this->buildApplicationPage( 24 + array( 25 + $crumbs, 26 + $content, 27 + ), 28 + array( 29 + 'device' => true, 30 + 'title' => array( 31 + nonempty(basename($drequest->getPath()), '/'), 32 + $drequest->getRepository()->getCallsign().' Repository', 33 + ), 34 + )); 35 + } 36 + 37 + private function renderSearchResults() { 38 + $drequest = $this->getDiffusionRequest(); 39 + $repository = $drequest->getRepository(); 40 + $results = array(); 41 + $no_data = pht('No results found.'); 42 + 43 + $limit = 100; 44 + $page = $this->getRequest()->getInt('page', 0); 45 + $pager = new AphrontPagerView(); 46 + $pager->setPageSize($limit); 47 + $pager->setOffset($page); 48 + $pager->setURI($this->getRequest()->getRequestURI(), 'page'); 49 + 50 + try { 51 + 52 + $results = $this->callConduitWithDiffusionRequest( 53 + 'diffusion.searchquery', 54 + array( 55 + 'grep' => $this->getRequest()->getStr('grep'), 56 + 'stableCommitName' => $drequest->getStableCommitName(), 57 + 'path' => $drequest->getPath(), 58 + 'limit' => $limit + 1, 59 + 'offset' => $page)); 60 + 61 + } catch (ConduitException $ex) { 62 + $err = $ex->getErrorDescription(); 63 + if ($err != '') { 64 + return id(new AphrontErrorView()) 65 + ->setTitle(pht('Search Error')) 66 + ->appendChild($err); 67 + } 68 + } 69 + 70 + $results = $pager->sliceResults($results); 71 + 72 + require_celerity_resource('syntax-highlighting-css'); 73 + 74 + // NOTE: This can be wrong because we may find the string inside the 75 + // comment. But it's correct in most cases and highlighting the whole file 76 + // would be too expensive. 77 + $futures = array(); 78 + $engine = PhabricatorSyntaxHighlighter::newEngine(); 79 + foreach ($results as $result) { 80 + list($path, $line, $string) = $result; 81 + $futures["{$path}:{$line}"] = $engine->getHighlightFuture( 82 + $engine->getLanguageFromFilename($path), 83 + ltrim($string)); 84 + } 85 + 86 + try { 87 + Futures($futures)->limit(8)->resolveAll(); 88 + } catch (PhutilSyntaxHighlighterException $ex) { 89 + } 90 + 91 + $rows = array(); 92 + foreach ($results as $result) { 93 + list($path, $line, $string) = $result; 94 + 95 + $href = $drequest->generateURI(array( 96 + 'action' => 'browse', 97 + 'path' => $path, 98 + 'line' => $line, 99 + )); 100 + 101 + try { 102 + $string = $futures["{$path}:{$line}"]->resolve(); 103 + } catch (PhutilSyntaxHighlighterException $ex) { 104 + } 105 + 106 + $string = phutil_tag( 107 + 'pre', 108 + array('class' => 'PhabricatorMonospaced'), 109 + $string); 110 + 111 + $path = Filesystem::readablePath($path, $drequest->getPath()); 112 + 113 + $rows[] = array( 114 + phutil_tag('a', array('href' => $href), $path), 115 + $line, 116 + $string, 117 + ); 118 + } 119 + 120 + $table = id(new AphrontTableView($rows)) 121 + ->setClassName('remarkup-code') 122 + ->setHeaders(array(pht('Path'), pht('Line'), pht('String'))) 123 + ->setColumnClasses(array('', 'n', 'wide')) 124 + ->setNoDataString($no_data); 125 + 126 + return id(new AphrontPanelView()) 127 + ->setNoBackground(true) 128 + ->appendChild($table) 129 + ->appendChild($pager); 130 + } 131 + 132 + }
-95
src/applications/diffusion/controller/DiffusionController.php
··· 97 97 return $crumbs; 98 98 } 99 99 100 - protected function buildOpenRevisions() { 101 - $user = $this->getRequest()->getUser(); 102 - 103 - $drequest = $this->getDiffusionRequest(); 104 - $repository = $drequest->getRepository(); 105 - $path = $drequest->getPath(); 106 - 107 - $path_map = id(new DiffusionPathIDQuery(array($path)))->loadPathIDs(); 108 - $path_id = idx($path_map, $path); 109 - if (!$path_id) { 110 - return null; 111 - } 112 - 113 - $revisions = id(new DifferentialRevisionQuery()) 114 - ->setViewer($user) 115 - ->withPath($repository->getID(), $path_id) 116 - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 117 - ->setOrder(DifferentialRevisionQuery::ORDER_PATH_MODIFIED) 118 - ->setLimit(10) 119 - ->needRelationships(true) 120 - ->execute(); 121 - 122 - if (!$revisions) { 123 - return null; 124 - } 125 - 126 - $view = id(new DifferentialRevisionListView()) 127 - ->setRevisions($revisions) 128 - ->setFields(DifferentialRevisionListView::getDefaultFields($user)) 129 - ->setUser($user) 130 - ->loadAssets(); 131 - 132 - $phids = $view->getRequiredHandlePHIDs(); 133 - $handles = $this->loadViewerHandles($phids); 134 - $view->setHandles($handles); 135 - 136 - $header = id(new PHUIHeaderView()) 137 - ->setHeader(pht('Pending Differential Revisions')); 138 - 139 - return array( 140 - $header, 141 - $view, 142 - ); 143 - } 144 - 145 100 private function buildCrumbList(array $spec = array()) { 146 101 147 102 $spec = $spec + array( ··· 342 297 PhabricatorRepository $repository, 343 298 $path) { 344 299 return $this->getApplicationURI($repository->getCallsign().'/'.$path); 345 - } 346 - 347 - 348 - protected function buildBrowseActionView(DiffusionRequest $drequest) { 349 - $viewer = $this->getRequest()->getUser(); 350 - 351 - $view = id(new PhabricatorActionListView()) 352 - ->setUser($viewer); 353 - 354 - $history_uri = $drequest->generateURI( 355 - array( 356 - 'action' => 'history', 357 - )); 358 - 359 - $view->addAction( 360 - id(new PhabricatorActionView()) 361 - ->setName(pht('View History')) 362 - ->setHref($history_uri) 363 - ->setIcon('perflab')); 364 - 365 - $behind_head = $drequest->getRawCommit(); 366 - $head_uri = $drequest->generateURI( 367 - array( 368 - 'commit' => '', 369 - 'action' => 'browse', 370 - )); 371 - $view->addAction( 372 - id(new PhabricatorActionView()) 373 - ->setName(pht('Jump to HEAD')) 374 - ->setHref($head_uri) 375 - ->setIcon('home') 376 - ->setDisabled(!$behind_head)); 377 - 378 - // TODO: Ideally, this should live in Owners and be event-triggered, but 379 - // there's no reasonable object for it to react to right now. 380 - 381 - $owners_uri = id(new PhutilURI('/owners/view/search/')) 382 - ->setQueryParams( 383 - array( 384 - 'repository' => $drequest->getCallsign(), 385 - 'path' => '/'.$drequest->getPath(), 386 - )); 387 - 388 - $view->addAction( 389 - id(new PhabricatorActionView()) 390 - ->setName(pht('Find Owners')) 391 - ->setHref((string)$owners_uri) 392 - ->setIcon('preview')); 393 - 394 - return $view; 395 300 } 396 301 397 302 protected function renderPathLinks(DiffusionRequest $drequest) {