mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Specialize rendering of self-URIs in the form "/X123"
Summary: Depends on D20510. Ref T5378. When remarkup includes a hyperlink to the current install in the form "/X123" (which is common), load the corresponding object and specialize the rendering. This doesn't cover everything (notably, no handling for Diffusion paths yet), but does cover a lot of the most common cases. The "uri" form preserves the URI as written, but adds an icon, tag, and hovercard. The "{uri}" form is more similar to `{T123}` and shows the object name. Test Plan: {F6440367} Reviewers: amckinley, joshuaspence Reviewed By: joshuaspence Subscribers: joshuaspence Maniphest Tasks: T5378 Differential Revision: https://secure.phabricator.com/D20512
This commit is contained in:
parent
706826bf02
commit
23bfe0c0f6
2 changed files with 90 additions and 0 deletions
|
@ -4548,6 +4548,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSecuritySetupCheck' => 'applications/config/check/PhabricatorSecuritySetupCheck.php',
|
||||
'PhabricatorSelectEditField' => 'applications/transactions/editfield/PhabricatorSelectEditField.php',
|
||||
'PhabricatorSelectSetting' => 'applications/settings/setting/PhabricatorSelectSetting.php',
|
||||
'PhabricatorSelfHyperlinkEngineExtension' => 'applications/meta/engineextension/PhabricatorSelfHyperlinkEngineExtension.php',
|
||||
'PhabricatorSessionsSettingsPanel' => 'applications/settings/panel/PhabricatorSessionsSettingsPanel.php',
|
||||
'PhabricatorSetConfigType' => 'applications/config/type/PhabricatorSetConfigType.php',
|
||||
'PhabricatorSetting' => 'applications/settings/setting/PhabricatorSetting.php',
|
||||
|
@ -10858,6 +10859,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSecuritySetupCheck' => 'PhabricatorSetupCheck',
|
||||
'PhabricatorSelectEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorSelectSetting' => 'PhabricatorSetting',
|
||||
'PhabricatorSelfHyperlinkEngineExtension' => 'PhutilRemarkupHyperlinkEngineExtension',
|
||||
'PhabricatorSessionsSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorSetConfigType' => 'PhabricatorTextConfigType',
|
||||
'PhabricatorSetting' => 'Phobject',
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorSelfHyperlinkEngineExtension
|
||||
extends PhutilRemarkupHyperlinkEngineExtension {
|
||||
|
||||
const LINKENGINEKEY = 'phabricator-self';
|
||||
|
||||
public function processHyperlinks(array $hyperlinks) {
|
||||
$engine = $this->getEngine();
|
||||
$viewer = $engine->getConfig('viewer');
|
||||
|
||||
// If we don't have a valid viewer, just bail out. We aren't going to be
|
||||
// able to do very much.
|
||||
if (!$viewer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find links which point to resources on the Phabricator install itself.
|
||||
// We're going to try to enhance these.
|
||||
$self_links = array();
|
||||
foreach ($hyperlinks as $link) {
|
||||
$uri = $link->getURI();
|
||||
if (PhabricatorEnv::isSelfURI($uri)) {
|
||||
$self_links[] = $link;
|
||||
}
|
||||
}
|
||||
|
||||
// For links in the form "/X123", we can reasonably guess that they are
|
||||
// fairly likely to be object names. Try to look them up.
|
||||
$object_names = array();
|
||||
foreach ($self_links as $key => $link) {
|
||||
$uri = new PhutilURI($link->getURI());
|
||||
|
||||
$matches = null;
|
||||
$path = $uri->getPath();
|
||||
if (!preg_match('(^/([^/]+)\z)', $path, $matches)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$object_names[$key] = $matches[1];
|
||||
}
|
||||
|
||||
if ($object_names) {
|
||||
$object_query = id(new PhabricatorObjectQuery())
|
||||
->setViewer($viewer)
|
||||
->withNames($object_names);
|
||||
|
||||
$object_query->execute();
|
||||
|
||||
$object_map = $object_query->getNamedResults();
|
||||
} else {
|
||||
$object_map = array();
|
||||
}
|
||||
|
||||
if ($object_map) {
|
||||
$handles = $viewer->loadHandles(mpull($object_map, 'getPHID'));
|
||||
} else {
|
||||
$handles = array();
|
||||
}
|
||||
|
||||
foreach ($object_names as $key => $object_name) {
|
||||
$object = idx($object_map, $object_name);
|
||||
if (!$object) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$phid = $object->getPHID();
|
||||
$handle = $handles[$phid];
|
||||
|
||||
$link = $self_links[$key];
|
||||
$raw_uri = $link->getURI();
|
||||
$is_embed = $link->isEmbed();
|
||||
|
||||
$tag = $handle->renderTag()
|
||||
->setPHID($phid)
|
||||
->setHref($raw_uri);
|
||||
|
||||
if (!$is_embed) {
|
||||
$tag->setName($raw_uri);
|
||||
}
|
||||
|
||||
$link->setResult($tag);
|
||||
|
||||
unset($self_links[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue