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
122 lines
3.4 KiB
PHP
122 lines
3.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright 2012 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 DiffusionDiffController extends DiffusionController {
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$data = $data + array(
|
|
'dblob' => $this->getRequest()->getStr('ref'),
|
|
);
|
|
$drequest = DiffusionRequest::newFromAphrontRequestDictionary($data);
|
|
|
|
$this->diffusionRequest = $drequest;
|
|
}
|
|
|
|
public function processRequest() {
|
|
$drequest = $this->getDiffusionRequest();
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
if (!$request->isAjax()) {
|
|
|
|
// This request came out of the dropdown menu, either "View Standalone"
|
|
// or "View Raw File".
|
|
|
|
$view = $request->getStr('view');
|
|
if ($view == 'r') {
|
|
$uri = $drequest->generateURI(
|
|
array(
|
|
'action' => 'browse',
|
|
'params' => array(
|
|
'view' => 'raw',
|
|
),
|
|
));
|
|
} else {
|
|
$uri = $drequest->generateURI(
|
|
array(
|
|
'action' => 'change',
|
|
));
|
|
}
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
|
}
|
|
|
|
|
|
$diff_query = DiffusionDiffQuery::newFromDiffusionRequest($drequest);
|
|
$changeset = $diff_query->loadChangeset();
|
|
|
|
if (!$changeset) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
|
|
$parser = new DifferentialChangesetParser();
|
|
$parser->setUser($user);
|
|
$parser->setChangeset($changeset);
|
|
$parser->setRenderingReference($diff_query->getRenderingReference());
|
|
|
|
$pquery = new DiffusionPathIDQuery(array($changeset->getFilename()));
|
|
$ids = $pquery->loadPathIDs();
|
|
$path_id = $ids[$changeset->getFilename()];
|
|
|
|
$parser->setLeftSideCommentMapping($path_id, false);
|
|
$parser->setRightSideCommentMapping($path_id, true);
|
|
|
|
$parser->setWhitespaceMode(
|
|
DifferentialChangesetParser::WHITESPACE_SHOW_ALL);
|
|
|
|
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
|
|
'commitPHID = %s AND pathID = %d AND
|
|
(authorPHID = %s OR auditCommentID IS NOT NULL)',
|
|
$drequest->loadCommit()->getPHID(),
|
|
$path_id,
|
|
$user->getPHID());
|
|
|
|
if ($inlines) {
|
|
foreach ($inlines as $inline) {
|
|
$parser->parseInlineComment($inline);
|
|
}
|
|
|
|
$phids = mpull($inlines, 'getAuthorPHID');
|
|
$handles = $this->loadViewerHandles($phids);
|
|
$parser->setHandles($handles);
|
|
}
|
|
|
|
$engine = new PhabricatorMarkupEngine();
|
|
$engine->setViewer($user);
|
|
|
|
foreach ($inlines as $inline) {
|
|
$engine->addObject(
|
|
$inline,
|
|
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
|
|
}
|
|
|
|
$engine->process();
|
|
|
|
$parser->setMarkupEngine($engine);
|
|
|
|
$spec = $request->getStr('range');
|
|
list($range_s, $range_e, $mask) =
|
|
DifferentialChangesetParser::parseRangeSpecification($spec);
|
|
$output = $parser->render($range_s, $range_e, $mask);
|
|
|
|
return id(new PhabricatorChangesetResponse())
|
|
->setRenderedChangeset($output);
|
|
}
|
|
}
|