diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2643,6 +2643,8 @@ 'PhabricatorPhurlApplication' => 'applications/phurl/application/PhabricatorPhurlApplication.php', 'PhabricatorPhurlController' => 'applications/phurl/controller/PhabricatorPhurlController.php', 'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php', + 'PhabricatorPhurlLinkRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php', + 'PhabricatorPhurlRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php', 'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php', 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', @@ -6770,6 +6772,8 @@ 'PhabricatorPhurlApplication' => 'PhabricatorApplication', 'PhabricatorPhurlController' => 'PhabricatorController', 'PhabricatorPhurlDAO' => 'PhabricatorLiskDAO', + 'PhabricatorPhurlLinkRemarkupRule' => 'PhutilRemarkupRule', + 'PhabricatorPhurlRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'PhabricatorPhurlSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorPhurlURL' => array( 'PhabricatorPhurlDAO', diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php --- a/src/applications/phurl/application/PhabricatorPhurlApplication.php +++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php @@ -26,6 +26,13 @@ return true; } + public function getRemarkupRules() { + return array( + new PhabricatorPhurlRemarkupRule(), + new PhabricatorPhurlLinkRemarkupRule(), + ); + } + public function getRoutes() { return array( '/U(?P[1-9]\d*)' => 'PhabricatorPhurlURLViewController', diff --git a/src/applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php b/src/applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php new file mode 100644 --- /dev/null +++ b/src/applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php @@ -0,0 +1,63 @@ +getEngine(); + $viewer = $engine->getConfig('viewer'); + $text_mode = $engine->isTextMode(); + + if (!$this->isFlatText($matches[0])) { + return $matches[0]; + } + + $ref = $matches[1]; + + if (ctype_digit($ref)) { + $phurls = id(new PhabricatorPhurlURLQuery()) + ->setViewer($viewer) + ->withIDs(array($ref)) + ->execute(); + } else { + $phurls = id(new PhabricatorPhurlURLQuery()) + ->setViewer($viewer) + ->withAliases(array($ref)) + ->execute(); + } + + $phurl = head($phurls); + + if ($phurl) { + if ($text_mode) { + return $phurl->getName().' <'.$phurl->getLongURL().'>'; + } + + $link = phutil_tag( + 'a', + array( + 'href' => $phurl->getLongURL(), + 'target' => '_blank', + ), + $phurl->getName()); + + return $this->getEngine()->storeText($link); + } else { + return $matches[0]; + } + } + + +} diff --git a/src/applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php b/src/applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php new file mode 100644 --- /dev/null +++ b/src/applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php @@ -0,0 +1,19 @@ +getEngine()->getConfig('viewer'); + + return id(new PhabricatorPhurlURLQuery()) + ->setViewer($viewer) + ->withIDs($ids) + ->execute(); + } + +}