3 final class PhabricatorPhurlLinkRemarkupRule
extends PhutilRemarkupRule
{
5 public function getPriority() {
9 public function apply($text) {
10 // `((123))` remarkup link to `/u/123`
11 // `((alias))` remarkup link to `/u/alias`
12 return preg_replace_callback(
14 array($this, 'markupLink'),
18 public function markupLink(array $matches) {
19 $engine = $this->getEngine();
20 $viewer = $engine->getConfig('viewer');
22 $text_mode = $engine->isTextMode();
23 $html_mode = $engine->isHTMLMailMode();
25 if (!$this->isFlatText($matches[0])) {
31 $is_monogram = '/^U(?P<id>[1-9]\d*)/';
33 $query = id(new PhabricatorPhurlURLQuery())
36 if (preg_match($is_monogram, $ref, $monogram)) {
37 $query->withIDs(array($monogram[1]));
38 } else if (ctype_digit($ref)) {
39 $query->withIDs(array($ref));
41 $query->withAliases(array($ref));
44 $phurl = $query->executeOne();
49 $uri = $phurl->getRedirectURI();
50 $name = $phurl->getDisplayName();
52 if ($text_mode ||
$html_mode) {
53 $uri = PhabricatorEnv
::getProductionURI($uri);
67 'rel' => 'noreferrer',
72 return $this->getEngine()->storeText($link);