2011-01-30 19:37:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionCommentListView extends AphrontView {
|
|
|
|
|
|
|
|
private $comments;
|
|
|
|
private $handles;
|
2011-02-03 04:38:43 +01:00
|
|
|
private $inlines;
|
|
|
|
private $changesets;
|
2011-04-15 02:22:57 +02:00
|
|
|
private $target;
|
2012-01-06 16:36:55 +01:00
|
|
|
private $versusDiffID;
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 23:03:26 +02:00
|
|
|
private $id;
|
2011-01-30 19:37:36 +01:00
|
|
|
|
2011-02-03 04:38:43 +01:00
|
|
|
public function setComments(array $comments) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($comments, 'DifferentialComment');
|
2011-01-30 19:37:36 +01:00
|
|
|
$this->comments = $comments;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-03 04:38:43 +01:00
|
|
|
public function setInlineComments(array $inline_comments) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
2011-02-03 04:38:43 +01:00
|
|
|
$this->inlines = $inline_comments;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-30 19:37:36 +01:00
|
|
|
public function setHandles(array $handles) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
2011-01-30 19:37:36 +01:00
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-03 04:38:43 +01:00
|
|
|
public function setChangesets(array $changesets) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($changesets, 'DifferentialChangeset');
|
2011-02-03 04:38:43 +01:00
|
|
|
$this->changesets = $changesets;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-04-15 02:22:57 +02:00
|
|
|
public function setTargetDiff(DifferentialDiff $target) {
|
|
|
|
$this->target = $target;
|
2012-01-06 16:36:55 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setVersusDiffID($diff_vs) {
|
|
|
|
$this->versusDiffID = $diff_vs;
|
|
|
|
return $this;
|
2011-04-15 02:22:57 +02:00
|
|
|
}
|
|
|
|
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 23:03:26 +02:00
|
|
|
public function getID() {
|
|
|
|
if (!$this->id) {
|
|
|
|
$this->id = celerity_generate_unique_node_id();
|
|
|
|
}
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2011-01-30 19:37:36 +01:00
|
|
|
public function render() {
|
|
|
|
|
|
|
|
require_celerity_resource('differential-revision-comment-list-css');
|
|
|
|
|
2012-10-24 02:33:58 +02:00
|
|
|
$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();
|
2011-01-30 22:20:56 +01:00
|
|
|
|
2011-02-03 04:38:43 +01:00
|
|
|
$inlines = mgroup($this->inlines, 'getCommentID');
|
|
|
|
|
2011-05-31 19:23:31 +02:00
|
|
|
$num = 1;
|
2011-02-05 20:06:56 +01:00
|
|
|
$html = array();
|
2011-01-30 19:37:36 +01:00
|
|
|
foreach ($this->comments as $comment) {
|
|
|
|
$view = new DifferentialRevisionCommentView();
|
|
|
|
$view->setComment($comment);
|
Use phabricator_ time functions in more places
Summary:
Replace some more date() calls with locale-aware calls.
Also, at least on my system, the DateTimeZone / DateTime stuff didn't actually
work and always rendered in UTC. Fixed that.
Test Plan:
Viewed daemon console, differential revisions, files, and maniphest timestamps
in multiple timezones.
Reviewed By: toulouse
Reviewers: toulouse, fratrik, jungejason, aran, tuomaspelkonen
CC: aran, toulouse
Differential Revision: 530
2011-06-26 18:22:52 +02:00
|
|
|
$view->setUser($this->user);
|
2011-01-30 19:37:36 +01:00
|
|
|
$view->setHandles($this->handles);
|
2011-01-30 22:20:56 +01:00
|
|
|
$view->setMarkupEngine($engine);
|
2011-02-03 04:38:43 +01:00
|
|
|
$view->setInlineComments(idx($inlines, $comment->getID(), array()));
|
|
|
|
$view->setChangesets($this->changesets);
|
2011-04-15 02:22:57 +02:00
|
|
|
$view->setTargetDiff($this->target);
|
2012-01-06 16:36:55 +01:00
|
|
|
$view->setVersusDiffID($this->versusDiffID);
|
2012-02-07 23:36:17 +01:00
|
|
|
if ($comment->getAction() == DifferentialAction::ACTION_SUMMARIZE) {
|
|
|
|
$view->setAnchorName('summary');
|
2012-04-05 00:06:45 +02:00
|
|
|
} else if ($comment->getAction() == DifferentialAction::ACTION_TESTPLAN) {
|
2012-02-07 23:36:17 +01:00
|
|
|
$view->setAnchorName('test-plan');
|
|
|
|
} else {
|
|
|
|
$view->setAnchorName('comment-'.$num);
|
|
|
|
$num++;
|
|
|
|
}
|
2011-01-30 19:37:36 +01:00
|
|
|
|
2011-02-05 20:06:56 +01:00
|
|
|
$html[] = $view->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
$objs = array_reverse(array_values($this->comments));
|
|
|
|
$html = array_reverse(array_values($html));
|
|
|
|
$user = $this->user;
|
|
|
|
|
|
|
|
$last_comment = null;
|
|
|
|
// Find the most recent comment by the viewer.
|
|
|
|
foreach ($objs as $position => $comment) {
|
|
|
|
if ($user && ($comment->getAuthorPHID() == $user->getPHID())) {
|
|
|
|
if ($last_comment === null) {
|
|
|
|
$last_comment = $position;
|
|
|
|
} else if ($last_comment == $position - 1) {
|
|
|
|
// If the viewer made several comments in a row, show them all. This
|
|
|
|
// is a spaz rule for epriestley.
|
|
|
|
$last_comment = $position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = array();
|
|
|
|
$hidden = array();
|
|
|
|
if ($last_comment !== null) {
|
|
|
|
foreach ($objs as $position => $comment) {
|
|
|
|
if (!$comment->getID()) {
|
|
|
|
// These are synthetic comments with summary/test plan information.
|
|
|
|
$header[] = $html[$position];
|
|
|
|
unset($html[$position]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($position <= $last_comment) {
|
|
|
|
// Always show comments after the viewer's last comment.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($position < 3) {
|
|
|
|
// Always show the 3 most recent comments.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$hidden[] = $position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($hidden) <= 3) {
|
|
|
|
// Don't hide if there's not much to hide.
|
|
|
|
$hidden = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = array_reverse($header);
|
|
|
|
|
|
|
|
|
|
|
|
$hidden = array_select_keys($html, $hidden);
|
|
|
|
$visible = array_diff_key($html, $hidden);
|
|
|
|
|
|
|
|
$hidden = array_reverse($hidden);
|
|
|
|
$visible = array_reverse($visible);
|
|
|
|
|
|
|
|
if ($hidden) {
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'differential-show-all-comments',
|
|
|
|
array(
|
|
|
|
'markup' => implode("\n", $hidden),
|
|
|
|
));
|
2013-01-31 18:08:02 +01:00
|
|
|
$hidden = javelin_tag(
|
2011-02-05 20:06:56 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'sigil' => "differential-all-comments-container",
|
|
|
|
),
|
2013-01-31 18:08:02 +01:00
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-older-comments-are-hidden',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
pht(
|
2013-02-01 01:07:17 +01:00
|
|
|
'%s older comments are hidden.',
|
|
|
|
new PhutilNumber(count($hidden))),
|
|
|
|
' ',
|
2013-01-31 18:08:02 +01:00
|
|
|
javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-show-all-comments',
|
|
|
|
),
|
|
|
|
pht('Show all comments.')),
|
|
|
|
)));
|
2011-02-05 20:06:56 +01:00
|
|
|
} else {
|
|
|
|
$hidden = null;
|
2011-01-30 19:37:36 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return javelin_tag(
|
Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
2012-08-14 23:03:26 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-comment-list',
|
|
|
|
'id' => $this->getID(),
|
|
|
|
),
|
2013-02-13 23:50:15 +01:00
|
|
|
array_merge($header, array($hidden), $visible));
|
2011-01-30 19:37:36 +01:00
|
|
|
}
|
|
|
|
}
|