mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 11:21:01 +01:00
Implement PhabricatorMarkupInterface in Diffusion/Audit comments
Summary: Followup to D3804. Makes Diffusion main comments (not just inlines) render properly with the modern markup pipeline. Test Plan: Created previews and inline previews. Edited inlines. Saved comment, viewed comment. Verified caches were read and written using "Services" tab. Reviewers: btrahan, vrana Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3805
This commit is contained in:
parent
7ab82ed72e
commit
244b1302a0
6 changed files with 83 additions and 37 deletions
|
@ -61,7 +61,15 @@ final class PhabricatorAuditPreviewController
|
||||||
$phids = array_merge($phids, $ccs);
|
$phids = array_merge($phids, $ccs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$engine = new PhabricatorMarkupEngine();
|
||||||
|
$engine->setViewer($user);
|
||||||
|
$engine->addObject(
|
||||||
|
$comment,
|
||||||
|
PhabricatorAuditComment::MARKUP_FIELD_BODY);
|
||||||
|
$engine->process();
|
||||||
|
|
||||||
$view = id(new DiffusionCommentView())
|
$view = id(new DiffusionCommentView())
|
||||||
|
->setMarkupEngine($engine)
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->setComment($comment)
|
->setComment($comment)
|
||||||
->setIsPreview(true);
|
->setIsPreview(true);
|
||||||
|
|
|
@ -16,11 +16,14 @@
|
||||||
* limitations under the License.
|
* 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_AUDITORS = 'added-auditors';
|
||||||
const METADATA_ADDED_CCS = 'added-ccs';
|
const METADATA_ADDED_CCS = 'added-ccs';
|
||||||
|
|
||||||
|
const MARKUP_FIELD_BODY = 'markup:body';
|
||||||
|
|
||||||
protected $phid;
|
protected $phid;
|
||||||
protected $actorPHID;
|
protected $actorPHID;
|
||||||
protected $targetPHID;
|
protected $targetPHID;
|
||||||
|
@ -41,4 +44,28 @@ final class PhabricatorAuditComment extends PhabricatorAuditDAO {
|
||||||
return PhabricatorPHID::generateNewPHID('ACMT');
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,7 +498,25 @@ final class DiffusionCommitController extends DiffusionController {
|
||||||
$path_map = ipull($path_map, 'path', 'id');
|
$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 = new DiffusionCommentListView();
|
||||||
|
$view->setMarkupEngine($engine);
|
||||||
$view->setUser($user);
|
$view->setUser($user);
|
||||||
$view->setComments($comments);
|
$view->setComments($comments);
|
||||||
$view->setInlineComments($inlines);
|
$view->setInlineComments($inlines);
|
||||||
|
|
|
@ -23,6 +23,7 @@ final class DiffusionCommentListView extends AphrontView {
|
||||||
private $inlineComments = array();
|
private $inlineComments = array();
|
||||||
private $pathMap = array();
|
private $pathMap = array();
|
||||||
private $handles = array();
|
private $handles = array();
|
||||||
|
private $markupEngine;
|
||||||
|
|
||||||
public function setUser(PhabricatorUser $user) {
|
public function setUser(PhabricatorUser $user) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
@ -46,6 +47,15 @@ final class DiffusionCommentListView extends AphrontView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
|
||||||
|
$this->markupEngine = $markup_engine;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMarkupEngine() {
|
||||||
|
return $this->markupEngine;
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequiredHandlePHIDs() {
|
public function getRequiredHandlePHIDs() {
|
||||||
$phids = array();
|
$phids = array();
|
||||||
foreach ($this->comments as $comment) {
|
foreach ($this->comments as $comment) {
|
||||||
|
@ -87,6 +97,7 @@ final class DiffusionCommentListView extends AphrontView {
|
||||||
$inlines = idx($inline_comments, $comment->getID(), array());
|
$inlines = idx($inline_comments, $comment->getID(), array());
|
||||||
|
|
||||||
$view = id(new DiffusionCommentView())
|
$view = id(new DiffusionCommentView())
|
||||||
|
->setMarkupEngine($this->getMarkupEngine())
|
||||||
->setComment($comment)
|
->setComment($comment)
|
||||||
->setInlineComments($inlines)
|
->setInlineComments($inlines)
|
||||||
->setCommentNumber($num)
|
->setCommentNumber($num)
|
||||||
|
|
|
@ -26,8 +26,7 @@ final class DiffusionCommentView extends AphrontView {
|
||||||
private $pathMap;
|
private $pathMap;
|
||||||
|
|
||||||
private $inlineComments;
|
private $inlineComments;
|
||||||
|
private $markupEngine;
|
||||||
private $engine;
|
|
||||||
|
|
||||||
public function setUser(PhabricatorUser $user) {
|
public function setUser(PhabricatorUser $user) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
@ -66,6 +65,15 @@ final class DiffusionCommentView extends AphrontView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
|
||||||
|
$this->markupEngine = $markup_engine;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMarkupEngine() {
|
||||||
|
return $this->markupEngine;
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequiredHandlePHIDs() {
|
public function getRequiredHandlePHIDs() {
|
||||||
return array($this->comment->getActorPHID());
|
return array($this->comment->getActorPHID());
|
||||||
}
|
}
|
||||||
|
@ -146,14 +154,16 @@ final class DiffusionCommentView extends AphrontView {
|
||||||
|
|
||||||
private function renderContent() {
|
private function renderContent() {
|
||||||
$comment = $this->comment;
|
$comment = $this->comment;
|
||||||
$engine = $this->getEngine();
|
$engine = $this->getMarkupEngine();
|
||||||
|
|
||||||
if (!strlen($comment->getContent()) && empty($this->inlineComments)) {
|
if (!strlen($comment->getContent()) && empty($this->inlineComments)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
'<div class="phabricator-remarkup">'.
|
'<div class="phabricator-remarkup">'.
|
||||||
$engine->markupText($comment->getContent()).
|
$engine->getOutput(
|
||||||
|
$comment,
|
||||||
|
PhabricatorAuditComment::MARKUP_FIELD_BODY).
|
||||||
$this->renderSingleView($this->renderInlines()).
|
$this->renderSingleView($this->renderInlines()).
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
@ -164,6 +174,8 @@ final class DiffusionCommentView extends AphrontView {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$engine = $this->getMarkupEngine();
|
||||||
|
|
||||||
$inlines_by_path = mgroup($this->inlineComments, 'getPathID');
|
$inlines_by_path = mgroup($this->inlineComments, 'getPathID');
|
||||||
|
|
||||||
$view = new PhabricatorInlineSummaryView();
|
$view = new PhabricatorInlineSummaryView();
|
||||||
|
@ -179,9 +191,9 @@ final class DiffusionCommentView extends AphrontView {
|
||||||
'id' => $inline->getID(),
|
'id' => $inline->getID(),
|
||||||
'line' => $inline->getLineNumber(),
|
'line' => $inline->getLineNumber(),
|
||||||
'length' => $inline->getLineLength(),
|
'length' => $inline->getLineLength(),
|
||||||
'content' => PhabricatorInlineSummaryView::renderCommentContent(
|
'content' => $engine->getOutput(
|
||||||
$inline,
|
$inline,
|
||||||
$this->getEngine()),
|
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,13 +203,6 @@ final class DiffusionCommentView extends AphrontView {
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getEngine() {
|
|
||||||
if (!$this->engine) {
|
|
||||||
$this->engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
|
||||||
}
|
|
||||||
return $this->engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function renderHandleList(array $phids) {
|
private function renderHandleList(array $phids) {
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($phids as $phid) {
|
foreach ($phids as $phid) {
|
||||||
|
|
|
@ -29,29 +29,6 @@ final class PhabricatorInlineSummaryView extends AphrontView {
|
||||||
return $this;
|
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() {
|
public function render() {
|
||||||
require_celerity_resource('inline-comment-summary-css');
|
require_celerity_resource('inline-comment-summary-css');
|
||||||
return $this->renderHeader().$this->renderTable();
|
return $this->renderHeader().$this->renderTable();
|
||||||
|
|
Loading…
Reference in a new issue