2011-02-02 01:42:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
final class DifferentialInlineCommentView extends AphrontView {
|
|
|
|
|
|
|
|
private $inlineComment;
|
|
|
|
private $onRight;
|
|
|
|
private $buildScaffolding;
|
|
|
|
private $handles;
|
|
|
|
private $markupEngine;
|
2011-02-02 19:10:25 +01:00
|
|
|
private $editable;
|
2011-02-02 01:42:36 +01:00
|
|
|
|
|
|
|
public function setInlineComment(DifferentialInlineComment $comment) {
|
|
|
|
$this->inlineComment = $comment;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOnRight($on_right) {
|
|
|
|
$this->onRight = $on_right;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBuildScaffolding($scaffold) {
|
|
|
|
$this->buildScaffolding = $scaffold;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
public function setHandles(array $handles) {
|
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
public function setMarkupEngine(PhutilMarkupEngine $engine) {
|
|
|
|
$this->markupEngine = $engine;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
public function setEditable($editable) {
|
|
|
|
$this->editable = $editable;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
public function render() {
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$inline = $this->inlineComment;
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$start = $inline->getLineNumber();
|
|
|
|
$length = $inline->getLineLength();
|
|
|
|
if ($length) {
|
|
|
|
$end = $start + $length;
|
|
|
|
$line = 'Lines '.number_format($start).'-'.number_format($end);
|
|
|
|
} else {
|
|
|
|
$line = 'Line '.number_format($start);
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$metadata = array(
|
2011-02-02 19:10:25 +01:00
|
|
|
'id' => $inline->getID(),
|
2011-02-02 01:42:36 +01:00
|
|
|
'number' => $inline->getLineNumber(),
|
|
|
|
'length' => $inline->getLineLength(),
|
2011-02-02 19:10:25 +01:00
|
|
|
'on_right' => $this->onRight,
|
2011-02-02 01:42:36 +01:00
|
|
|
);
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$sigil = 'differential-inline-comment';
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$content = $inline->getContent();
|
|
|
|
$handles = $this->handles;
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$links = array();
|
2011-04-15 03:08:10 +02:00
|
|
|
|
2011-05-11 21:25:29 +02:00
|
|
|
$links[] = javelin_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-prev',
|
|
|
|
),
|
|
|
|
'Previous');
|
|
|
|
|
|
|
|
$links[] = javelin_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-next',
|
|
|
|
),
|
|
|
|
'Next');
|
|
|
|
|
2011-04-15 03:08:10 +02:00
|
|
|
$links[] = javelin_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-reply',
|
|
|
|
'meta' => array(
|
|
|
|
'is_new' => true,
|
|
|
|
'changeset' => $inline->getChangesetID(),
|
|
|
|
'number' => $inline->getLineNumber(),
|
|
|
|
'length' => $inline->getLineLength(),
|
|
|
|
'on_right' => $this->onRight,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Reply');
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
if ($this->editable) {
|
|
|
|
$links[] = javelin_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-edit',
|
|
|
|
),
|
|
|
|
'Edit');
|
|
|
|
$links[] = javelin_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'sigil' => 'differential-inline-delete',
|
|
|
|
),
|
|
|
|
'Delete');
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
if ($links) {
|
2011-02-02 22:48:52 +01:00
|
|
|
$links =
|
2011-02-02 01:42:36 +01:00
|
|
|
'<span class="differential-inline-comment-links">'.
|
2011-02-02 19:10:25 +01:00
|
|
|
implode(' · ', $links).
|
2011-02-02 01:42:36 +01:00
|
|
|
'</span>';
|
2011-02-02 19:10:25 +01:00
|
|
|
} else {
|
|
|
|
$links = null;
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-03 04:38:43 +01:00
|
|
|
$cache = $inline->getCache();
|
|
|
|
if (strlen($cache)) {
|
|
|
|
$content = $cache;
|
|
|
|
} else {
|
|
|
|
$content = $this->markupEngine->markupText($content);
|
|
|
|
if ($inline->getID()) {
|
|
|
|
$inline->setCache($content);
|
|
|
|
$inline->save();
|
|
|
|
}
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-14 01:00:21 +01:00
|
|
|
$anchor = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'name' => 'inline-'.$inline->getID(),
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$markup = javelin_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'differential-inline-comment',
|
|
|
|
'sigil' => $sigil,
|
|
|
|
'meta' => $metadata,
|
|
|
|
),
|
|
|
|
'<div class="differential-inline-comment-head">'.
|
2011-02-14 01:00:21 +01:00
|
|
|
$anchor.
|
2011-02-02 01:42:36 +01:00
|
|
|
$links.
|
|
|
|
'<span class="differential-inline-comment-line">'.$line.'</span>'.
|
2011-02-02 19:10:25 +01:00
|
|
|
phutil_escape_html($handles[$inline->getAuthorPHID()]->getName()).
|
2011-02-02 01:42:36 +01:00
|
|
|
'</div>'.
|
2011-03-30 06:38:05 +02:00
|
|
|
'<div class="phabricator-remarkup">'.
|
|
|
|
$content.
|
|
|
|
'</div>');
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
return $this->scaffoldMarkup($markup);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function scaffoldMarkup($markup) {
|
|
|
|
if (!$this->buildScaffolding) {
|
|
|
|
return $markup;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-04-15 03:08:10 +02:00
|
|
|
$left_markup = !$this->onRight ? $markup : '';
|
|
|
|
$right_markup = $this->onRight ? $markup : '';
|
|
|
|
|
|
|
|
return
|
|
|
|
'<table>'.
|
|
|
|
'<tr class="inline">'.
|
|
|
|
'<th></th>'.
|
|
|
|
'<td>'.$left_markup.'</td>'.
|
|
|
|
'<th></th>'.
|
|
|
|
'<td>'.$right_markup.'</td>'.
|
|
|
|
'</tr>'.
|
|
|
|
'</table>';
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|