diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 2b6f135645..438725b56b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2615,6 +2615,7 @@ 'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php', 'PhabricatorBoolMailStamp' => 'applications/metamta/stamp/PhabricatorBoolMailStamp.php', 'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php', + 'PhabricatorBugzillaLinkRule' => 'infrastructure/markup/rule/PhabricatorBugzillaLinkRule.php', 'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php', 'PhabricatorBuiltinFileCachePurger' => 'applications/cache/purger/PhabricatorBuiltinFileCachePurger.php', 'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php', @@ -9055,6 +9056,7 @@ 'PhabricatorBoolEditField' => 'PhabricatorEditField', 'PhabricatorBoolMailStamp' => 'PhabricatorMailStamp', 'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation', + 'PhabricatorBugzillaLinkRule' => 'PhutilRemarkupRule', 'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine', 'PhabricatorBuiltinFileCachePurger' => 'PhabricatorCachePurger', 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php index 3ad5304945..aacdeccf6a 100644 --- a/src/infrastructure/markup/PhabricatorMarkupEngine.php +++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php @@ -517,6 +517,8 @@ public static function newMarkupEngine(array $options) { $rules[] = new PhabricatorYoutubeRemarkupRule(); } + $rules[] = new PhabricatorBugzillaLinkRule(); + $rules[] = new PhabricatorIconRemarkupRule(); $rules[] = new PhabricatorEmojiRemarkupRule(); $rules[] = new PhabricatorHandleRemarkupRule(); diff --git a/src/infrastructure/markup/rule/PhabricatorBugzillaLinkRule.php b/src/infrastructure/markup/rule/PhabricatorBugzillaLinkRule.php new file mode 100644 index 0000000000..d9c018e141 --- /dev/null +++ b/src/infrastructure/markup/rule/PhabricatorBugzillaLinkRule.php @@ -0,0 +1,37 @@ +<?php + +final class PhabricatorBugzillaLinkRule extends PhutilRemarkupRule { + + public function getPriority() { + return 360.0; + } + + public function apply($text) { + return preg_replace_callback( + '/bug\s*#?\s*(\d+)(\s*comment\s*\#?\s*(\d+))?/i', + array($this, 'markupBugzillaLink'), + $text + ); + } + + private function markupBugzillaLink(array $matches) { + $text = $matches[0]; + $bug = $matches[1]; + $comment = null; + if (count($matches) == 4) { + $comment = $matches[3]; + } + + $uri = id(new PhutilURI(PhabricatorEnv::getEnvConfig('bugzilla.url'))) + ->setPath('/show_bug.cgi') + ->setQueryParam('id', $bug); + if ($comment) { + $uri->setFragment('c' . $comment); + } + + $link = $this->newTag('a', array('href' => $uri), $text); + + return $this->getEngine()->storeText($link); + } + +}