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

Replace "search scope" with selectable default behavior

Summary:
Fixes T4365. See discussion in D8123.

This implements the most conservative solution of approaches discussed in D8123. Basically:

- When you search in primary search, we overwrite "query" in your default (topmost) search filter, and execute that.

This doesn't implement any of the other "sticky" stuff, where the query sticks around. Maybe we'll do that eventually, but it gets messy and could be confusing. Practically, this addresses the major use case in the wild, which is to make the menu bar search mean "Open Tasks" by default.

This also removes the old, obsolete "search scope" stuff. A long time ago, searching from within Maniphest would search tasks, etc., but this was pretty weird and confusing and is no longer used, and no one complained when we got rid of it.

Test Plan: Dragged "Open Tasks" to my top search, searched for "asdf", got "asdf in open tasks" results.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: bigo, aran

Maniphest Tasks: T4365

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

+50 -78
-41
src/applications/search/constants/PhabricatorSearchScope.php
··· 1 - <?php 2 - 3 - /** 4 - * @group search 5 - */ 6 - final class PhabricatorSearchScope { 7 - 8 - const SCOPE_ALL = 'all'; 9 - const SCOPE_OPEN_REVISIONS = 'open-revisions'; 10 - const SCOPE_OPEN_TASKS = 'open-tasks'; 11 - const SCOPE_COMMITS = 'commits'; 12 - const SCOPE_WIKI = 'wiki'; 13 - const SCOPE_QUESTIONS = 'questions'; 14 - 15 - public static function getScopeOptions() { 16 - return array( 17 - self::SCOPE_ALL => 'All Documents', 18 - self::SCOPE_OPEN_TASKS => 'Open Tasks', 19 - self::SCOPE_WIKI => 'Wiki Documents', 20 - self::SCOPE_OPEN_REVISIONS => 'Open Revisions', 21 - self::SCOPE_COMMITS => 'Commits', 22 - self::SCOPE_QUESTIONS => 'Ponder Questions', 23 - ); 24 - } 25 - 26 - public static function getScopePlaceholder($scope) { 27 - switch ($scope) { 28 - case self::SCOPE_OPEN_TASKS: 29 - return pht('Search Open Tasks'); 30 - case self::SCOPE_WIKI: 31 - return pht('Search Wiki Documents'); 32 - case self::SCOPE_OPEN_REVISIONS: 33 - return pht('Search Open Revisions'); 34 - case self::SCOPE_COMMITS: 35 - return pht('Search Commits'); 36 - default: 37 - return pht('Search'); 38 - } 39 - } 40 - 41 - }
+44 -1
src/applications/search/controller/PhabricatorSearchController.php
··· 30 30 } 31 31 } 32 32 33 + $engine = new PhabricatorSearchApplicationSearchEngine(); 34 + $engine->setViewer($viewer); 35 + 36 + // NOTE: This is a little weird. If we're coming from primary search, we 37 + // load the user's first search filter and overwrite the "query" part of 38 + // it, then send them to that result page. This is sort of odd, but lets 39 + // users choose a default query like "Open Tasks" in a reasonable way, 40 + // with only this piece of somewhat-sketchy code. See discussion in T4365. 41 + 42 + if ($request->getBool('search:primary')) { 43 + $named_queries = $engine->loadEnabledNamedQueries(); 44 + if ($named_queries) { 45 + $named = head($named_queries); 46 + 47 + $query_key = $named->getQueryKey(); 48 + $saved = null; 49 + if ($engine->isBuiltinQuery($query_key)) { 50 + $saved = $engine->buildSavedQueryFromBuiltin($query_key); 51 + } else { 52 + $saved = id(new PhabricatorSavedQueryQuery()) 53 + ->setViewer($viewer) 54 + ->withQueryKeys(array($query_key)) 55 + ->executeOne(); 56 + } 57 + 58 + if ($saved) { 59 + $saved->setParameter('query', $request->getStr('query')); 60 + $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 61 + try { 62 + $saved->setID(null)->save(); 63 + } catch (AphrontQueryDuplicateKeyException $ex) { 64 + // Ignore, this is just a repeated search. 65 + } 66 + unset($unguarded); 67 + 68 + $results_uri = $engine->getQueryResultsPageURI( 69 + $saved->getQueryKey()).'#R'; 70 + 71 + return id(new AphrontRedirectResponse())->setURI($results_uri); 72 + } 73 + } 74 + } 75 + 33 76 $controller = id(new PhabricatorApplicationSearchController($request)) 34 77 ->setQueryKey($this->queryKey) 35 - ->setSearchEngine(new PhabricatorSearchApplicationSearchEngine()) 78 + ->setSearchEngine($engine) 36 79 ->setUseOffsetPaging(true) 37 80 ->setNavigation($this->buildSideNavView()); 38 81
+1 -12
src/view/page/PhabricatorStandardPageView.php
··· 13 13 private $menuContent; 14 14 private $showChrome = true; 15 15 private $disableConsole; 16 - private $searchDefaultScope; 17 16 private $pageObjects = array(); 18 17 private $applicationMenu; 19 18 ··· 56 55 57 56 public function getShowChrome() { 58 57 return $this->showChrome; 59 - } 60 - 61 - public function setSearchDefaultScope($search_default_scope) { 62 - $this->searchDefaultScope = $search_default_scope; 63 - return $this; 64 - } 65 - 66 - public function getSearchDefaultScope() { 67 - return $this->searchDefaultScope; 68 58 } 69 59 70 60 public function appendPageObjects(array $objs) { ··· 212 202 } 213 203 214 204 $menu = id(new PhabricatorMainMenuView()) 215 - ->setUser($viewer) 216 - ->setDefaultSearchScope($this->getSearchDefaultScope()); 205 + ->setUser($viewer); 217 206 218 207 if ($this->getController()) { 219 208 $menu->setController($this->getController());
+5 -13
src/view/page/menu/PhabricatorMainMenuSearchView.php
··· 2 2 3 3 final class PhabricatorMainMenuSearchView extends AphrontView { 4 4 5 - private $scope; 6 5 private $id; 7 6 8 - public function setScope($scope) { 9 - $this->scope = $scope; 10 - return $this; 11 - } 12 - 13 7 public function getID() { 14 8 if (!$this->id) { 15 9 $this->id = celerity_generate_unique_node_id(); ··· 32 26 'autocomplete' => 'off', 33 27 )); 34 28 35 - $scope = $this->scope; 36 - 37 29 $target = javelin_tag( 38 30 'div', 39 31 array( ··· 49 41 'input' => $search_id, 50 42 'src' => '/typeahead/common/mainsearch/', 51 43 'limit' => 10, 52 - 'placeholder' => PhabricatorSearchScope::getScopePlaceholder($scope), 44 + 'placeholder' => pht('Search'), 53 45 )); 54 46 55 - $scope_input = phutil_tag( 47 + $primary_input = phutil_tag( 56 48 'input', 57 49 array( 58 50 'type' => 'hidden', 59 - 'name' => 'scope', 60 - 'value' => $scope, 51 + 'name' => 'search:primary', 52 + 'value' => 'true', 61 53 )); 62 54 63 55 $form = phabricator_form( ··· 69 61 phutil_tag_div('phabricator-main-menu-search-container', array( 70 62 $input, 71 63 phutil_tag('button', array(), pht('Search')), 72 - $scope_input, 64 + $primary_input, 73 65 $target, 74 66 ))); 75 67
-11
src/view/page/menu/PhabricatorMainMenuView.php
··· 2 2 3 3 final class PhabricatorMainMenuView extends AphrontView { 4 4 5 - private $defaultSearchScope; 6 5 private $controller; 7 6 private $applicationMenu; 8 7 ··· 22 21 23 22 public function getController() { 24 23 return $this->controller; 25 - } 26 - 27 - public function setDefaultSearchScope($default_search_scope) { 28 - $this->defaultSearchScope = $default_search_scope; 29 - return $this; 30 - } 31 - 32 - public function getDefaultSearchScope() { 33 - return $this->defaultSearchScope; 34 24 } 35 25 36 26 public function render() { ··· 105 95 if ($show_search) { 106 96 $search = new PhabricatorMainMenuSearchView(); 107 97 $search->setUser($user); 108 - $search->setScope($this->getDefaultSearchScope()); 109 98 $result = $search; 110 99 111 100 $pref_shortcut = PhabricatorUserPreferences::PREFERENCE_SEARCH_SHORTCUT;