1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 23:40:57 +01:00

When a user pastes a Phabricator URI into the search box, redirect to the URI

Summary:
Depends on D20509. See PHI1224. Ref T5378. With some frequency, I paste URIs into the global search input (I am dumb).

When I do this dumb thing, redirect to the URI as though the global search was a URI bar.

Maybe only I am dumb like this, but I don't think it'll hurt anything.

Test Plan: pasted a URI and hit return; tried to eat a rock

Reviewers: amckinley, joshuaspence

Reviewed By: joshuaspence

Maniphest Tasks: T5378

Differential Revision: https://secure.phabricator.com/D20510
This commit is contained in:
epriestley 2019-05-09 11:20:09 -07:00
parent f2feb0378f
commit 706826bf02
2 changed files with 36 additions and 0 deletions

View file

@ -3040,6 +3040,7 @@ phutil_register_library_map(array(
'PhabricatorDatasourceEditType' => 'applications/transactions/edittype/PhabricatorDatasourceEditType.php',
'PhabricatorDatasourceEngine' => 'applications/search/engine/PhabricatorDatasourceEngine.php',
'PhabricatorDatasourceEngineExtension' => 'applications/search/engineextension/PhabricatorDatasourceEngineExtension.php',
'PhabricatorDatasourceURIEngineExtension' => 'applications/meta/engineextension/PhabricatorDatasourceURIEngineExtension.php',
'PhabricatorDateFormatSetting' => 'applications/settings/setting/PhabricatorDateFormatSetting.php',
'PhabricatorDateTimeSettingsPanel' => 'applications/settings/panel/PhabricatorDateTimeSettingsPanel.php',
'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php',
@ -9082,6 +9083,7 @@ phutil_register_library_map(array(
'PhabricatorDatasourceEditType' => 'PhabricatorPHIDListEditType',
'PhabricatorDatasourceEngine' => 'Phobject',
'PhabricatorDatasourceEngineExtension' => 'Phobject',
'PhabricatorDatasourceURIEngineExtension' => 'PhabricatorDatasourceEngineExtension',
'PhabricatorDateFormatSetting' => 'PhabricatorSelectSetting',
'PhabricatorDateTimeSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
'PhabricatorDebugController' => 'PhabricatorController',

View file

@ -0,0 +1,34 @@
<?php
final class PhabricatorDatasourceURIEngineExtension
extends PhabricatorDatasourceEngineExtension {
public function newQuickSearchDatasources() {
return array();
}
public function newJumpURI($query) {
// If you search for a URI on the local install, just redirect to that
// URI as though you had pasted it into the URI bar.
if (PhabricatorEnv::isSelfURI($query)) {
// Strip off the absolute part of the URI. If we don't, the URI redirect
// validator will get upset that we're performing an unmarked external
// redirect.
// The correct host and protocol may also differ from the host and
// protocol used in the search: for example, if you search for "http://"
// we want to redirect to "https://" if an install is HTTPS, and
// the "isSelfURI()" check includes alternate domains in addition to the
// canonical domain.
$uri = id(new PhutilURI($query))
->setDomain(null)
->setProtocol(null)
->setPort(null);
return phutil_string_cast($uri);
}
return null;
}
}