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

Mostly modernize lint views and delete dead code

Summary:
This is a mostly-faithful modernization of the Diffusion lint interfaces. It:

- Makes them policy aware;
- removes the last callsites for old/dead code (crumbs, nav).

It's a little rough, but should be perfectly usable. At some point this should get another pass, but probably after we make it easier to populate the lint data.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, FacebookPOC

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

+140 -164
-124
src/applications/diffusion/controller/DiffusionController.php
··· 25 25 return $this->diffusionRequest; 26 26 } 27 27 28 - final protected function buildSideNav($selected, $has_change_view) { 29 - $nav = new AphrontSideNavFilterView(); 30 - $nav->setBaseURI(new PhutilURI('')); 31 - 32 - $navs = array( 33 - 'history' => pht('History View'), 34 - 'browse' => pht('Browse View'), 35 - 'change' => pht('Change View'), 36 - ); 37 - 38 - if (!$has_change_view) { 39 - unset($navs['change']); 40 - } 41 - 42 - $drequest = $this->getDiffusionRequest(); 43 - $branch = $drequest->loadBranch(); 44 - 45 - if ($branch && $branch->getLintCommit()) { 46 - $navs['lint'] = pht('Lint View'); 47 - } 48 - 49 - $selected_href = null; 50 - foreach ($navs as $action => $name) { 51 - $href = $drequest->generateURI( 52 - array( 53 - 'action' => $action, 54 - )); 55 - if ($action == $selected) { 56 - $selected_href = $href; 57 - } 58 - 59 - $nav->addFilter($href, $name, $href); 60 - } 61 - $nav->selectFilter($selected_href, null); 62 - 63 - // TODO: URI encoding might need to be sorted out for this link. 64 - 65 - $nav->addFilter( 66 - '', 67 - pht("Search Owners \xE2\x86\x97"), 68 - '/owners/view/search/'. 69 - '?repository='.phutil_escape_uri($drequest->getCallsign()). 70 - '&path='.phutil_escape_uri('/'.$drequest->getPath())); 71 - 72 - return $nav; 73 - } 74 - 75 28 public function buildCrumbs(array $spec = array()) { 76 29 $crumbs = $this->buildApplicationCrumbs(); 77 30 $crumb_list = $this->buildCrumbList($spec); ··· 167 120 $crumb = new PhabricatorCrumbView(); 168 121 $view = $spec['view']; 169 122 170 - $path = null; 171 - if (isset($spec['path'])) { 172 - $path = $drequest->getPath(); 173 - } 174 - 175 - if ($raw_commit) { 176 - $commit_link = DiffusionView::linkCommit( 177 - $repository, 178 - $raw_commit); 179 - } else { 180 - $commit_link = ''; 181 - } 182 - 183 123 switch ($view) { 184 124 case 'history': 185 125 $view_name = pht('History'); ··· 195 135 break; 196 136 } 197 137 198 - $uri_params = array( 199 - 'action' => $view, 200 - ); 201 - 202 138 $crumb = id(new PhabricatorCrumbView()) 203 139 ->setName($view_name); 204 140 205 - if ($view == 'browse' || $view == 'change' || $view == 'history') { 206 - $crumb_list[] = $crumb; 207 - return $crumb_list; 208 - } 209 - 210 - $crumb->setHref($drequest->generateURI( 211 - array( 212 - 'path' => '', 213 - ) + $uri_params)); 214 141 $crumb_list[] = $crumb; 215 - 216 - $path_parts = explode('/', $path); 217 - do { 218 - $last = array_pop($path_parts); 219 - } while (count($path_parts) && $last == ''); 220 - 221 - $path_sections = array(); 222 - $thus_far = ''; 223 - foreach ($path_parts as $path_part) { 224 - $thus_far .= $path_part.'/'; 225 - $path_sections[] = '/'; 226 - $path_sections[] = phutil_tag( 227 - 'a', 228 - array( 229 - 'href' => $drequest->generateURI( 230 - array( 231 - 'path' => $thus_far, 232 - ) + $uri_params), 233 - ), 234 - $path_part); 235 - } 236 - 237 - $path_sections[] = '/'.$last; 238 - 239 - $crumb_list[] = id(new PhabricatorCrumbView()) 240 - ->setName($path_sections); 241 - 242 - $last_crumb = array_pop($crumb_list); 243 - 244 - if ($raw_commit) { 245 - $jump_link = phutil_tag( 246 - 'a', 247 - array( 248 - 'href' => $drequest->generateURI( 249 - array( 250 - 'commit' => '', 251 - ) + $uri_params), 252 - ), 253 - pht('Jump to HEAD')); 254 - 255 - $name = $last_crumb->getName(); 256 - $name = hsprintf('%s @ %s (%s)', $name, $commit_link, $jump_link); 257 - $last_crumb->setName($name); 258 - } else if ($spec['view'] != 'lint') { 259 - $name = $last_crumb->getName(); 260 - $name = hsprintf('%s @ HEAD', $name); 261 - $last_crumb->setName($name); 262 - } 263 - 264 - $crumb_list[] = $last_crumb; 265 - 266 142 return $crumb_list; 267 143 } 268 144
+135 -23
src/applications/diffusion/controller/DiffusionLintController.php
··· 2 2 3 3 final class DiffusionLintController extends DiffusionController { 4 4 5 + public function shouldAllowPublic() { 6 + return true; 7 + } 8 + 5 9 public function processRequest() { 6 10 $request = $this->getRequest(); 7 11 $user = $this->getRequest()->getUser(); ··· 17 21 $owners = array(); 18 22 if (!$drequest) { 19 23 if (!$request->getArr('owner')) { 20 - $owners[$user->getPHID()] = $user->getFullName(); 24 + if ($user->isLoggedIn()) { 25 + $owners[$user->getPHID()] = $user->getFullName(); 26 + } 21 27 } else { 22 28 $phids = $request->getArr('owner'); 23 29 $phid = reset($phids); ··· 29 35 $codes = $this->loadLintCodes(array_keys($owners)); 30 36 31 37 if ($codes && !$drequest) { 38 + // TODO: Build some real Query classes for this stuff. 39 + 32 40 $branches = id(new PhabricatorRepositoryBranch())->loadAllWhere( 33 41 'id IN (%Ld)', 34 42 array_unique(ipull($codes, 'branchID'))); 35 43 36 - $repositories = id(new PhabricatorRepository())->loadAllWhere( 37 - 'id IN (%Ld)', 38 - array_unique(mpull($branches, 'getRepositoryID'))); 44 + $repositories = id(new PhabricatorRepositoryQuery()) 45 + ->setViewer($user) 46 + ->withIDs(mpull($branches, 'getRepositoryID')) 47 + ->execute(); 39 48 40 49 $drequests = array(); 41 50 foreach ($branches as $id => $branch) { 51 + if (empty($repositories[$branch->getRepositoryID()])) { 52 + continue; 53 + } 54 + 42 55 $drequests[$id] = DiffusionRequest::newFromDictionary(array( 43 56 'user' => $user, 44 57 'repository' => $repositories[$branch->getRepositoryID()], ··· 48 61 } 49 62 50 63 $rows = array(); 64 + $total = 0; 51 65 foreach ($codes as $code) { 52 66 if (!$this->diffusionRequest) { 53 - $drequest = $drequests[$code['branchID']]; 67 + $drequest = idx($drequests, $code['branchID']); 54 68 } 69 + 70 + if (!$drequest) { 71 + continue; 72 + } 73 + 74 + $total += $code['n']; 55 75 56 76 $rows[] = array( 57 77 hsprintf( ··· 95 115 $content = array(); 96 116 97 117 $link = null; 98 - if ($this->diffusionRequest) { 99 - $link = hsprintf( 100 - '<a href="%s">%s</a>', 101 - $drequest->generateURI(array( 102 - 'action' => 'lint', 103 - 'lint' => '', 104 - )), 105 - pht('Switch to List View')); 106 - 107 - } else { 118 + if (!$this->diffusionRequest) { 108 119 $form = id(new AphrontFormView()) 109 120 ->setUser($user) 110 121 ->setMethod('GET') ··· 122 133 } 123 134 124 135 $content[] = id(new AphrontPanelView()) 125 - ->setHeader(pht('%d Lint Message(s)', array_sum(ipull($codes, 'n')))) 136 + ->setNoBackground(true) 126 137 ->setCaption($link) 127 138 ->appendChild($table); 128 139 ··· 133 144 'path' => true, 134 145 'view' => 'lint', 135 146 )); 147 + 136 148 if ($this->diffusionRequest) { 137 149 $title[] = $drequest->getCallsign(); 138 - $content = $this->buildSideNav('lint', false) 139 - ->setCrumbs($crumbs) 140 - ->appendChild($content); 150 + } else { 151 + $crumbs->addCrumb( 152 + id(new PhabricatorCrumbView()) 153 + ->setName(pht('All Lint'))); 154 + } 155 + 156 + if ($this->diffusionRequest) { 157 + $branch = $drequest->loadBranch(); 158 + 159 + $header = id(new PHUIHeaderView()) 160 + ->setHeader($this->renderPathLinks($drequest, 'lint')) 161 + ->setUser($user) 162 + ->setPolicyObject($drequest->getRepository()); 163 + $actions = $this->buildActionView($drequest); 164 + $properties = $this->buildPropertyView( 165 + $drequest, 166 + $branch, 167 + $total); 141 168 } else { 142 - array_unshift($content, $crumbs); 169 + $header = null; 170 + $actions = null; 171 + $properties = null; 143 172 } 173 + 144 174 145 175 return $this->buildApplicationPage( 146 - $content, 176 + array( 177 + $crumbs, 178 + $header, 179 + $actions, 180 + $properties, 181 + $content, 182 + ), 147 183 array( 148 184 'title' => $title, 149 - 'device' => true, 150 - )); 185 + )); 151 186 } 152 187 153 188 private function loadLintCodes(array $owner_phids) { ··· 232 267 PhabricatorRepository::TABLE_LINTMESSAGE, 233 268 implode(' AND ', $where)); 234 269 } 270 + 271 + protected function buildActionView(DiffusionRequest $drequest) { 272 + $viewer = $this->getRequest()->getUser(); 273 + 274 + $view = id(new PhabricatorActionListView()) 275 + ->setUser($viewer); 276 + 277 + $list_uri = $drequest->generateURI( 278 + array( 279 + 'action' => 'lint', 280 + 'lint' => '', 281 + )); 282 + 283 + $view->addAction( 284 + id(new PhabricatorActionView()) 285 + ->setName(pht('View As List')) 286 + ->setHref($list_uri) 287 + ->setIcon('transcript')); 288 + 289 + $history_uri = $drequest->generateURI( 290 + array( 291 + 'action' => 'history', 292 + )); 293 + 294 + $view->addAction( 295 + id(new PhabricatorActionView()) 296 + ->setName(pht('View History')) 297 + ->setHref($history_uri) 298 + ->setIcon('history')); 299 + 300 + $browse_uri = $drequest->generateURI( 301 + array( 302 + 'action' => 'browse', 303 + )); 304 + 305 + $view->addAction( 306 + id(new PhabricatorActionView()) 307 + ->setName(pht('Browse Content')) 308 + ->setHref($browse_uri) 309 + ->setIcon('file')); 310 + 311 + return $view; 312 + } 313 + 314 + protected function buildPropertyView( 315 + DiffusionRequest $drequest, 316 + PhabricatorRepositoryBranch $branch, 317 + $total) { 318 + 319 + $viewer = $this->getRequest()->getUser(); 320 + 321 + $view = id(new PhabricatorPropertyListView()) 322 + ->setUser($viewer); 323 + 324 + $callsign = $drequest->getRepository()->getCallsign(); 325 + $lint_commit = $branch->getLintCommit(); 326 + 327 + $view->addProperty( 328 + pht('Lint Commit'), 329 + phutil_tag( 330 + 'a', 331 + array( 332 + 'href' => $drequest->generateURI( 333 + array( 334 + 'action' => 'commit', 335 + 'commit' => $lint_commit, 336 + )), 337 + ), 338 + $drequest->getRepository()->formatCommitName($lint_commit))); 339 + 340 + $view->addProperty( 341 + pht('Total Messages'), 342 + pht('%s', new PhutilNumber($total))); 343 + 344 + return $view; 345 + } 346 + 235 347 236 348 }
+5 -17
src/applications/diffusion/controller/DiffusionLintDetailsController.php
··· 68 68 ->setHasMorePages(count($messages) >= $limit) 69 69 ->setURI($this->getRequest()->getRequestURI(), 'offset'); 70 70 71 - $lint = $drequest->getLint(); 72 - $link = hsprintf( 73 - '<a href="%s">%s</a>', 74 - $drequest->generateURI(array( 75 - 'action' => 'lint', 76 - 'lint' => null, 77 - )), 78 - pht('Switch to Grouped View')); 79 - 80 71 $content[] = id(new AphrontPanelView()) 81 - ->setHeader( 82 - ($lint != '' ? $lint." \xC2\xB7 " : ''). 83 - pht('%d Lint Message(s)', count($messages))) 84 - ->setCaption($link) 72 + ->setNoBackground(true) 85 73 ->appendChild($table) 86 74 ->appendChild($pager); 87 75 88 - $nav = $this->buildSideNav('lint', false); 89 - $nav->appendChild($content); 90 76 $crumbs = $this->buildCrumbs( 91 77 array( 92 78 'branch' => true, 93 79 'path' => true, 94 80 'view' => 'lint', 95 81 )); 96 - $nav->setCrumbs($crumbs); 97 82 98 83 return $this->buildApplicationPage( 99 - $nav, 84 + array( 85 + $crumbs, 86 + $content, 87 + ), 100 88 array( 101 89 'device' => true, 102 90 'title' =>