@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 file browse controller

Summary: This needs some more cleanup, but gets us a step closer to something reasonable.

Test Plan: See screenshot.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

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

+181 -154
+1 -93
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 30 30 $content = array(); 31 31 32 32 $content[] = $this->buildHeaderView($drequest); 33 - $content[] = $this->buildActionView($drequest); 33 + $content[] = $this->buildBrowseActionView($drequest); 34 34 $content[] = $this->buildPropertyView($drequest); 35 35 36 36 $content[] = $this->renderSearchForm(); ··· 278 278 return $header; 279 279 } 280 280 281 - private function buildActionView(DiffusionRequest $drequest) { 282 - $viewer = $this->getRequest()->getUser(); 283 - 284 - $view = id(new PhabricatorActionListView()) 285 - ->setUser($viewer); 286 - 287 - $history_uri = $drequest->generateURI( 288 - array( 289 - 'action' => 'history', 290 - )); 291 - 292 - $view->addAction( 293 - id(new PhabricatorActionView()) 294 - ->setName(pht('View History')) 295 - ->setHref($history_uri) 296 - ->setIcon('perflab')); 297 - 298 - $behind_head = $drequest->getRawCommit(); 299 - $head_uri = $drequest->generateURI( 300 - array( 301 - 'commit' => '', 302 - 'action' => 'browse', 303 - )); 304 - $view->addAction( 305 - id(new PhabricatorActionView()) 306 - ->setName(pht('Jump to HEAD')) 307 - ->setHref($head_uri) 308 - ->setIcon('home') 309 - ->setDisabled(!$behind_head)); 310 - 311 - // TODO: Ideally, this should live in Owners and be event-triggered, but 312 - // there's no reasonable object for it to react to right now. 313 - 314 - $owners_uri = id(new PhutilURI('/owners/view/search/')) 315 - ->setQueryParams( 316 - array( 317 - 'repository' => $drequest->getCallsign(), 318 - 'path' => '/'.$drequest->getPath(), 319 - )); 320 - 321 - $view->addAction( 322 - id(new PhabricatorActionView()) 323 - ->setName(pht('Find Owners')) 324 - ->setHref((string)$owners_uri) 325 - ->setIcon('preview')); 326 - 327 - return $view; 328 - } 329 - 330 281 private function buildPropertyView(DiffusionRequest $drequest) { 331 282 $viewer = $this->getRequest()->getUser(); 332 283 ··· 359 310 } 360 311 361 312 return $view; 362 - } 363 - 364 - private function renderPathLinks(DiffusionRequest $drequest) { 365 - $path = $drequest->getPath(); 366 - $path_parts = array_filter(explode('/', trim($path, '/'))); 367 - 368 - $links = array(); 369 - if ($path_parts) { 370 - $links[] = phutil_tag( 371 - 'a', 372 - array( 373 - 'href' => $drequest->generateURI( 374 - array( 375 - 'action' => 'browse', 376 - 'path' => '', 377 - )), 378 - ), 379 - 'r'.$drequest->getRepository()->getCallsign().'/'); 380 - $accum = ''; 381 - $last_key = last_key($path_parts); 382 - foreach ($path_parts as $key => $part) { 383 - $links[] = ' '; 384 - $accum .= '/'.$part; 385 - if ($key === $last_key) { 386 - $links[] = $part; 387 - } else { 388 - $links[] = phutil_tag( 389 - 'a', 390 - array( 391 - 'href' => $drequest->generateURI( 392 - array( 393 - 'action' => 'browse', 394 - 'path' => $accum, 395 - )), 396 - ), 397 - $part.'/'); 398 - } 399 - } 400 - } else { 401 - $links[] = 'r'.$drequest->getRepository()->getCallsign().'/'; 402 - } 403 - 404 - return $links; 405 313 } 406 314 407 315 }
+86 -61
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 71 71 72 72 require_celerity_resource('diffusion-source-css'); 73 73 74 - if ($this->corpusType == 'text') { 75 - $view_select_panel = $this->renderViewSelectPanel($selected); 76 - } else { 77 - $view_select_panel = null; 78 - } 79 - 80 74 // Render the page. 81 75 $content = array(); 76 + 77 + $content[] = $this->buildHeaderView($drequest); 78 + $view = $this->buildBrowseActionView($drequest); 79 + $content[] = $this->enrichActionView($view, $drequest, $selected); 80 + $content[] = $this->buildPropertyView($drequest); 82 81 83 82 $follow = $request->getStr('follow'); 84 83 if ($follow) { ··· 111 110 $content[] = $notice; 112 111 } 113 112 114 - $content[] = $view_select_panel; 115 113 $content[] = $corpus; 116 114 $content[] = $this->buildOpenRevisions(); 117 115 118 - $nav = $this->buildSideNav('browse', true); 119 - $nav->appendChild($content); 120 116 $crumbs = $this->buildCrumbs( 121 117 array( 122 118 'branch' => true, 123 119 'path' => true, 124 120 'view' => 'browse', 125 121 )); 126 - $nav->setCrumbs($crumbs); 127 122 128 123 $basename = basename($this->getDiffusionRequest()->getPath()); 129 124 130 125 return $this->buildApplicationPage( 131 - $nav, 126 + array( 127 + $crumbs, 128 + $content, 129 + ), 132 130 array( 133 131 'title' => $basename, 134 132 )); ··· 296 294 return $corpus; 297 295 } 298 296 299 - private function renderViewSelectPanel($selected) { 297 + private function enrichActionView( 298 + PhabricatorActionListView $view, 299 + DiffusionRequest $drequest, 300 + $selected) { 301 + 302 + $viewer = $this->getRequest()->getUser(); 303 + $base_uri = $this->getRequest()->getRequestURI(); 304 + 300 305 $toggle_blame = array( 301 306 'highlighted' => 'blame', 302 307 'blame' => 'highlighted', ··· 304 309 'plainblame' => 'plain', 305 310 'raw' => 'raw', // not a real case. 306 311 ); 312 + 307 313 $toggle_highlight = array( 308 314 'highlighted' => 'plain', 309 315 'blame' => 'plainblame', ··· 312 318 'raw' => 'raw', // not a real case. 313 319 ); 314 320 315 - $user = $this->getRequest()->getUser(); 316 - $base_uri = $this->getRequest()->getRequestURI(); 317 - 318 321 $blame_on = ($selected == 'blame' || $selected == 'plainblame'); 319 322 if ($blame_on) { 320 323 $blame_text = pht('Disable Blame'); 324 + $blame_icon = 'blame-grey'; 321 325 } else { 322 326 $blame_text = pht('Enable Blame'); 327 + $blame_icon = 'blame'; 323 328 } 324 329 325 - $blame_button = $this->createViewAction( 326 - $blame_text, 327 - $base_uri->alter('view', $toggle_blame[$selected]), 328 - $user); 330 + $view->addAction( 331 + id(new PhabricatorActionView()) 332 + ->setName($blame_text) 333 + ->setHref($base_uri->alter('view', $toggle_blame[$selected])) 334 + ->setIcon($blame_icon) 335 + ->setUser($viewer) 336 + ->setRenderAsForm(true)); 329 337 330 338 331 339 $highlight_on = ($selected == 'blame' || $selected == 'highlighted'); 332 340 if ($highlight_on) { 333 341 $highlight_text = pht('Disable Highlighting'); 342 + $highlight_icon = 'highlight-grey'; 334 343 } else { 335 344 $highlight_text = pht('Enable Highlighting'); 345 + $highlight_icon = 'highlight'; 336 346 } 337 - $highlight_button = $this->createViewAction( 338 - $highlight_text, 339 - $base_uri->alter('view', $toggle_highlight[$selected]), 340 - $user); 347 + 348 + $view->addAction( 349 + id(new PhabricatorActionView()) 350 + ->setName($highlight_text) 351 + ->setHref($base_uri->alter('view', $toggle_highlight[$selected])) 352 + ->setIcon($highlight_icon) 353 + ->setUser($viewer) 354 + ->setRenderAsForm(true)); 341 355 342 356 343 357 $href = null; ··· 347 361 348 362 } else if ($this->lintCommit === null) { 349 363 $lint_text = pht('Lint not Available'); 350 - 351 364 } else { 352 365 $lint_text = pht( 353 366 'Show %d Lint Message(s)', ··· 358 371 ))->alter('lint', ''); 359 372 } 360 373 361 - $lint_button = $this->createViewAction( 362 - $lint_text, 363 - $href, 364 - $user); 374 + $view->addAction( 375 + id(new PhabricatorActionView()) 376 + ->setName($lint_text) 377 + ->setHref($href) 378 + ->setIcon('warning') 379 + ->setDisabled(!$href)); 365 380 366 - if (!$href) { 367 - $lint_button->setDisabled(true); 368 - } 381 + $view->addAction( 382 + id(new PhabricatorActionView()) 383 + ->setName(pht('View Raw File')) 384 + ->setHref($base_uri->alter('view', 'raw')) 385 + ->setIcon('file')); 369 386 387 + $view->addAction($this->createEditAction()); 370 388 371 - $raw_button = $this->createViewAction( 372 - pht('View Raw File'), 373 - $base_uri->alter('view', 'raw'), 374 - $user, 375 - 'file'); 376 - 377 - $edit_button = $this->createEditAction(); 378 - 379 - return id(new PhabricatorActionListView()) 380 - ->setUser($user) 381 - ->setObjectURI($this->getRequest()->getRequestURI()) 382 - ->addAction($blame_button) 383 - ->addAction($highlight_button) 384 - ->addAction($lint_button) 385 - ->addAction($raw_button) 386 - ->addAction($edit_button); 387 - } 388 - 389 - private function createViewAction( 390 - $localized_text, 391 - $href, 392 - $user, 393 - $icon = null) { 394 - 395 - return id(new PhabricatorActionView()) 396 - ->setName($localized_text) 397 - ->setIcon($icon) 398 - ->setUser($user) 399 - ->setRenderAsForm(true) 400 - ->setHref($href); 389 + return $view; 401 390 } 402 391 403 392 private function createEditAction() { ··· 977 966 'commit' => $commit)); 978 967 979 968 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; 980 1005 } 981 1006 982 1007 }
+94
src/applications/diffusion/controller/DiffusionController.php
··· 344 344 return $this->getApplicationURI($repository->getCallsign().'/'.$path); 345 345 } 346 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 + } 396 + 397 + protected function renderPathLinks(DiffusionRequest $drequest) { 398 + $path = $drequest->getPath(); 399 + $path_parts = array_filter(explode('/', trim($path, '/'))); 400 + 401 + $links = array(); 402 + if ($path_parts) { 403 + $links[] = phutil_tag( 404 + 'a', 405 + array( 406 + 'href' => $drequest->generateURI( 407 + array( 408 + 'action' => 'browse', 409 + 'path' => '', 410 + )), 411 + ), 412 + 'r'.$drequest->getRepository()->getCallsign().'/'); 413 + $accum = ''; 414 + $last_key = last_key($path_parts); 415 + foreach ($path_parts as $key => $part) { 416 + $links[] = ' '; 417 + $accum .= '/'.$part; 418 + if ($key === $last_key) { 419 + $links[] = $part; 420 + } else { 421 + $links[] = phutil_tag( 422 + 'a', 423 + array( 424 + 'href' => $drequest->generateURI( 425 + array( 426 + 'action' => 'browse', 427 + 'path' => $accum, 428 + )), 429 + ), 430 + $part.'/'); 431 + } 432 + } 433 + } else { 434 + $links[] = 'r'.$drequest->getRepository()->getCallsign().'/'; 435 + } 436 + 437 + return $links; 438 + } 439 + 347 440 } 441 +