@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use modern two-stage markup cache (PhabricatorMarkupInterface) in Differential

Summary:
See T1963 for discussion of the Facebook-specific hack.

Differential currently uses a one-stage cache (render -> postprocess -> save in cache) rather than the two-stage cache (render -> save in cache -> postprocess) offered by `PhabricatorMarkupInteface`. This breaks Differential comments coming out of cache for the lightbox, and makes various other things suboptimal (status of handles like @mentions and embeds are not displayed accurately).

Instead, use the modern stuff.

Test Plan:
- Created preview comments and inlines in Differential.
- Edited a Differential inline.
- Submitted main and inline Differential comments.
- Viewed and edited Differential summary and test plan.
- Created preview comments and inlines in Diffusion.
- Submitted comments and inlines in Diffusion.
- Verified Differential now loads and saves to the generalized markup cache (Diffusion is close, but main comments still hold a single-stage cache).
- Verified old Differential comments work correctly with the lightbox.

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1963

Differential Revision: https://secure.phabricator.com/D3804

+178 -42
+24
src/applications/audit/storage/PhabricatorAuditInlineComment.php
··· 120 120 return $this->readField('authorPHID'); 121 121 } 122 122 123 + /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ 124 + 125 + 126 + public function getMarkupFieldKey($field) { 127 + return 'AI:'.$this->getID(); 128 + } 129 + 130 + public function newMarkupEngine($field) { 131 + return PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 132 + } 133 + 134 + public function getMarkupText($field) { 135 + return $this->getContent(); 136 + } 137 + 138 + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 139 + return $output; 140 + } 141 + 142 + public function shouldUseMarkupCache($field) { 143 + // Only cache submitted comments. 144 + return ($this->getID() && $this->getAuditCommentID()); 145 + } 146 + 123 147 }
+10 -1
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 206 206 $handles = $this->loadViewerHandles($phids); 207 207 $parser->setHandles($handles); 208 208 209 - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 209 + $engine = new PhabricatorMarkupEngine(); 210 + $engine->setViewer($request->getUser()); 211 + 212 + foreach ($inlines as $inline) { 213 + $engine->addObject( 214 + $inline, 215 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 216 + } 217 + 218 + $engine->process(); 210 219 $parser->setMarkupEngine($engine); 211 220 212 221 if ($request->isAjax()) {
+5 -1
src/applications/differential/controller/DifferentialCommentPreviewController.php
··· 33 33 34 34 $action = $request->getStr('action'); 35 35 36 - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 37 36 38 37 $comment = new DifferentialComment(); 39 38 $comment->setContent($request->getStr('content')); ··· 57 56 } 58 57 59 58 $handles = $this->loadViewerHandles($handles); 59 + 60 + $engine = new PhabricatorMarkupEngine(); 61 + $engine->setViewer($request->getUser()); 62 + $engine->addObject($comment, DifferentialComment::MARKUP_FIELD_BODY); 63 + $engine->process(); 60 64 61 65 $view = new DifferentialRevisionCommentView(); 62 66 $view->setUser($request->getUser());
+1 -1
src/applications/differential/parser/DifferentialChangesetParser.php
··· 250 250 return $this; 251 251 } 252 252 253 - public function setMarkupEngine(PhutilMarkupEngine $engine) { 253 + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { 254 254 $this->markupEngine = $engine; 255 255 return $this; 256 256 }
+53 -1
src/applications/differential/storage/DifferentialComment.php
··· 16 16 * limitations under the License. 17 17 */ 18 18 19 - final class DifferentialComment extends DifferentialDAO { 19 + final class DifferentialComment extends DifferentialDAO 20 + implements PhabricatorMarkupInterface { 20 21 21 22 const METADATA_ADDED_REVIEWERS = 'added-reviewers'; 22 23 const METADATA_REMOVED_REVIEWERS = 'removed-reviewers'; 23 24 const METADATA_ADDED_CCS = 'added-ccs'; 24 25 const METADATA_DIFF_ID = 'diff-id'; 25 26 27 + const MARKUP_FIELD_BODY = 'markup:body'; 28 + 26 29 protected $authorPHID; 27 30 protected $revisionID; 28 31 protected $action; ··· 31 34 protected $metadata = array(); 32 35 protected $contentSource; 33 36 37 + private $arbitraryDiffForFacebook; 38 + 39 + public function giveFacebookSomeArbitraryDiff(DifferentialDiff $diff) { 40 + $this->arbitraryDiffForFacebook = $diff; 41 + return $this; 42 + } 43 + 34 44 public function getConfiguration() { 35 45 return array( 36 46 self::CONFIG_SERIALIZATION => array( ··· 46 56 47 57 public function getContentSource() { 48 58 return PhabricatorContentSource::newFromSerialized($this->contentSource); 59 + } 60 + 61 + 62 + public function getMarkupFieldKey($field) { 63 + if ($this->getID()) { 64 + return 'DC:'.$this->getID(); 65 + } 66 + 67 + // The summary and test plan render as comments, but do not have IDs. 68 + // They are also mutable. Build keys using content hashes. 69 + $hash = PhabricatorHash::digest($this->getMarkupText($field)); 70 + return 'DC:'.$hash; 71 + } 72 + 73 + public function newMarkupEngine($field) { 74 + return PhabricatorMarkupEngine::newDifferentialMarkupEngine( 75 + array( 76 + 'differential.diff' => $this->arbitraryDiffForFacebook, 77 + )); 78 + } 79 + 80 + public function getMarkupText($field) { 81 + return $this->getContent(); 82 + } 83 + 84 + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 85 + return $output; 86 + } 87 + 88 + public function shouldUseMarkupCache($field) { 89 + if ($this->getID()) { 90 + return true; 91 + } 92 + 93 + $action = $this->getAction(); 94 + switch ($action) { 95 + case DifferentialAction::ACTION_SUMMARIZE: 96 + case DifferentialAction::ACTION_TESTPLAN: 97 + return true; 98 + } 99 + 100 + return false; 49 101 } 50 102 51 103 }
+25
src/applications/differential/storage/DifferentialInlineComment.php
··· 121 121 return $this->readField('authorPHID'); 122 122 } 123 123 124 + 125 + /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ 126 + 127 + 128 + public function getMarkupFieldKey($field) { 129 + return 'DI:'.$this->getID(); 130 + } 131 + 132 + public function newMarkupEngine($field) { 133 + return PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 134 + } 135 + 136 + public function getMarkupText($field) { 137 + return $this->getContent(); 138 + } 139 + 140 + public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 141 + return $output; 142 + } 143 + 144 + public function shouldUseMarkupCache($field) { 145 + // Only cache submitted comments. 146 + return ($this->getID() && $this->getCommentID()); 147 + } 148 + 124 149 }
+4 -14
src/applications/differential/view/DifferentialInlineCommentView.php
··· 48 48 return $this; 49 49 } 50 50 51 - public function setMarkupEngine(PhutilMarkupEngine $engine) { 51 + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { 52 52 $this->markupEngine = $engine; 53 53 return $this; 54 54 } ··· 199 199 $links = null; 200 200 } 201 201 202 - $cache = $inline->getCache(); 203 - if (strlen($cache)) { 204 - $content = $cache; 205 - } else { 206 - $content = $this->markupEngine->markupText($content); 207 - if ($inline->getID()) { 208 - $inline->setCache($content); 209 - 210 - $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 211 - $inline->save(); 212 - unset($unguarded); 213 - } 214 - } 202 + $content = $this->markupEngine->getOutput( 203 + $inline, 204 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 215 205 216 206 if ($this->preview) { 217 207 $anchor = null;
+17 -3
src/applications/differential/view/DifferentialRevisionCommentListView.php
··· 77 77 78 78 require_celerity_resource('differential-revision-comment-list-css'); 79 79 80 - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(array( 81 - 'differential.diff' => $this->target 82 - )); 80 + $engine = new PhabricatorMarkupEngine(); 81 + $engine->setViewer($this->user); 82 + foreach ($this->comments as $comment) { 83 + $comment->giveFacebookSomeArbitraryDiff($this->target); 84 + 85 + $engine->addObject( 86 + $comment, 87 + DifferentialComment::MARKUP_FIELD_BODY); 88 + } 89 + 90 + foreach ($this->inlines as $inline) { 91 + $engine->addObject( 92 + $inline, 93 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 94 + } 95 + 96 + $engine->process(); 83 97 84 98 $inlines = mgroup($this->inlines, 'getCommentID'); 85 99
+7 -16
src/applications/differential/view/DifferentialRevisionCommentView.php
··· 40 40 return $this; 41 41 } 42 42 43 - public function setMarkupEngine($markup_engine) { 43 + public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) { 44 44 $this->markupEngine = $markup_engine; 45 45 return $this; 46 46 } ··· 104 104 $hide_comments = true; 105 105 if (strlen(rtrim($content))) { 106 106 $hide_comments = false; 107 - $cache = $comment->getCache(); 108 - if (strlen($cache)) { 109 - $content = $cache; 110 - } else { 111 - $content = $this->markupEngine->markupText($content); 112 - if ($comment->getID()) { 113 - $comment->setCache($content); 114 107 115 - $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 116 - $comment->save(); 117 - unset($unguarded); 118 - } 119 - } 108 + $content = $this->markupEngine->getOutput( 109 + $comment, 110 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 111 + 120 112 $content = 121 113 '<div class="phabricator-remarkup">'. 122 114 $content. ··· 292 284 'id' => $inline->getID(), 293 285 'line' => $inline->getLineNumber(), 294 286 'length' => $inline->getLineLength(), 295 - 'content' => PhabricatorInlineSummaryView::renderCommentContent( 287 + 'content' => $this->markupEngine->getOutput( 296 288 $inline, 297 - $this->markupEngine), 289 + DifferentialInlineComment::MARKUP_FIELD_BODY), 298 290 ); 299 291 300 292 if (!$is_visible) { ··· 313 305 314 306 return $view; 315 307 } 316 - 317 308 318 309 }
+14 -2
src/applications/diffusion/controller/DiffusionDiffController.php
··· 64 64 return new Aphront404Response(); 65 65 } 66 66 67 + 67 68 $parser = new DifferentialChangesetParser(); 68 69 $parser->setUser($user); 69 70 $parser->setChangeset($changeset); 70 71 $parser->setRenderingReference($diff_query->getRenderingReference()); 71 - $parser->setMarkupEngine( 72 - PhabricatorMarkupEngine::newDiffusionMarkupEngine()); 73 72 74 73 $pquery = new DiffusionPathIDQuery(array($changeset->getFilename())); 75 74 $ids = $pquery->loadPathIDs(); ··· 97 96 $handles = $this->loadViewerHandles($phids); 98 97 $parser->setHandles($handles); 99 98 } 99 + 100 + $engine = new PhabricatorMarkupEngine(); 101 + $engine->setViewer($user); 102 + 103 + foreach ($inlines as $inline) { 104 + $engine->addObject( 105 + $inline, 106 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 107 + } 108 + 109 + $engine->process(); 110 + 111 + $parser->setMarkupEngine($engine); 100 112 101 113 $spec = $request->getStr('range'); 102 114 list($range_s, $range_e, $mask) =
+6 -1
src/infrastructure/diff/PhabricatorInlineCommentController.php
··· 222 222 $request = $this->getRequest(); 223 223 $user = $request->getUser(); 224 224 225 - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 225 + $engine = new PhabricatorMarkupEngine(); 226 + $engine->setViewer($user); 227 + $engine->addObject( 228 + $inline, 229 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 230 + $engine->process(); 226 231 227 232 $phids = array($user->getPHID()); 228 233
+9 -1
src/infrastructure/diff/PhabricatorInlineCommentPreviewController.php
··· 27 27 28 28 $inlines = $this->loadInlineComments(); 29 29 assert_instances_of($inlines, 'PhabricatorInlineCommentInterface'); 30 - $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 30 + 31 + $engine = new PhabricatorMarkupEngine(); 32 + $engine->setViewer($user); 33 + foreach ($inlines as $inline) { 34 + $engine->addObject( 35 + $inline, 36 + PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); 37 + } 38 + $engine->process(); 31 39 32 40 $phids = array($user->getPHID()); 33 41 $handles = $this->loadViewerHandles($phids);
+3 -1
src/infrastructure/diff/interface/PhabricatorInlineCommentInterface.php
··· 19 19 /** 20 20 * Shared interface used by Differential and Diffusion inline comments. 21 21 */ 22 - interface PhabricatorInlineCommentInterface { 22 + interface PhabricatorInlineCommentInterface extends PhabricatorMarkupInterface { 23 + 24 + const MARKUP_FIELD_BODY = 'markup:body'; 23 25 24 26 public function setChangesetID($id); 25 27 public function getChangesetID();