Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / controller / DiffusionDiffController.php
blob69a473dc9132da32ca99ccc410c30280cecb7982
1 <?php
3 final class DiffusionDiffController extends DiffusionController {
5 public function shouldAllowPublic() {
6 return true;
9 protected function getDiffusionBlobFromRequest(AphrontRequest $request) {
10 return $request->getStr('ref');
13 public function handleRequest(AphrontRequest $request) {
14 $response = $this->loadDiffusionContext();
15 if ($response) {
16 return $response;
19 $viewer = $this->getViewer();
20 $drequest = $this->getDiffusionRequest();
22 if (!$request->isAjax()) {
24 // This request came out of the dropdown menu, either "View Standalone"
25 // or "View Raw File".
27 $view = $request->getStr('view');
28 if ($view == 'r') {
29 $uri = $drequest->generateURI(
30 array(
31 'action' => 'browse',
32 'params' => array(
33 'view' => 'raw',
35 ));
36 } else {
37 $uri = $drequest->generateURI(
38 array(
39 'action' => 'change',
40 ));
43 return id(new AphrontRedirectResponse())->setURI($uri);
46 $data = $this->callConduitWithDiffusionRequest(
47 'diffusion.diffquery',
48 array(
49 'commit' => $drequest->getCommit(),
50 'path' => $drequest->getPath(),
51 ));
52 $drequest->updateSymbolicCommit($data['effectiveCommit']);
53 $raw_changes = ArcanistDiffChange::newFromConduit($data['changes']);
54 $diff = DifferentialDiff::newEphemeralFromRawChanges(
55 $raw_changes);
56 $changesets = $diff->getChangesets();
57 $changeset = reset($changesets);
59 if (!$changeset) {
60 return new Aphront404Response();
63 $commit = $drequest->loadCommit();
65 $viewstate_engine = id(new PhabricatorChangesetViewStateEngine())
66 ->setViewer($viewer)
67 ->setObjectPHID($commit->getPHID())
68 ->setChangeset($changeset);
70 $viewstate = $viewstate_engine->newViewStateFromRequest($request);
72 if ($viewstate->getDiscardResponse()) {
73 return new AphrontAjaxResponse();
76 $parser = id(new DifferentialChangesetParser())
77 ->setViewer($viewer)
78 ->setChangeset($changeset)
79 ->setViewState($viewstate);
81 $parser->setRenderingReference($drequest->generateURI(
82 array(
83 'action' => 'rendering-ref',
84 )));
86 $coverage = $drequest->loadCoverage();
87 if ($coverage) {
88 $parser->setCoverage($coverage);
91 $pquery = new DiffusionPathIDQuery(array($changeset->getFilename()));
92 $ids = $pquery->loadPathIDs();
93 $path_id = $ids[$changeset->getFilename()];
95 $parser->setLeftSideCommentMapping($path_id, false);
96 $parser->setRightSideCommentMapping($path_id, true);
97 $parser->setCanMarkDone(
98 ($commit->getAuthorPHID()) &&
99 ($viewer->getPHID() == $commit->getAuthorPHID()));
100 $parser->setObjectOwnerPHID($commit->getAuthorPHID());
102 $inlines = id(new DiffusionDiffInlineCommentQuery())
103 ->setViewer($viewer)
104 ->withCommitPHIDs(array($commit->getPHID()))
105 ->withPathIDs(array($path_id))
106 ->withPublishedComments(true)
107 ->withPublishableComments(true)
108 ->execute();
109 $inlines = mpull($inlines, 'newInlineCommentObject');
111 if ($inlines) {
112 foreach ($inlines as $inline) {
113 $parser->parseInlineComment($inline);
116 $phids = mpull($inlines, 'getAuthorPHID');
117 $handles = $this->loadViewerHandles($phids);
118 $parser->setHandles($handles);
121 $engine = new PhabricatorMarkupEngine();
122 $engine->setViewer($viewer);
124 foreach ($inlines as $inline) {
125 $engine->addObject(
126 $inline,
127 PhabricatorInlineComment::MARKUP_FIELD_BODY);
130 $engine->process();
132 $parser->setMarkupEngine($engine);
134 $spec = $request->getStr('range');
135 list($range_s, $range_e, $mask) =
136 DifferentialChangesetParser::parseRangeSpecification($spec);
138 $parser->setRange($range_s, $range_e);
139 $parser->setMask($mask);
141 return $parser->newChangesetResponse();