Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14351982
D15488.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D15488.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
@@ -2454,6 +2454,7 @@
'PhabricatorHandlePool' => 'applications/phid/handle/pool/PhabricatorHandlePool.php',
'PhabricatorHandlePoolTestCase' => 'applications/phid/handle/pool/__tests__/PhabricatorHandlePoolTestCase.php',
'PhabricatorHandleQuery' => 'applications/phid/query/PhabricatorHandleQuery.php',
+ 'PhabricatorHandleRemarkupRule' => 'applications/phid/remarkup/PhabricatorHandleRemarkupRule.php',
'PhabricatorHandlesEditField' => 'applications/transactions/editfield/PhabricatorHandlesEditField.php',
'PhabricatorHarbormasterApplication' => 'applications/harbormaster/application/PhabricatorHarbormasterApplication.php',
'PhabricatorHarbormasterConfigOptions' => 'applications/harbormaster/config/PhabricatorHarbormasterConfigOptions.php',
@@ -6897,6 +6898,7 @@
'PhabricatorHandlePool' => 'Phobject',
'PhabricatorHandlePoolTestCase' => 'PhabricatorTestCase',
'PhabricatorHandleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorHandleRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorHandlesEditField' => 'PhabricatorPHIDListEditField',
'PhabricatorHarbormasterApplication' => 'PhabricatorApplication',
'PhabricatorHarbormasterConfigOptions' => 'PhabricatorApplicationConfigOptions',
diff --git a/src/applications/phid/remarkup/PhabricatorHandleRemarkupRule.php b/src/applications/phid/remarkup/PhabricatorHandleRemarkupRule.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phid/remarkup/PhabricatorHandleRemarkupRule.php
@@ -0,0 +1,109 @@
+<?php
+
+final class PhabricatorHandleRemarkupRule extends PhutilRemarkupRule {
+
+ const KEY_RULE_HANDLE = 'rule.handle';
+ const KEY_RULE_HANDLE_ORIGINAL = 'rule.handle.original';
+
+ public function apply($text) {
+ return preg_replace_callback(
+ '/{(PHID-[a-zA-Z0-9-]*)}/',
+ array($this, 'markupHandle'),
+ $text);
+ }
+
+ public function markupHandle(array $matches) {
+ $engine = $this->getEngine();
+ $viewer = $engine->getConfig('viewer');
+
+ if (!$this->isFlatText($matches[0])) {
+ return $matches[0];
+ }
+
+ $phid_type = phid_get_type($matches[1]);
+ if ($phid_type == PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) {
+ return $matches[0];
+ }
+
+ $token = $engine->storeText($matches[0]);
+ if ($engine->isTextMode()) {
+ return $token;
+ }
+
+ $original_key = self::KEY_RULE_HANDLE_ORIGINAL;
+ $original = $engine->getTextMetadata($original_key, array());
+ $original[$token] = $matches[0];
+ $engine->setTextMetadata($original_key, $original);
+
+ $metadata_key = self::KEY_RULE_HANDLE;
+ $metadata = $engine->getTextMetadata($metadata_key, array());
+ $phid = $matches[1];
+ if (empty($metadata[$phid])) {
+ $metadata[$phid] = array();
+ }
+ $metadata[$phid][] = $token;
+ $engine->setTextMetadata($metadata_key, $metadata);
+
+ return $token;
+ }
+
+ public function didMarkupText() {
+ $engine = $this->getEngine();
+
+ $metadata_key = self::KEY_RULE_HANDLE;
+
+ $metadata = $engine->getTextMetadata($metadata_key, array());
+ if (empty($metadata)) {
+ // No mentions, or we already processed them.
+ return;
+ }
+
+ $original_key = self::KEY_RULE_HANDLE_ORIGINAL;
+ $original = $engine->getTextMetadata($original_key, array());
+
+ $phids = array_keys($metadata);
+
+ $handles = id(new PhabricatorHandleQuery())
+ ->setViewer($this->getEngine()->getConfig('viewer'))
+ ->withPHIDs($phids)
+ ->execute();
+
+ foreach ($metadata as $phid => $tokens) {
+ $handle = idx($handles, $phid);
+
+ if ($handle->isComplete()) {
+ if ($engine->isHTMLMailMode()) {
+ $href = $handle->getURI();
+ $href = PhabricatorEnv::getProductionURI($href);
+
+ $link = phutil_tag(
+ 'a',
+ array(
+ 'href' => $href,
+ 'style' => '
+ border-color: #f1f7ff;
+ color: #19558d;
+ background-color: #f1f7ff;
+ border: 1px solid transparent;
+ border-radius: 3px;
+ font-weight: bold;
+ padding: 0 4px;',
+ ),
+ $handle->getLinkName());
+ } else {
+ $link = $handle->renderTag();
+ $link->setPHID($phid);
+ }
+ foreach ($tokens as $token) {
+ $engine->overwriteStoredText($token, $link);
+ }
+ } else {
+ foreach ($tokens as $token) {
+ $engine->overwriteStoredText($token, idx($original, $token));
+ }
+ }
+ }
+
+ $engine->setTextMetadata($metadata_key, array());
+ }
+}
diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php
--- a/src/infrastructure/markup/PhabricatorMarkupEngine.php
+++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php
@@ -494,6 +494,7 @@
$rules[] = new PhabricatorIconRemarkupRule();
$rules[] = new PhabricatorEmojiRemarkupRule();
+ $rules[] = new PhabricatorHandleRemarkupRule();
$applications = PhabricatorApplication::getAllInstalledApplications();
foreach ($applications as $application) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 12:03 PM (20 h, 47 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6910329
Default Alt Text
D15488.diff (5 KB)
Attached To
Mode
D15488: Remarkup rule for rendering PHIDs as handles
Attached
Detach File
Event Timeline
Log In to Comment