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

Move paste rendering into SearchEngine

Summary:
Ref T4986. One note:

- I've disabled syntax highlighting in the previews. When we miss caches this is just way way too slow and has frustrated me several times in the past. The value of syntax highlighting these snippets is not huge. We could maybe ajax this in or use it //if// we get a cache hit in the future, but just kill it for the moment.

Test Plan: Viewed pastes. Created a paste panel.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

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

+65 -61
+1 -57
src/applications/paste/controller/PhabricatorPasteListController.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group paste 5 - */ 6 - final class PhabricatorPasteListController extends PhabricatorPasteController 7 - implements PhabricatorApplicationSearchResultsControllerInterface { 3 + final class PhabricatorPasteListController extends PhabricatorPasteController { 8 4 9 5 private $queryKey; 10 6 ··· 26 22 return $this->delegateToController($controller); 27 23 } 28 24 29 - public function renderResultsList( 30 - array $pastes, 31 - PhabricatorSavedQuery $query) { 32 - assert_instances_of($pastes, 'PhabricatorPaste'); 33 - 34 - $user = $this->getRequest()->getUser(); 35 - 36 - $this->loadHandles(mpull($pastes, 'getAuthorPHID')); 37 - 38 - $lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); 39 - 40 - $list = new PHUIObjectItemListView(); 41 - $list->setUser($user); 42 - foreach ($pastes as $paste) { 43 - $created = phabricator_date($paste->getDateCreated(), $user); 44 - $author = $this->getHandle($paste->getAuthorPHID())->renderLink(); 45 - $source_code = $this->buildSourceCodeView($paste, 5)->render(); 46 - 47 - $source_code = phutil_tag( 48 - 'div', 49 - array( 50 - 'class' => 'phabricator-source-code-summary', 51 - ), 52 - $source_code); 53 - 54 - $line_count = count(explode("\n", $paste->getContent())); 55 - $line_count = pht( 56 - '%s Line(s)', 57 - new PhutilNumber($line_count)); 58 - 59 - $title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)')); 60 - 61 - $item = id(new PHUIObjectItemView()) 62 - ->setObjectName('P'.$paste->getID()) 63 - ->setHeader($title) 64 - ->setHref('/P'.$paste->getID()) 65 - ->setObject($paste) 66 - ->addByline(pht('Author: %s', $author)) 67 - ->addIcon('none', $line_count) 68 - ->appendChild($source_code); 69 - 70 - $lang_name = $paste->getLanguage(); 71 - if ($lang_name) { 72 - $lang_name = idx($lang_map, $lang_name, $lang_name); 73 - $item->addIcon('none', $lang_name); 74 - } 75 - 76 - $list->addItem($item); 77 - } 78 - 79 - return $list; 80 - } 81 25 82 26 }
+64 -4
src/applications/paste/query/PhabricatorPasteSearchEngine.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group paste 5 - */ 6 3 final class PhabricatorPasteSearchEngine 7 4 extends PhabricatorApplicationSearchEngine { 8 5 ··· 26 23 27 24 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 28 25 $query = id(new PhabricatorPasteQuery()) 29 - ->needContent(true) 26 + ->needRawContent(true) 30 27 ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())) 31 28 ->withLanguages($saved->getParameter('languages', array())); 32 29 ··· 126 123 return parent::buildSavedQueryFromBuiltin($query_key); 127 124 } 128 125 126 + protected function getRequiredHandlePHIDsForResultList( 127 + array $pastes, 128 + PhabricatorSavedQuery $query) { 129 + return mpull($pastes, 'getAuthorPHID'); 130 + } 131 + 132 + protected function renderResultList( 133 + array $pastes, 134 + PhabricatorSavedQuery $query, 135 + array $handles) { 136 + assert_instances_of($pastes, 'PhabricatorPaste'); 137 + 138 + $viewer = $this->requireViewer(); 139 + 140 + $lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); 141 + 142 + $list = new PHUIObjectItemListView(); 143 + $list->setUser($viewer); 144 + foreach ($pastes as $paste) { 145 + $created = phabricator_date($paste->getDateCreated(), $viewer); 146 + $author = $handles[$paste->getAuthorPHID()]->renderLink(); 147 + 148 + $lines = phutil_split_lines($paste->getRawContent()); 149 + 150 + $preview = id(new PhabricatorSourceCodeView()) 151 + ->setLimit(5) 152 + ->setLines($lines) 153 + ->setURI(new PhutilURI($paste->getURI())); 154 + 155 + $source_code = phutil_tag( 156 + 'div', 157 + array( 158 + 'class' => 'phabricator-source-code-summary', 159 + ), 160 + $preview); 161 + 162 + $line_count = count($lines); 163 + $line_count = pht( 164 + '%s Line(s)', 165 + new PhutilNumber($line_count)); 166 + 167 + $title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)')); 168 + 169 + $item = id(new PHUIObjectItemView()) 170 + ->setObjectName('P'.$paste->getID()) 171 + ->setHeader($title) 172 + ->setHref('/P'.$paste->getID()) 173 + ->setObject($paste) 174 + ->addByline(pht('Author: %s', $author)) 175 + ->addIcon('none', $line_count) 176 + ->appendChild($source_code); 177 + 178 + $lang_name = $paste->getLanguage(); 179 + if ($lang_name) { 180 + $lang_name = idx($lang_map, $lang_name, $lang_name); 181 + $item->addIcon('none', $lang_name); 182 + } 183 + 184 + $list->addItem($item); 185 + } 186 + 187 + return $list; 188 + } 129 189 }