diff --git a/src/applications/paste/controller/PhabricatorPasteListController.php b/src/applications/paste/controller/PhabricatorPasteListController.php --- a/src/applications/paste/controller/PhabricatorPasteListController.php +++ b/src/applications/paste/controller/PhabricatorPasteListController.php @@ -1,10 +1,6 @@ delegateToController($controller); } - public function renderResultsList( - array $pastes, - PhabricatorSavedQuery $query) { - assert_instances_of($pastes, 'PhabricatorPaste'); - - $user = $this->getRequest()->getUser(); - - $this->loadHandles(mpull($pastes, 'getAuthorPHID')); - - $lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); - - $list = new PHUIObjectItemListView(); - $list->setUser($user); - foreach ($pastes as $paste) { - $created = phabricator_date($paste->getDateCreated(), $user); - $author = $this->getHandle($paste->getAuthorPHID())->renderLink(); - $source_code = $this->buildSourceCodeView($paste, 5)->render(); - - $source_code = phutil_tag( - 'div', - array( - 'class' => 'phabricator-source-code-summary', - ), - $source_code); - - $line_count = count(explode("\n", $paste->getContent())); - $line_count = pht( - '%s Line(s)', - new PhutilNumber($line_count)); - - $title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)')); - - $item = id(new PHUIObjectItemView()) - ->setObjectName('P'.$paste->getID()) - ->setHeader($title) - ->setHref('/P'.$paste->getID()) - ->setObject($paste) - ->addByline(pht('Author: %s', $author)) - ->addIcon('none', $line_count) - ->appendChild($source_code); - - $lang_name = $paste->getLanguage(); - if ($lang_name) { - $lang_name = idx($lang_map, $lang_name, $lang_name); - $item->addIcon('none', $lang_name); - } - - $list->addItem($item); - } - - return $list; - } } diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php --- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php +++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php @@ -1,8 +1,5 @@ needContent(true) + ->needRawContent(true) ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())) ->withLanguages($saved->getParameter('languages', array())); @@ -126,4 +123,67 @@ return parent::buildSavedQueryFromBuiltin($query_key); } + protected function getRequiredHandlePHIDsForResultList( + array $pastes, + PhabricatorSavedQuery $query) { + return mpull($pastes, 'getAuthorPHID'); + } + + protected function renderResultList( + array $pastes, + PhabricatorSavedQuery $query, + array $handles) { + assert_instances_of($pastes, 'PhabricatorPaste'); + + $viewer = $this->requireViewer(); + + $lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); + + $list = new PHUIObjectItemListView(); + $list->setUser($viewer); + foreach ($pastes as $paste) { + $created = phabricator_date($paste->getDateCreated(), $viewer); + $author = $handles[$paste->getAuthorPHID()]->renderLink(); + + $lines = phutil_split_lines($paste->getRawContent()); + + $preview = id(new PhabricatorSourceCodeView()) + ->setLimit(5) + ->setLines($lines) + ->setURI(new PhutilURI($paste->getURI())); + + $source_code = phutil_tag( + 'div', + array( + 'class' => 'phabricator-source-code-summary', + ), + $preview); + + $line_count = count($lines); + $line_count = pht( + '%s Line(s)', + new PhutilNumber($line_count)); + + $title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)')); + + $item = id(new PHUIObjectItemView()) + ->setObjectName('P'.$paste->getID()) + ->setHeader($title) + ->setHref('/P'.$paste->getID()) + ->setObject($paste) + ->addByline(pht('Author: %s', $author)) + ->addIcon('none', $line_count) + ->appendChild($source_code); + + $lang_name = $paste->getLanguage(); + if ($lang_name) { + $lang_name = idx($lang_map, $lang_name, $lang_name); + $item->addIcon('none', $lang_name); + } + + $list->addItem($item); + } + + return $list; + } }