diff --git a/src/applications/audit/storage/PhabricatorAuditInlineComment.php b/src/applications/audit/storage/PhabricatorAuditInlineComment.php index 9530bbc3d4..ff7a413adb 100644 --- a/src/applications/audit/storage/PhabricatorAuditInlineComment.php +++ b/src/applications/audit/storage/PhabricatorAuditInlineComment.php @@ -120,4 +120,28 @@ final class PhabricatorAuditInlineComment return $this->readField('authorPHID'); } +/* -( PhabricatorMarkupInterface Implementation )-------------------------- */ + + + public function getMarkupFieldKey($field) { + return 'AI:'.$this->getID(); + } + + public function newMarkupEngine($field) { + return PhabricatorMarkupEngine::newDifferentialMarkupEngine(); + } + + public function getMarkupText($field) { + return $this->getContent(); + } + + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { + return $output; + } + + public function shouldUseMarkupCache($field) { + // Only cache submitted comments. + return ($this->getID() && $this->getAuditCommentID()); + } + } diff --git a/src/applications/differential/controller/DifferentialChangesetViewController.php b/src/applications/differential/controller/DifferentialChangesetViewController.php index cc21b12e10..b525114cc3 100644 --- a/src/applications/differential/controller/DifferentialChangesetViewController.php +++ b/src/applications/differential/controller/DifferentialChangesetViewController.php @@ -206,7 +206,16 @@ final class DifferentialChangesetViewController extends DifferentialController { $handles = $this->loadViewerHandles($phids); $parser->setHandles($handles); - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); + $engine = new PhabricatorMarkupEngine(); + $engine->setViewer($request->getUser()); + + foreach ($inlines as $inline) { + $engine->addObject( + $inline, + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); + } + + $engine->process(); $parser->setMarkupEngine($engine); if ($request->isAjax()) { diff --git a/src/applications/differential/controller/DifferentialCommentPreviewController.php b/src/applications/differential/controller/DifferentialCommentPreviewController.php index 2710297be8..b8e0dc02a5 100644 --- a/src/applications/differential/controller/DifferentialCommentPreviewController.php +++ b/src/applications/differential/controller/DifferentialCommentPreviewController.php @@ -33,7 +33,6 @@ final class DifferentialCommentPreviewController $action = $request->getStr('action'); - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); $comment = new DifferentialComment(); $comment->setContent($request->getStr('content')); @@ -58,6 +57,11 @@ final class DifferentialCommentPreviewController $handles = $this->loadViewerHandles($handles); + $engine = new PhabricatorMarkupEngine(); + $engine->setViewer($request->getUser()); + $engine->addObject($comment, DifferentialComment::MARKUP_FIELD_BODY); + $engine->process(); + $view = new DifferentialRevisionCommentView(); $view->setUser($request->getUser()); $view->setComment($comment); diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 5602b79cda..da3f86086f 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -250,7 +250,7 @@ final class DifferentialChangesetParser { return $this; } - public function setMarkupEngine(PhutilMarkupEngine $engine) { + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { $this->markupEngine = $engine; return $this; } diff --git a/src/applications/differential/storage/DifferentialComment.php b/src/applications/differential/storage/DifferentialComment.php index 4cf73d26ab..50737a6d7c 100644 --- a/src/applications/differential/storage/DifferentialComment.php +++ b/src/applications/differential/storage/DifferentialComment.php @@ -16,13 +16,16 @@ * limitations under the License. */ -final class DifferentialComment extends DifferentialDAO { +final class DifferentialComment extends DifferentialDAO + implements PhabricatorMarkupInterface { const METADATA_ADDED_REVIEWERS = 'added-reviewers'; const METADATA_REMOVED_REVIEWERS = 'removed-reviewers'; const METADATA_ADDED_CCS = 'added-ccs'; const METADATA_DIFF_ID = 'diff-id'; + const MARKUP_FIELD_BODY = 'markup:body'; + protected $authorPHID; protected $revisionID; protected $action; @@ -31,6 +34,13 @@ final class DifferentialComment extends DifferentialDAO { protected $metadata = array(); protected $contentSource; + private $arbitraryDiffForFacebook; + + public function giveFacebookSomeArbitraryDiff(DifferentialDiff $diff) { + $this->arbitraryDiffForFacebook = $diff; + return $this; + } + public function getConfiguration() { return array( self::CONFIG_SERIALIZATION => array( @@ -48,4 +58,46 @@ final class DifferentialComment extends DifferentialDAO { return PhabricatorContentSource::newFromSerialized($this->contentSource); } + + public function getMarkupFieldKey($field) { + if ($this->getID()) { + return 'DC:'.$this->getID(); + } + + // The summary and test plan render as comments, but do not have IDs. + // They are also mutable. Build keys using content hashes. + $hash = PhabricatorHash::digest($this->getMarkupText($field)); + return 'DC:'.$hash; + } + + public function newMarkupEngine($field) { + return PhabricatorMarkupEngine::newDifferentialMarkupEngine( + array( + 'differential.diff' => $this->arbitraryDiffForFacebook, + )); + } + + public function getMarkupText($field) { + return $this->getContent(); + } + + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { + return $output; + } + + public function shouldUseMarkupCache($field) { + if ($this->getID()) { + return true; + } + + $action = $this->getAction(); + switch ($action) { + case DifferentialAction::ACTION_SUMMARIZE: + case DifferentialAction::ACTION_TESTPLAN: + return true; + } + + return false; + } + } diff --git a/src/applications/differential/storage/DifferentialInlineComment.php b/src/applications/differential/storage/DifferentialInlineComment.php index 89b7833290..79336ad9c3 100644 --- a/src/applications/differential/storage/DifferentialInlineComment.php +++ b/src/applications/differential/storage/DifferentialInlineComment.php @@ -121,4 +121,29 @@ final class DifferentialInlineComment return $this->readField('authorPHID'); } + +/* -( PhabricatorMarkupInterface Implementation )-------------------------- */ + + + public function getMarkupFieldKey($field) { + return 'DI:'.$this->getID(); + } + + public function newMarkupEngine($field) { + return PhabricatorMarkupEngine::newDifferentialMarkupEngine(); + } + + public function getMarkupText($field) { + return $this->getContent(); + } + + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { + return $output; + } + + public function shouldUseMarkupCache($field) { + // Only cache submitted comments. + return ($this->getID() && $this->getCommentID()); + } + } diff --git a/src/applications/differential/view/DifferentialInlineCommentView.php b/src/applications/differential/view/DifferentialInlineCommentView.php index a52578a59e..2ba429842f 100644 --- a/src/applications/differential/view/DifferentialInlineCommentView.php +++ b/src/applications/differential/view/DifferentialInlineCommentView.php @@ -48,7 +48,7 @@ final class DifferentialInlineCommentView extends AphrontView { return $this; } - public function setMarkupEngine(PhutilMarkupEngine $engine) { + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { $this->markupEngine = $engine; return $this; } @@ -199,19 +199,9 @@ final class DifferentialInlineCommentView extends AphrontView { $links = null; } - $cache = $inline->getCache(); - if (strlen($cache)) { - $content = $cache; - } else { - $content = $this->markupEngine->markupText($content); - if ($inline->getID()) { - $inline->setCache($content); - - $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); - $inline->save(); - unset($unguarded); - } - } + $content = $this->markupEngine->getOutput( + $inline, + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); if ($this->preview) { $anchor = null; diff --git a/src/applications/differential/view/DifferentialRevisionCommentListView.php b/src/applications/differential/view/DifferentialRevisionCommentListView.php index d1bbf4c1a1..0974eca7d1 100644 --- a/src/applications/differential/view/DifferentialRevisionCommentListView.php +++ b/src/applications/differential/view/DifferentialRevisionCommentListView.php @@ -77,9 +77,23 @@ final class DifferentialRevisionCommentListView extends AphrontView { require_celerity_resource('differential-revision-comment-list-css'); - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(array( - 'differential.diff' => $this->target - )); + $engine = new PhabricatorMarkupEngine(); + $engine->setViewer($this->user); + foreach ($this->comments as $comment) { + $comment->giveFacebookSomeArbitraryDiff($this->target); + + $engine->addObject( + $comment, + DifferentialComment::MARKUP_FIELD_BODY); + } + + foreach ($this->inlines as $inline) { + $engine->addObject( + $inline, + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); + } + + $engine->process(); $inlines = mgroup($this->inlines, 'getCommentID'); diff --git a/src/applications/differential/view/DifferentialRevisionCommentView.php b/src/applications/differential/view/DifferentialRevisionCommentView.php index 2f7b795f39..2ba1fb39e2 100644 --- a/src/applications/differential/view/DifferentialRevisionCommentView.php +++ b/src/applications/differential/view/DifferentialRevisionCommentView.php @@ -40,7 +40,7 @@ final class DifferentialRevisionCommentView extends AphrontView { return $this; } - public function setMarkupEngine($markup_engine) { + public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) { $this->markupEngine = $markup_engine; return $this; } @@ -104,19 +104,11 @@ final class DifferentialRevisionCommentView extends AphrontView { $hide_comments = true; if (strlen(rtrim($content))) { $hide_comments = false; - $cache = $comment->getCache(); - if (strlen($cache)) { - $content = $cache; - } else { - $content = $this->markupEngine->markupText($content); - if ($comment->getID()) { - $comment->setCache($content); - $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); - $comment->save(); - unset($unguarded); - } - } + $content = $this->markupEngine->getOutput( + $comment, + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); + $content = '