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

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

+90
+2
src/__phutil_library_map__.php
··· 4548 4548 'PhabricatorSecuritySetupCheck' => 'applications/config/check/PhabricatorSecuritySetupCheck.php', 4549 4549 'PhabricatorSelectEditField' => 'applications/transactions/editfield/PhabricatorSelectEditField.php', 4550 4550 'PhabricatorSelectSetting' => 'applications/settings/setting/PhabricatorSelectSetting.php', 4551 + 'PhabricatorSelfHyperlinkEngineExtension' => 'applications/meta/engineextension/PhabricatorSelfHyperlinkEngineExtension.php', 4551 4552 'PhabricatorSessionsSettingsPanel' => 'applications/settings/panel/PhabricatorSessionsSettingsPanel.php', 4552 4553 'PhabricatorSetConfigType' => 'applications/config/type/PhabricatorSetConfigType.php', 4553 4554 'PhabricatorSetting' => 'applications/settings/setting/PhabricatorSetting.php', ··· 10858 10859 'PhabricatorSecuritySetupCheck' => 'PhabricatorSetupCheck', 10859 10860 'PhabricatorSelectEditField' => 'PhabricatorEditField', 10860 10861 'PhabricatorSelectSetting' => 'PhabricatorSetting', 10862 + 'PhabricatorSelfHyperlinkEngineExtension' => 'PhutilRemarkupHyperlinkEngineExtension', 10861 10863 'PhabricatorSessionsSettingsPanel' => 'PhabricatorSettingsPanel', 10862 10864 'PhabricatorSetConfigType' => 'PhabricatorTextConfigType', 10863 10865 'PhabricatorSetting' => 'Phobject',
+88
src/applications/meta/engineextension/PhabricatorSelfHyperlinkEngineExtension.php
··· 1 + <?php 2 + 3 + final class PhabricatorSelfHyperlinkEngineExtension 4 + extends PhutilRemarkupHyperlinkEngineExtension { 5 + 6 + const LINKENGINEKEY = 'phabricator-self'; 7 + 8 + public function processHyperlinks(array $hyperlinks) { 9 + $engine = $this->getEngine(); 10 + $viewer = $engine->getConfig('viewer'); 11 + 12 + // If we don't have a valid viewer, just bail out. We aren't going to be 13 + // able to do very much. 14 + if (!$viewer) { 15 + return; 16 + } 17 + 18 + // Find links which point to resources on the Phabricator install itself. 19 + // We're going to try to enhance these. 20 + $self_links = array(); 21 + foreach ($hyperlinks as $link) { 22 + $uri = $link->getURI(); 23 + if (PhabricatorEnv::isSelfURI($uri)) { 24 + $self_links[] = $link; 25 + } 26 + } 27 + 28 + // For links in the form "/X123", we can reasonably guess that they are 29 + // fairly likely to be object names. Try to look them up. 30 + $object_names = array(); 31 + foreach ($self_links as $key => $link) { 32 + $uri = new PhutilURI($link->getURI()); 33 + 34 + $matches = null; 35 + $path = $uri->getPath(); 36 + if (!preg_match('(^/([^/]+)\z)', $path, $matches)) { 37 + continue; 38 + } 39 + 40 + $object_names[$key] = $matches[1]; 41 + } 42 + 43 + if ($object_names) { 44 + $object_query = id(new PhabricatorObjectQuery()) 45 + ->setViewer($viewer) 46 + ->withNames($object_names); 47 + 48 + $object_query->execute(); 49 + 50 + $object_map = $object_query->getNamedResults(); 51 + } else { 52 + $object_map = array(); 53 + } 54 + 55 + if ($object_map) { 56 + $handles = $viewer->loadHandles(mpull($object_map, 'getPHID')); 57 + } else { 58 + $handles = array(); 59 + } 60 + 61 + foreach ($object_names as $key => $object_name) { 62 + $object = idx($object_map, $object_name); 63 + if (!$object) { 64 + continue; 65 + } 66 + 67 + $phid = $object->getPHID(); 68 + $handle = $handles[$phid]; 69 + 70 + $link = $self_links[$key]; 71 + $raw_uri = $link->getURI(); 72 + $is_embed = $link->isEmbed(); 73 + 74 + $tag = $handle->renderTag() 75 + ->setPHID($phid) 76 + ->setHref($raw_uri); 77 + 78 + if (!$is_embed) { 79 + $tag->setName($raw_uri); 80 + } 81 + 82 + $link->setResult($tag); 83 + 84 + unset($self_links[$key]); 85 + } 86 + } 87 + 88 + }