Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14052186
D14427.id34858.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14427.id34858.diff
View Options
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,64 @@
+<?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) {
+ $engine = $this->getEngine();
+ $viewer = $engine->getConfig('viewer');
+ $text_mode = $engine->isTextMode();
+ $mail_mode = $engine->isHTMLMailMode();
+
+ 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 @@
+<?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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 7:07 AM (3 d, 3 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6762657
Default Alt Text
D14427.id34858.diff (4 KB)
Attached To
Mode
D14427: Add Phurl Remarkup
Attached
Detach File
Event Timeline
Log In to Comment