1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

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
This commit is contained in:
epriestley 2013-10-02 13:11:56 -07:00
parent 901bdda6b1
commit 691e73b576
3 changed files with 26 additions and 27 deletions

View file

@ -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) {

View file

@ -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;
}

View file

@ -1,10 +1,10 @@
<?php
final class PhabricatorJumpNavHandler {
public static function jumpPostResponse($jump) {
public static function getJumpResponse(PhabricatorUser $viewer, $jump) {
$jump = trim($jump);
$help_href = PhabricatorEnv::getDocLink(
'article/Jump_Nav_User_Guide.html');
$help_href = PhabricatorEnv::getDocLink('article/Jump_Nav_User_Guide.html');
$patterns = array(
'/^help/i' => '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;
}