diff --git a/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php b/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php index 723322fc5b..74c7a853c6 100644 --- a/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php +++ b/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php @@ -1,290 +1,292 @@ comment = $comment; return $this; } public function setHandles(array $handles) { $this->handles = $handles; return $this; } public function setMarkupEngine($markup_engine) { $this->markupEngine = $markup_engine; return $this; } public function setPreview($preview) { $this->preview = $preview; return $this; } public function setInlineComments(array $inline_comments) { $this->inlines = $inline_comments; return $this; } public function setChangesets(array $changesets) { // Ship these in sorted by getSortKey() and keyed by ID... or else! $this->changesets = $changesets; return $this; } public function setTargetDiff($target) { $this->target = $target; } public function setCommentNumber($comment_number) { $this->commentNumber = $comment_number; return $this; } public function setUser(PhabricatorUser $user) { $this->user = $user; return $this; } public function render() { if (!$this->user) { throw new Exception("Call setUser() before rendering!"); } require_celerity_resource('phabricator-remarkup-css'); require_celerity_resource('differential-revision-comment-css'); $comment = $this->comment; $action = $comment->getAction(); $action_class = 'differential-comment-action-'.phutil_escape_html($action); if ($this->preview) { $date = 'COMMENT PREVIEW'; } else { $date = phabricator_datetime($comment->getDateCreated(), $this->user); } $info = array($date); $comment_anchor = null; $num = $this->commentNumber; if ($num && !$this->preview) { Javelin::initBehavior('phabricator-watch-anchor'); $info[] = phutil_render_tag( 'a', array( 'name' => 'comment-'.$num, 'href' => '#comment-'.$num, ), 'Comment D'.$comment->getRevisionID().'#'.$num); $comment_anchor = 'anchor-comment-'.$num; } $info = implode(' · ', $info); $author = $this->handles[$comment->getAuthorPHID()]; $author_link = $author->renderLink(); $verb = DifferentialAction::getActionPastTenseVerb($comment->getAction()); $verb = phutil_escape_html($verb); $content = $comment->getContent(); $head_content = null; if (strlen(rtrim($content))) { $title = "{$author_link} {$verb} this revision:"; $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 = '
'. $content. '
'; } else { $title = null; $head_content = '
'. "

{$author_link} {$verb} this revision.

". '
'; $content = null; } if ($this->inlines) { $inline_render = array(); $inlines = $this->inlines; $changesets = $this->changesets; $inlines_by_changeset = mgroup($inlines, 'getChangesetID'); $inlines_by_changeset = array_select_keys( $inlines_by_changeset, array_keys($this->changesets)); $inline_render[] = ''; foreach ($inlines_by_changeset as $changeset_id => $inlines) { $changeset = $changesets[$changeset_id]; $inlines = msort($inlines, 'getLineNumber'); $inline_render[] = ''. ''. ''; foreach ($inlines as $inline) { if (!$inline->getLineLength()) { $lines = $inline->getLineNumber(); } else { $lines = $inline->getLineNumber()."\xE2\x80\x93". ($inline->getLineNumber() + $inline->getLineLength()); } if (!$this->target || $changeset->getDiffID() === $this->target->getID()) { $lines = phutil_render_tag( 'a', array( 'href' => '#inline-'.$inline->getID(), 'class' => 'num', ), $lines); } $inline_content = $inline->getContent(); if (strlen($inline_content)) { $inline_cache = $inline->getCache(); if ($inline_cache) { $inline_content = $inline_cache; } else { $inline_content = $this->markupEngine->markupText( $inline_content); if ($inline->getID()) { $inline->setCache($inline_content); + $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $inline->save(); + unset($unguarded); } } } $inline_render[] = ''. ''. ''. ''; } } $inline_render[] = '
'. phutil_escape_html($changeset->getFileName()). '
'.$lines.''. '
'. $inline_content. '
'. '
'; $inline_render = implode("\n", $inline_render); $inline_render = '
'. 'Inline Comments'. '
'. $inline_render; } else { $inline_render = null; } $background = null; $uri = $author->getImageURI(); if ($uri) { $background = "background-image: url('{$uri}');"; } $metadata_blocks = array(); $metadata = $comment->getMetadata(); $added_reviewers = idx( $metadata, DifferentialComment::METADATA_ADDED_REVIEWERS); if ($added_reviewers) { $reviewers = 'Added reviewers: '.$this->renderHandleList( $added_reviewers); $metadata_blocks[] = $reviewers; } $added_ccs = idx( $metadata, DifferentialComment::METADATA_ADDED_CCS); if ($added_ccs) { $ccs = 'Added CCs: '.$this->renderHandleList($added_ccs); $metadata_blocks[] = $ccs; } if ($metadata_blocks) { $metadata_blocks = '
'. implode("\n", $metadata_blocks). '
'; } else { $metadata_blocks = null; } return phutil_render_tag( 'div', array( 'class' => "differential-comment {$action_class}", 'id' => $comment_anchor, ), '
'. ''.$info.''. ''.$title.''. '
'. '
'. '
'. '
'. $head_content. $metadata_blocks. '
'. $content. '
'. $inline_render. '
'. '
'); } private function renderHandleList(array $phids) { $result = array(); foreach ($phids as $phid) { $result[] = $this->handles[$phid]->renderLink(); } return implode(', ', $result); } }