Path: blob/master/src/applications/meta/engineextension/PhabricatorSelfHyperlinkEngineExtension.php
12256 views
<?php12final class PhabricatorSelfHyperlinkEngineExtension3extends PhabricatorRemarkupHyperlinkEngineExtension {45const LINKENGINEKEY = 'phabricator-self';67public function processHyperlinks(array $hyperlinks) {8$engine = $this->getEngine();9$viewer = $engine->getConfig('viewer');1011// If we don't have a valid viewer, just bail out. We aren't going to be12// able to do very much.13if (!$viewer) {14return;15}1617$self_links = $this->getSelfLinks($hyperlinks);1819// For links in the form "/X123", we can reasonably guess that they are20// fairly likely to be object names. Try to look them up.21$object_names = array();22foreach ($self_links as $key => $link) {23$uri = new PhutilURI($link->getURI());2425$matches = null;26$path = $uri->getPath();27if (!preg_match('(^/([^/]+)\z)', $path, $matches)) {28continue;29}3031$object_names[$key] = $matches[1];32}3334if ($object_names) {35$object_query = id(new PhabricatorObjectQuery())36->setViewer($viewer)37->withNames($object_names);3839$object_query->execute();4041$object_map = $object_query->getNamedResults();42} else {43$object_map = array();44}4546if ($object_map) {47$object_phids = mpull($object_map, 'getPHID');48} else {49$object_phids = array();50}5152$handles = $viewer->loadHandles($object_phids);5354foreach ($object_names as $key => $object_name) {55$object = idx($object_map, $object_name);56if (!$object) {57continue;58}5960$phid = $object->getPHID();61$handle = $handles[$phid];6263$link = $self_links[$key];64$raw_uri = $link->getURI();65$is_embed = $link->isEmbed();6667$tag = $handle->renderTag()68->setPHID($phid)69->setHref($raw_uri);7071if (!$is_embed) {72$tag->setName($raw_uri);73}7475$link->setResult($tag);7677unset($self_links[$key]);78}7980$key_mentioned = PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS;81$mentioned_phids = $engine->getTextMetadata($key_mentioned, array());82foreach ($object_phids as $object_phid) {83$mentioned_phids[$object_phid] = $object_phid;84}85$engine->setTextMetadata($key_mentioned, $mentioned_phids);86}8788}899091