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

Build a basic DiffusionPatternSearchView

Summary: Roughs this in a little, kinda basic. Allows for grouping results by page. A bit better on mobile. Would like more content return from conduit though.

Test Plan:
Test `CMS`, `cms`, and `OMGLOLWTFBBQ`, desktop and mobile

{F5099081}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

+166 -117
+4 -4
resources/celerity/map.php
··· 75 75 'rsrc/css/application/diffusion/diffusion-readme.css' => '419dd5b6', 76 76 'rsrc/css/application/diffusion/diffusion-repository.css' => 'ee6f20ec', 77 77 'rsrc/css/application/diffusion/diffusion-source.css' => '750add59', 78 - 'rsrc/css/application/diffusion/diffusion.css' => '8a6eb632', 78 + 'rsrc/css/application/diffusion/diffusion.css' => 'd0fbb996', 79 79 'rsrc/css/application/feed/feed.css' => 'ecd4ec57', 80 80 'rsrc/css/application/files/global-drag-and-drop.css' => 'b556a948', 81 81 'rsrc/css/application/flag/flag.css' => 'bba8f811', ··· 111 111 'rsrc/css/application/releeph/releeph-request-differential-create-dialog.css' => '8d8b92cd', 112 112 'rsrc/css/application/releeph/releeph-request-typeahead.css' => '667a48ae', 113 113 'rsrc/css/application/search/application-search-view.css' => '66ee5d46', 114 - 'rsrc/css/application/search/search-results.css' => '8f8e08ed', 114 + 'rsrc/css/application/search/search-results.css' => '505dd8cf', 115 115 'rsrc/css/application/slowvote/slowvote.css' => 'a94b7230', 116 116 'rsrc/css/application/tokens/tokens.css' => '3d0f239e', 117 117 'rsrc/css/application/uiexample/example.css' => '528b19de', ··· 570 570 'differential-revision-history-css' => '0e8eb855', 571 571 'differential-revision-list-css' => 'f3c47d33', 572 572 'differential-table-of-contents-css' => 'ae4b7a55', 573 - 'diffusion-css' => '8a6eb632', 573 + 'diffusion-css' => 'd0fbb996', 574 574 'diffusion-icons-css' => '0c15255e', 575 575 'diffusion-readme-css' => '419dd5b6', 576 576 'diffusion-repository-css' => 'ee6f20ec', ··· 798 798 'phabricator-phtize' => 'd254d646', 799 799 'phabricator-prefab' => 'c5af80a2', 800 800 'phabricator-remarkup-css' => 'cad18339', 801 - 'phabricator-search-results-css' => '8f8e08ed', 801 + 'phabricator-search-results-css' => '505dd8cf', 802 802 'phabricator-shaped-request' => '7cbe244b', 803 803 'phabricator-slowvote-css' => 'a94b7230', 804 804 'phabricator-source-code-view-css' => 'aea41829',
+2
src/__phutil_library_map__.php
··· 776 776 'DiffusionPathQueryTestCase' => 'applications/diffusion/query/pathid/__tests__/DiffusionPathQueryTestCase.php', 777 777 'DiffusionPathTreeController' => 'applications/diffusion/controller/DiffusionPathTreeController.php', 778 778 'DiffusionPathValidateController' => 'applications/diffusion/controller/DiffusionPathValidateController.php', 779 + 'DiffusionPatternSearchView' => 'applications/diffusion/view/DiffusionPatternSearchView.php', 779 780 'DiffusionPhpExternalSymbolsSource' => 'applications/diffusion/symbol/DiffusionPhpExternalSymbolsSource.php', 780 781 'DiffusionPreCommitContentAffectedFilesHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentAffectedFilesHeraldField.php', 781 782 'DiffusionPreCommitContentAuthorHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitContentAuthorHeraldField.php', ··· 5776 5777 'DiffusionPathQueryTestCase' => 'PhabricatorTestCase', 5777 5778 'DiffusionPathTreeController' => 'DiffusionController', 5778 5779 'DiffusionPathValidateController' => 'DiffusionController', 5780 + 'DiffusionPatternSearchView' => 'DiffusionView', 5779 5781 'DiffusionPhpExternalSymbolsSource' => 'DiffusionExternalSymbolsSource', 5780 5782 'DiffusionPreCommitContentAffectedFilesHeraldField' => 'DiffusionPreCommitContentHeraldField', 5781 5783 'DiffusionPreCommitContentAuthorHeraldField' => 'DiffusionPreCommitContentHeraldField',
+28 -111
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 447 447 } 448 448 $results = $pager->sliceResults($results); 449 449 450 + $table = null; 451 + $header = null; 450 452 if ($search_mode == 'grep') { 451 453 $table = $this->renderGrepResults($results, $query_string); 452 - $header = pht( 454 + $title = pht( 453 455 'File content matching "%s" under "%s"', 454 456 $query_string, 455 457 nonempty($drequest->getPath(), '/')); 458 + $header = id(new PHUIHeaderView()) 459 + ->setHeader($title) 460 + ->addClass('diffusion-search-result-header'); 456 461 } 457 462 458 - return id(new PHUIObjectBoxView()) 459 - ->setHeaderText($header) 460 - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 461 - ->setTable($table) 462 - ->setPager($pager); 463 + return array($header, $table, $pager); 463 464 464 465 } 465 466 466 467 private function renderGrepResults(array $results, $pattern) { 467 468 $drequest = $this->getDiffusionRequest(); 468 - 469 469 require_celerity_resource('phabricator-search-results-css'); 470 470 471 - $rows = array(); 472 - foreach ($results as $result) { 473 - list($path, $line, $string) = $result; 474 - 475 - $href = $drequest->generateURI(array( 476 - 'action' => 'browse', 477 - 'path' => $path, 478 - 'line' => $line, 479 - )); 480 - 481 - $matches = null; 482 - $count = @preg_match_all( 483 - '('.$pattern.')u', 484 - $string, 485 - $matches, 486 - PREG_OFFSET_CAPTURE); 487 - 488 - if (!$count) { 489 - $output = ltrim($string); 490 - } else { 491 - $output = array(); 492 - $cursor = 0; 493 - $length = strlen($string); 494 - foreach ($matches[0] as $match) { 495 - $offset = $match[1]; 496 - if ($cursor != $offset) { 497 - $output[] = array( 498 - 'text' => substr($string, $cursor, $offset), 499 - 'highlight' => false, 500 - ); 501 - } 502 - $output[] = array( 503 - 'text' => $match[0], 504 - 'highlight' => true, 505 - ); 506 - $cursor = $offset + strlen($match[0]); 507 - } 508 - if ($cursor != $length) { 509 - $output[] = array( 510 - 'text' => substr($string, $cursor), 511 - 'highlight' => false, 512 - ); 513 - } 471 + if (!$results) { 472 + return id(new PHUIInfoView()) 473 + ->setSeverity(PHUIInfoView::SEVERITY_NODATA) 474 + ->appendChild( 475 + pht( 476 + 'The pattern you searched for was not found in the content of any '. 477 + 'files.')); 478 + } 514 479 515 - if ($output) { 516 - $output[0]['text'] = ltrim($output[0]['text']); 517 - } 518 - 519 - foreach ($output as $key => $segment) { 520 - if ($segment['highlight']) { 521 - $output[$key] = phutil_tag('strong', array(), $segment['text']); 522 - } else { 523 - $output[$key] = $segment['text']; 524 - } 525 - } 526 - } 527 - 528 - $string = phutil_tag( 529 - 'pre', 530 - array('class' => 'PhabricatorMonospaced phui-source-fragment'), 531 - $output); 532 - 533 - $path = Filesystem::readablePath($path, $drequest->getPath()); 534 - 535 - $rows[] = array( 536 - phutil_tag('a', array('href' => $href), $path), 537 - $line, 538 - $string, 539 - ); 480 + $grouped = array(); 481 + foreach ($results as $file) { 482 + list($path, $line, $string) = $file; 483 + $grouped[$path][] = array($line, $string); 540 484 } 541 485 542 - $table = id(new AphrontTableView($rows)) 543 - ->setClassName('remarkup-code') 544 - ->setHeaders(array(pht('Path'), pht('Line'), pht('String'))) 545 - ->setColumnClasses(array('', 'n', 'wide')) 546 - ->setNoDataString( 547 - pht( 548 - 'The pattern you searched for was not found in the content of any '. 549 - 'files.')); 550 - 551 - return $table; 552 - } 553 - 554 - private function renderFindResults(array $results) { 555 - $drequest = $this->getDiffusionRequest(); 556 - 557 - $rows = array(); 558 - foreach ($results as $result) { 559 - $href = $drequest->generateURI(array( 560 - 'action' => 'browse', 561 - 'path' => $result, 562 - )); 563 - 564 - $readable = Filesystem::readablePath($result, $drequest->getPath()); 565 - 566 - $rows[] = array( 567 - phutil_tag('a', array('href' => $href), $readable), 568 - ); 486 + $view = array(); 487 + foreach ($grouped as $path => $matches) { 488 + $view[] = id(new DiffusionPatternSearchView()) 489 + ->setPath($path) 490 + ->setMatches($matches) 491 + ->setPattern($pattern) 492 + ->setDiffusionRequest($drequest) 493 + ->render(); 569 494 } 570 495 571 - $table = id(new AphrontTableView($rows)) 572 - ->setHeaders(array(pht('Path'))) 573 - ->setColumnClasses(array('wide')) 574 - ->setNoDataString( 575 - pht( 576 - 'The pattern you searched for did not match the names of any '. 577 - 'files.')); 578 - 579 - return $table; 496 + return $view; 580 497 } 581 498 582 499 private function loadLintMessages() {
+124
src/applications/diffusion/view/DiffusionPatternSearchView.php
··· 1 + <?php 2 + 3 + final class DiffusionPatternSearchView extends DiffusionView { 4 + 5 + private $path; 6 + private $matches; 7 + private $pattern; 8 + 9 + public function setPath($path) { 10 + $this->path = $path; 11 + return $this; 12 + } 13 + 14 + public function setMatches(array $matches) { 15 + $this->matches = $matches; 16 + return $this; 17 + } 18 + 19 + public function setPattern($pattern) { 20 + $this->pattern = $pattern; 21 + return $this; 22 + } 23 + 24 + public function render() { 25 + $drequest = $this->getDiffusionRequest(); 26 + $path = $this->path; 27 + $pattern = $this->pattern; 28 + $rows = array(); 29 + 30 + foreach ($this->matches as $result) { 31 + list($line, $string) = $result; 32 + 33 + $matches = null; 34 + $count = @preg_match_all( 35 + '('.$pattern.')u', 36 + $string, 37 + $matches, 38 + PREG_OFFSET_CAPTURE); 39 + 40 + if (!$count) { 41 + $output = ltrim($string); 42 + } else { 43 + $output = array(); 44 + $cursor = 0; 45 + $length = strlen($string); 46 + foreach ($matches[0] as $match) { 47 + $offset = $match[1]; 48 + if ($cursor != $offset) { 49 + $output[] = array( 50 + 'text' => substr($string, $cursor, $offset), 51 + 'highlight' => false, 52 + ); 53 + } 54 + $output[] = array( 55 + 'text' => $match[0], 56 + 'highlight' => true, 57 + ); 58 + $cursor = $offset + strlen($match[0]); 59 + } 60 + if ($cursor != $length) { 61 + $output[] = array( 62 + 'text' => substr($string, $cursor), 63 + 'highlight' => false, 64 + ); 65 + } 66 + 67 + if ($output) { 68 + $output[0]['text'] = ltrim($output[0]['text']); 69 + } 70 + 71 + foreach ($output as $key => $segment) { 72 + if ($segment['highlight']) { 73 + $output[$key] = phutil_tag('strong', array(), $segment['text']); 74 + } else { 75 + $output[$key] = $segment['text']; 76 + } 77 + } 78 + } 79 + 80 + $string = phutil_tag( 81 + 'pre', 82 + array('class' => 'PhabricatorMonospaced phui-source-fragment'), 83 + $output); 84 + 85 + $href = $drequest->generateURI(array( 86 + 'action' => 'browse', 87 + 'path' => $path, 88 + 'line' => $line, 89 + )); 90 + 91 + $rows[] = array( 92 + phutil_tag('a', array('href' => $href), $line), 93 + $string, 94 + ); 95 + } 96 + 97 + $path_title = Filesystem::readablePath($this->path, $drequest->getPath()); 98 + 99 + $href = $drequest->generateURI(array( 100 + 'action' => 'browse', 101 + 'path' => $path_title, 102 + )); 103 + 104 + $title = phutil_tag('a', array('href' => $href), $path_title); 105 + 106 + 107 + $table = id(new AphrontTableView($rows)) 108 + ->setClassName('remarkup-code') 109 + ->setHeaders(array(pht('Line'), pht('String'))) 110 + ->setColumnClasses(array('n', 'wide')); 111 + 112 + $header = id(new PHUIHeaderView()) 113 + ->setHeader($title); 114 + 115 + $box = id(new PHUIObjectBoxView()) 116 + ->setHeader($header) 117 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 118 + ->setTable($table); 119 + 120 + return $box->render(); 121 + } 122 + 123 + 124 + }
+5
webroot/rsrc/css/application/diffusion/diffusion.css
··· 122 122 color: {$darkbluetext}; 123 123 } 124 124 125 + .diffusion-search-result-header.phui-header-shell { 126 + border: none; 127 + padding-bottom: 24px; 128 + } 129 + 125 130 /* - Search Input ------------------------------------------------------------*/ 126 131 127 132 .diffusion-search-form-view {
+3 -2
webroot/rsrc/css/application/search/search-results.css
··· 12 12 } 13 13 14 14 .phui-source-fragment strong { 15 - background-color: {$lightyellow}; 16 - font-weight: normal; 15 + background-color: {$gentle.highlight}; 16 + font-weight: 600; 17 17 color: {$blacktext}; 18 + letter-spacing: 0.02em; 18 19 } 19 20 20 21 .phui-fulltext-tokens {