Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / controller / DiffusionChangeController.php
blob0120c978d0f0faab8e003f84e744572915ee70b6
1 <?php
3 final class DiffusionChangeController extends DiffusionController {
5 public function shouldAllowPublic() {
6 return true;
9 public function handleRequest(AphrontRequest $request) {
10 $response = $this->loadDiffusionContext();
11 if ($response) {
12 return $response;
15 $viewer = $this->getViewer();
16 $drequest = $this->getDiffusionRequest();
18 $data = $this->callConduitWithDiffusionRequest(
19 'diffusion.diffquery',
20 array(
21 'commit' => $drequest->getCommit(),
22 'path' => $drequest->getPath(),
23 ));
25 $drequest->updateSymbolicCommit($data['effectiveCommit']);
27 $raw_changes = ArcanistDiffChange::newFromConduit($data['changes']);
28 $diff = DifferentialDiff::newEphemeralFromRawChanges(
29 $raw_changes);
30 $changesets = $diff->getChangesets();
31 $changeset = reset($changesets);
33 if (!$changeset) {
34 // TODO: Refine this.
35 return new Aphront404Response();
38 $repository = $drequest->getRepository();
39 $changesets = array(
40 0 => $changeset,
43 $changeset_header = $this->buildChangesetHeader($drequest);
45 $changeset_view = new DifferentialChangesetListView();
46 $changeset_view->setChangesets($changesets);
47 $changeset_view->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
48 $changeset_view->setVisibleChangesets($changesets);
49 $changeset_view->setRenderingReferences(
50 array(
51 0 => $drequest->generateURI(array('action' => 'rendering-ref')),
52 ));
54 $raw_params = array(
55 'action' => 'browse',
56 'params' => array(
57 'view' => 'raw',
61 $right_uri = $drequest->generateURI($raw_params);
62 $raw_params['params']['before'] = $drequest->getStableCommit();
63 $left_uri = $drequest->generateURI($raw_params);
64 $changeset_view->setRawFileURIs($left_uri, $right_uri);
66 $changeset_view->setRenderURI($repository->getPathURI('diff/'));
67 $changeset_view->setUser($viewer);
68 $changeset_view->setHeader($changeset_header);
70 // TODO: This is pretty awkward, unify the CSS between Diffusion and
71 // Differential better.
72 require_celerity_resource('differential-core-view-css');
74 $crumbs = $this->buildCrumbs(
75 array(
76 'branch' => true,
77 'path' => true,
78 'view' => 'change',
79 ));
80 $crumbs->setBorder(true);
82 $links = $this->renderPathLinks($drequest, $mode = 'browse');
83 $header = $this->buildHeader($drequest, $links);
85 $view = id(new PHUITwoColumnView())
86 ->setHeader($header)
87 ->setMainColumn(array(
89 ->setFooter(array(
90 $changeset_view,
91 ));
93 return $this->newPage()
94 ->setTitle(
95 array(
96 basename($drequest->getPath()),
97 $repository->getDisplayName(),
99 ->setCrumbs($crumbs)
100 ->appendChild(
101 array(
102 $view,
106 private function buildHeader(
107 DiffusionRequest $drequest,
108 $links) {
109 $viewer = $this->getViewer();
111 $tag = $this->renderCommitHashTag($drequest);
113 $header = id(new PHUIHeaderView())
114 ->setHeader($links)
115 ->setUser($viewer)
116 ->setPolicyObject($drequest->getRepository())
117 ->addTag($tag);
119 return $header;
122 private function buildChangesetHeader(DiffusionRequest $drequest) {
123 $viewer = $this->getViewer();
125 $header = id(new PHUIHeaderView())
126 ->setHeader(pht('Changes'));
128 $history_uri = $drequest->generateURI(
129 array(
130 'action' => 'history',
133 $header->addActionLink(
134 id(new PHUIButtonView())
135 ->setTag('a')
136 ->setText(pht('View History'))
137 ->setHref($history_uri)
138 ->setIcon('fa-clock-o'));
140 $browse_uri = $drequest->generateURI(
141 array(
142 'action' => 'browse',
145 $header->addActionLink(
146 id(new PHUIButtonView())
147 ->setTag('a')
148 ->setText(pht('Browse Content'))
149 ->setHref($browse_uri)
150 ->setIcon('fa-files-o'));
152 return $header;
155 protected function buildPropertyView(
156 DiffusionRequest $drequest,
157 PhabricatorActionListView $actions) {
159 $viewer = $this->getRequest()->getUser();
161 $view = id(new PHUIPropertyListView())
162 ->setUser($viewer)
163 ->setActionList($actions);
165 $stable_commit = $drequest->getStableCommit();
167 $view->addProperty(
168 pht('Commit'),
169 phutil_tag(
170 'a',
171 array(
172 'href' => $drequest->generateURI(
173 array(
174 'action' => 'commit',
175 'commit' => $stable_commit,
178 $drequest->getRepository()->formatCommitName($stable_commit)));
180 return $view;