@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Phurl Remarkup

Summary: Ref T9722, Add Phurl Remarkup as `((id))` or `((alias))`

Test Plan: Add a comment to any object as `((id))` or `((alias))`. Make sure comment renders as a link.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T9722

Differential Revision: https://secure.phabricator.com/D14427

+93
+4
src/__phutil_library_map__.php
··· 2643 2643 'PhabricatorPhurlApplication' => 'applications/phurl/application/PhabricatorPhurlApplication.php', 2644 2644 'PhabricatorPhurlController' => 'applications/phurl/controller/PhabricatorPhurlController.php', 2645 2645 'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php', 2646 + 'PhabricatorPhurlLinkRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php', 2647 + 'PhabricatorPhurlRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php', 2646 2648 'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php', 2647 2649 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 2648 2650 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', ··· 6770 6772 'PhabricatorPhurlApplication' => 'PhabricatorApplication', 6771 6773 'PhabricatorPhurlController' => 'PhabricatorController', 6772 6774 'PhabricatorPhurlDAO' => 'PhabricatorLiskDAO', 6775 + 'PhabricatorPhurlLinkRemarkupRule' => 'PhutilRemarkupRule', 6776 + 'PhabricatorPhurlRemarkupRule' => 'PhabricatorObjectRemarkupRule', 6773 6777 'PhabricatorPhurlSchemaSpec' => 'PhabricatorConfigSchemaSpec', 6774 6778 'PhabricatorPhurlURL' => array( 6775 6779 'PhabricatorPhurlDAO',
+7
src/applications/phurl/application/PhabricatorPhurlApplication.php
··· 26 26 return true; 27 27 } 28 28 29 + public function getRemarkupRules() { 30 + return array( 31 + new PhabricatorPhurlRemarkupRule(), 32 + new PhabricatorPhurlLinkRemarkupRule(), 33 + ); 34 + } 35 + 29 36 public function getRoutes() { 30 37 return array( 31 38 '/U(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLViewController',
+63
src/applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlLinkRemarkupRule extends PhutilRemarkupRule { 4 + 5 + public function getPriority() { 6 + return 200.0; 7 + } 8 + 9 + public function apply($text) { 10 + // `((U123))` remarkup link to `/u/123` 11 + // `((alias))` remarkup link to `/u/alias` 12 + return preg_replace_callback( 13 + '/\(\(([^ )]+)\)\)/', 14 + array($this, 'markupLink'), 15 + $text); 16 + } 17 + 18 + public function markupLink(array $matches) { 19 + $engine = $this->getEngine(); 20 + $viewer = $engine->getConfig('viewer'); 21 + $text_mode = $engine->isTextMode(); 22 + 23 + if (!$this->isFlatText($matches[0])) { 24 + return $matches[0]; 25 + } 26 + 27 + $ref = $matches[1]; 28 + 29 + if (ctype_digit($ref)) { 30 + $phurls = id(new PhabricatorPhurlURLQuery()) 31 + ->setViewer($viewer) 32 + ->withIDs(array($ref)) 33 + ->execute(); 34 + } else { 35 + $phurls = id(new PhabricatorPhurlURLQuery()) 36 + ->setViewer($viewer) 37 + ->withAliases(array($ref)) 38 + ->execute(); 39 + } 40 + 41 + $phurl = head($phurls); 42 + 43 + if ($phurl) { 44 + if ($text_mode) { 45 + return $phurl->getName().' <'.$phurl->getLongURL().'>'; 46 + } 47 + 48 + $link = phutil_tag( 49 + 'a', 50 + array( 51 + 'href' => $phurl->getLongURL(), 52 + 'target' => '_blank', 53 + ), 54 + $phurl->getName()); 55 + 56 + return $this->getEngine()->storeText($link); 57 + } else { 58 + return $matches[0]; 59 + } 60 + } 61 + 62 + 63 + }
+19
src/applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlRemarkupRule 4 + extends PhabricatorObjectRemarkupRule { 5 + 6 + protected function getObjectNamePrefix() { 7 + return 'U'; 8 + } 9 + 10 + protected function loadObjects(array $ids) { 11 + $viewer = $this->getEngine()->getConfig('viewer'); 12 + 13 + return id(new PhabricatorPhurlURLQuery()) 14 + ->setViewer($viewer) 15 + ->withIDs($ids) 16 + ->execute(); 17 + } 18 + 19 + }