mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +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);
|
||||
}
|
||||
|
||||
$engine = new PhabricatorMarkupEngine();
|
||||
$engine->setViewer($user);
|
||||
$engine->addObject(
|
||||
$comment,
|
||||
PhabricatorAuditComment::MARKUP_FIELD_BODY);
|
||||
$engine->process();
|
||||
|
||||
$view = id(new DiffusionCommentView())
|
||||
->setMarkupEngine($engine)
|
||||
->setUser($user)
|
||||
->setComment($comment)
|
||||
->setIsPreview(true);
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
* 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_CCS = 'added-ccs';
|
||||
|
||||
const MARKUP_FIELD_BODY = 'markup:body';
|
||||
|
||||
protected $phid;
|
||||
protected $actorPHID;
|
||||
protected $targetPHID;
|
||||
|
@ -41,4 +44,28 @@ final class PhabricatorAuditComment extends PhabricatorAuditDAO {
|
|||
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');
|
||||
}
|
||||
|
||||
$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->setMarkupEngine($engine);
|
||||
$view->setUser($user);
|
||||
$view->setComments($comments);
|
||||
$view->setInlineComments($inlines);
|
||||
|
|
|
@ -23,6 +23,7 @@ final class DiffusionCommentListView extends AphrontView {
|
|||
private $inlineComments = array();
|
||||
private $pathMap = array();
|
||||
private $handles = array();
|
||||
private $markupEngine;
|
||||
|
||||
public function setUser(PhabricatorUser $user) {
|
||||
$this->user = $user;
|
||||
|
@ -46,6 +47,15 @@ final class DiffusionCommentListView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
|
||||
$this->markupEngine = $markup_engine;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMarkupEngine() {
|
||||
return $this->markupEngine;
|
||||
}
|
||||
|
||||
public function getRequiredHandlePHIDs() {
|
||||
$phids = array();
|
||||
foreach ($this->comments as $comment) {
|
||||
|
@ -87,6 +97,7 @@ final class DiffusionCommentListView extends AphrontView {
|
|||
$inlines = idx($inline_comments, $comment->getID(), array());
|
||||
|
||||
$view = id(new DiffusionCommentView())
|
||||
->setMarkupEngine($this->getMarkupEngine())
|
||||
->setComment($comment)
|
||||
->setInlineComments($inlines)
|
||||
->setCommentNumber($num)
|
||||
|
|
|
@ -26,8 +26,7 @@ final class DiffusionCommentView extends AphrontView {
|
|||
private $pathMap;
|
||||
|
||||
private $inlineComments;
|
||||
|
||||
private $engine;
|
||||
private $markupEngine;
|
||||
|
||||
public function setUser(PhabricatorUser $user) {
|
||||
$this->user = $user;
|
||||
|
@ -66,6 +65,15 @@ final class DiffusionCommentView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {
|
||||
$this->markupEngine = $markup_engine;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMarkupEngine() {
|
||||
return $this->markupEngine;
|
||||
}
|
||||
|
||||
public function getRequiredHandlePHIDs() {
|
||||
return array($this->comment->getActorPHID());
|
||||
}
|
||||
|
@ -146,14 +154,16 @@ final class DiffusionCommentView extends AphrontView {
|
|||
|
||||
private function renderContent() {
|
||||
$comment = $this->comment;
|
||||
$engine = $this->getEngine();
|
||||
$engine = $this->getMarkupEngine();
|
||||
|
||||
if (!strlen($comment->getContent()) && empty($this->inlineComments)) {
|
||||
return null;
|
||||
} else {
|
||||
return
|
||||
'<div class="phabricator-remarkup">'.
|
||||
$engine->markupText($comment->getContent()).
|
||||
$engine->getOutput(
|
||||
$comment,
|
||||
PhabricatorAuditComment::MARKUP_FIELD_BODY).
|
||||
$this->renderSingleView($this->renderInlines()).
|
||||
'</div>';
|
||||
}
|
||||
|
@ -164,6 +174,8 @@ final class DiffusionCommentView extends AphrontView {
|
|||
return null;
|
||||
}
|
||||
|
||||
$engine = $this->getMarkupEngine();
|
||||
|
||||
$inlines_by_path = mgroup($this->inlineComments, 'getPathID');
|
||||
|
||||
$view = new PhabricatorInlineSummaryView();
|
||||
|
@ -179,9 +191,9 @@ final class DiffusionCommentView extends AphrontView {
|
|||
'id' => $inline->getID(),
|
||||
'line' => $inline->getLineNumber(),
|
||||
'length' => $inline->getLineLength(),
|
||||
'content' => PhabricatorInlineSummaryView::renderCommentContent(
|
||||
'content' => $engine->getOutput(
|
||||
$inline,
|
||||
$this->getEngine()),
|
||||
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -191,13 +203,6 @@ final class DiffusionCommentView extends AphrontView {
|
|||
return $view;
|
||||
}
|
||||
|
||||
private function getEngine() {
|
||||
if (!$this->engine) {
|
||||
$this->engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
||||
}
|
||||
return $this->engine;
|
||||
}
|
||||
|
||||
private function renderHandleList(array $phids) {
|
||||
$result = array();
|
||||
foreach ($phids as $phid) {
|
||||
|
|
|
@ -29,29 +29,6 @@ final class PhabricatorInlineSummaryView extends AphrontView {
|
|||
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() {
|
||||
require_celerity_resource('inline-comment-summary-css');
|
||||
return $this->renderHeader().$this->renderTable();
|
||||
|
|
Loading…
Reference in a new issue