diff --git a/src/applications/audit/controller/PhabricatorAuditPreviewController.php b/src/applications/audit/controller/PhabricatorAuditPreviewController.php index 4e8f3c688b..98c853d688 100644 --- a/src/applications/audit/controller/PhabricatorAuditPreviewController.php +++ b/src/applications/audit/controller/PhabricatorAuditPreviewController.php @@ -61,7 +61,15 @@ final class PhabricatorAuditPreviewController $phids = array_merge($phids, $ccs); } + $engine = new PhabricatorMarkupEngine(); + $engine->setViewer($user); + $engine->addObject( + $comment, + PhabricatorAuditComment::MARKUP_FIELD_BODY); + $engine->process(); + $view = id(new DiffusionCommentView()) + ->setMarkupEngine($engine) ->setUser($user) ->setComment($comment) ->setIsPreview(true); diff --git a/src/applications/audit/storage/PhabricatorAuditComment.php b/src/applications/audit/storage/PhabricatorAuditComment.php index 1a02343fc4..9ad70ecd1a 100644 --- a/src/applications/audit/storage/PhabricatorAuditComment.php +++ b/src/applications/audit/storage/PhabricatorAuditComment.php @@ -16,11 +16,14 @@ * limitations under the License. */ -final class PhabricatorAuditComment extends PhabricatorAuditDAO { +final class PhabricatorAuditComment extends PhabricatorAuditDAO + implements PhabricatorMarkupInterface { const METADATA_ADDED_AUDITORS = 'added-auditors'; const METADATA_ADDED_CCS = 'added-ccs'; + const MARKUP_FIELD_BODY = 'markup:body'; + protected $phid; protected $actorPHID; protected $targetPHID; @@ -41,4 +44,28 @@ final class PhabricatorAuditComment extends PhabricatorAuditDAO { return PhabricatorPHID::generateNewPHID('ACMT'); } + +/* -( PhabricatorMarkupInterface Implementation )-------------------------- */ + + + public function getMarkupFieldKey($field) { + return 'AC:'.$this->getID(); + } + + public function newMarkupEngine($field) { + return PhabricatorMarkupEngine::newDiffusionMarkupEngine(); + } + + public function getMarkupText($field) { + return $this->getContent(); + } + + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { + return $output; + } + + public function shouldUseMarkupCache($field) { + return (bool)$this->getID(); + } + } diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index 829889bbf7..b9fe53ed84 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -498,7 +498,25 @@ final class DiffusionCommitController extends DiffusionController { $path_map = ipull($path_map, 'path', 'id'); } + $engine = new PhabricatorMarkupEngine(); + $engine->setViewer($user); + + foreach ($comments as $comment) { + $engine->addObject( + $comment, + PhabricatorAuditComment::MARKUP_FIELD_BODY); + } + + foreach ($inlines as $inline) { + $engine->addObject( + $inline, + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); + } + + $engine->process(); + $view = new DiffusionCommentListView(); + $view->setMarkupEngine($engine); $view->setUser($user); $view->setComments($comments); $view->setInlineComments($inlines); diff --git a/src/applications/diffusion/view/DiffusionCommentListView.php b/src/applications/diffusion/view/DiffusionCommentListView.php index 713a2a300e..0f5b1e0a48 100644 --- a/src/applications/diffusion/view/DiffusionCommentListView.php +++ b/src/applications/diffusion/view/DiffusionCommentListView.php @@ -23,6 +23,7 @@ final class DiffusionCommentListView extends AphrontView { private $inlineComments = array(); private $pathMap = array(); private $handles = array(); + private $markupEngine; public function setUser(PhabricatorUser $user) { $this->user = $user; @@ -46,6 +47,15 @@ final class DiffusionCommentListView extends AphrontView { return $this; } + public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) { + $this->markupEngine = $markup_engine; + return $this; + } + + public function getMarkupEngine() { + return $this->markupEngine; + } + public function getRequiredHandlePHIDs() { $phids = array(); foreach ($this->comments as $comment) { @@ -87,6 +97,7 @@ final class DiffusionCommentListView extends AphrontView { $inlines = idx($inline_comments, $comment->getID(), array()); $view = id(new DiffusionCommentView()) + ->setMarkupEngine($this->getMarkupEngine()) ->setComment($comment) ->setInlineComments($inlines) ->setCommentNumber($num) diff --git a/src/applications/diffusion/view/DiffusionCommentView.php b/src/applications/diffusion/view/DiffusionCommentView.php index 46aedc8219..42ef8a11f0 100644 --- a/src/applications/diffusion/view/DiffusionCommentView.php +++ b/src/applications/diffusion/view/DiffusionCommentView.php @@ -26,8 +26,7 @@ final class DiffusionCommentView extends AphrontView { private $pathMap; private $inlineComments; - - private $engine; + private $markupEngine; public function setUser(PhabricatorUser $user) { $this->user = $user; @@ -66,6 +65,15 @@ final class DiffusionCommentView extends AphrontView { return $this; } + public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) { + $this->markupEngine = $markup_engine; + return $this; + } + + public function getMarkupEngine() { + return $this->markupEngine; + } + public function getRequiredHandlePHIDs() { return array($this->comment->getActorPHID()); } @@ -146,14 +154,16 @@ final class DiffusionCommentView extends AphrontView { private function renderContent() { $comment = $this->comment; - $engine = $this->getEngine(); + $engine = $this->getMarkupEngine(); if (!strlen($comment->getContent()) && empty($this->inlineComments)) { return null; } else { return '
'. - $engine->markupText($comment->getContent()). + $engine->getOutput( + $comment, + PhabricatorAuditComment::MARKUP_FIELD_BODY). $this->renderSingleView($this->renderInlines()). '
'; } @@ -164,6 +174,8 @@ final class DiffusionCommentView extends AphrontView { return null; } + $engine = $this->getMarkupEngine(); + $inlines_by_path = mgroup($this->inlineComments, 'getPathID'); $view = new PhabricatorInlineSummaryView(); @@ -179,9 +191,9 @@ final class DiffusionCommentView extends AphrontView { 'id' => $inline->getID(), 'line' => $inline->getLineNumber(), 'length' => $inline->getLineLength(), - 'content' => PhabricatorInlineSummaryView::renderCommentContent( + 'content' => $engine->getOutput( $inline, - $this->getEngine()), + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY), ); } @@ -191,13 +203,6 @@ final class DiffusionCommentView extends AphrontView { return $view; } - private function getEngine() { - if (!$this->engine) { - $this->engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine(); - } - return $this->engine; - } - private function renderHandleList(array $phids) { $result = array(); foreach ($phids as $phid) { diff --git a/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php b/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php index bc7b40c120..58e45e4ea9 100644 --- a/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php +++ b/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php @@ -29,29 +29,6 @@ final class PhabricatorInlineSummaryView extends AphrontView { return $this; } - public static function renderCommentContent( - PhabricatorInlineCommentInterface $inline, - PhutilMarkupEngine $engine) { - - $inline_content = $inline->getContent(); - if (strlen($inline_content)) { - $inline_cache = $inline->getCache(); - if ($inline_cache) { - $inline_content = $inline_cache; - } else { - $inline_content = $engine->markupText($inline_content); - if ($inline->getID()) { - $inline->setCache($inline_content); - $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); - $inline->save(); - unset($unguarded); - } - } - } - - return $inline_content; - } - public function render() { require_celerity_resource('inline-comment-summary-css'); return $this->renderHeader().$this->renderTable();