Page MenuHomePhabricator

D14427.id34854.diff
No OneTemporary

D14427.id34854.diff

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',
@@ -6769,6 +6771,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<id>[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,48 @@
+<?php
+
+final class PhabricatorPhurlLinkRemarkupRule extends PhutilRemarkupRule {
+
+ public function getPriority() {
+ return 200.0;
+ }
+
+ public function apply($text) {
+ // `((U123))` remarkup link to `/u/123`
+ // `((alias))` remarkup link to `/u/alias`
+ return preg_replace_callback(
+ '/\(\(([^)]+)\)\)/',
+ array($this, 'markupLink'),
+ $text);
+ }
+
+ public function markupLink(array $matches) {
+ $viewer = $this->getEngine()->getConfig('viewer');
+ $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) {
+ $link = id(new PHUIIconView())
+ ->setHref($phurl->getLongURL())
+ ->setText($phurl->getName());
+
+ return $this->getEngine()->storeText($link);
+ } else {
+ return null;
+ }
+ }
+
+
+}
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 @@
+<?php
+
+final class PhabricatorPhurlRemarkupRule
+ extends PhabricatorObjectRemarkupRule {
+
+ protected function getObjectNamePrefix() {
+ return 'U';
+ }
+
+ protected function loadObjects(array $ids) {
+ $viewer = $this->getEngine()->getConfig('viewer');
+
+ return id(new PhabricatorPhurlURLQuery())
+ ->setViewer($viewer)
+ ->withIDs($ids)
+ ->execute();
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 22, 9:08 PM (4 d, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7740630
Default Alt Text
D14427.id34854.diff (4 KB)

Event Timeline