From 691e73b576e240223fb720494845da0a9cd6f6bb Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 2 Oct 2013 13:11:56 -0700 Subject: [PATCH] Make jump nav use object name queries Summary: Cleans up jump nav so it doesn't hard code a bunch of application behaviors. It still hard-codes a few, but few//er//? Test Plan: Jumped to stuff like `D12`, `d`, `@dog`, `p admins only`, etc. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7196 --- .../PhabricatorDirectoryMainController.php | 5 ++- .../PhabricatorSearchController.php | 4 +- .../engine/PhabricatorJumpNavHandler.php | 44 +++++++++---------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/applications/directory/controller/PhabricatorDirectoryMainController.php b/src/applications/directory/controller/PhabricatorDirectoryMainController.php index bbb80fea0b..0936d0a361 100644 --- a/src/applications/directory/controller/PhabricatorDirectoryMainController.php +++ b/src/applications/directory/controller/PhabricatorDirectoryMainController.php @@ -76,10 +76,11 @@ final class PhabricatorDirectoryMainController private function buildJumpResponse() { $request = $this->getRequest(); - $jump = $request->getStr('jump'); - $response = PhabricatorJumpNavHandler::jumpPostResponse($jump); + $response = PhabricatorJumpNavHandler::getJumpResponse( + $request->getUser(), + $jump); if ($response) { diff --git a/src/applications/search/controller/PhabricatorSearchController.php b/src/applications/search/controller/PhabricatorSearchController.php index cde4501464..79f566a128 100644 --- a/src/applications/search/controller/PhabricatorSearchController.php +++ b/src/applications/search/controller/PhabricatorSearchController.php @@ -36,7 +36,9 @@ final class PhabricatorSearchController $pref_jump = PhabricatorUserPreferences::PREFERENCE_SEARCHBAR_JUMP; if ($request->getStr('jump') != 'no' && $user && $user->loadPreferences()->getPreference($pref_jump, 1)) { - $response = PhabricatorJumpNavHandler::jumpPostResponse($query_str); + $response = PhabricatorJumpNavHandler::getJumpResponse( + $user, + $query_str); } else { $response = null; } diff --git a/src/applications/search/engine/PhabricatorJumpNavHandler.php b/src/applications/search/engine/PhabricatorJumpNavHandler.php index 6087033305..b0e80962f0 100644 --- a/src/applications/search/engine/PhabricatorJumpNavHandler.php +++ b/src/applications/search/engine/PhabricatorJumpNavHandler.php @@ -1,10 +1,10 @@ 'uri:'.$help_href, @@ -15,18 +15,14 @@ final class PhabricatorJumpNavHandler { '/^t$/i' => 'uri:/maniphest/', '/^p$/i' => 'uri:/project/', '/^u$/i' => 'uri:/people/', - '/^r([A-Z]+)$/' => 'repository', - '/^r([A-Z]+)(\S+)$/' => 'commit', - '/^d(\d+)$/i' => 'revision', - '/^t(\d+)$/i' => 'task', - '/^p(\d+)$/i' => 'paste', '/^p\s+(.+)$/i' => 'project', + '/^#(.+)$/i' => 'project', '/^u\s+(\S+)$/i' => 'user', + '/^@(.+)$/i' => 'user', '/^task:\s*(.+)/i' => 'create-task', '/^(?:s|symbol)\s+(\S+)/i' => 'find-symbol', ); - foreach ($patterns as $pattern => $effect) { $matches = null; if (preg_match($pattern, $jump, $matches)) { @@ -35,24 +31,9 @@ final class PhabricatorJumpNavHandler { ->setURI(substr($effect, 4)); } else { switch ($effect) { - case 'repository': - return id(new AphrontRedirectResponse()) - ->setURI('/diffusion/'.$matches[1].'/'); - case 'commit': - return id(new AphrontRedirectResponse()) - ->setURI('/'.$matches[0]); - case 'revision': - return id(new AphrontRedirectResponse()) - ->setURI('/D'.$matches[1]); - case 'task': - return id(new AphrontRedirectResponse()) - ->setURI('/T'.$matches[1]); case 'user': return id(new AphrontRedirectResponse()) ->setURI('/p/'.$matches[1].'/'); - case 'paste': - return id(new AphrontRedirectResponse()) - ->setURI('/P'.$matches[1]); case 'project': $project = self::findCloselyNamedProject($matches[1]); if ($project) { @@ -83,6 +64,21 @@ final class PhabricatorJumpNavHandler { } } + // If none of the patterns matched, look for an object by name. + $objects = id(new PhabricatorObjectQuery()) + ->setViewer($viewer) + ->withNames(array($jump)) + ->execute(); + + if (count($objects) == 1) { + $handle = id(new PhabricatorHandleQuery()) + ->setViewer($viewer) + ->withPHIDs(mpull($objects, 'getPHID')) + ->executeOne(); + + return id(new AphrontRedirectResponse())->setURI($handle->getURI()); + } + return null; }