Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / controller / DiffusionHistoryController.php
blobfb35d9b6ad7e435e216f83db2979c3f37f73d7b6
1 <?php
3 final class DiffusionHistoryController 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;
14 require_celerity_resource('diffusion-css');
16 $viewer = $this->getViewer();
17 $drequest = $this->getDiffusionRequest();
18 $repository = $drequest->getRepository();
20 $pager = id(new PHUIPagerView())
21 ->readFromRequest($request);
23 $params = array(
24 'commit' => $drequest->getCommit(),
25 'path' => $drequest->getPath(),
26 'offset' => $pager->getOffset(),
27 'limit' => $pager->getPageSize() + 1,
30 $history_results = $this->callConduitWithDiffusionRequest(
31 'diffusion.historyquery',
32 $params);
33 $history = DiffusionPathChange::newFromConduit(
34 $history_results['pathChanges']);
36 $history = $pager->sliceResults($history);
38 $history_list = id(new DiffusionCommitGraphView())
39 ->setViewer($viewer)
40 ->setDiffusionRequest($drequest)
41 ->setHistory($history);
43 // NOTE: If we have a path (like "src/"), many nodes in the graph are
44 // likely to be missing (since the path wasn't touched by those commits).
46 // If we draw the graph, commits will often appear to be unrelated because
47 // intermediate nodes are omitted. Just drop the graph.
49 // The ideal behavior would be to load the entire graph and then connect
50 // ancestors appropriately, but this would currrently be prohibitively
51 // expensive in the general case.
53 $show_graph = !strlen($drequest->getPath());
54 if ($show_graph) {
55 $history_list
56 ->setParents($history_results['parents'])
57 ->setIsHead(!$pager->getOffset())
58 ->setIsTail(!$pager->getHasMorePages());
61 $header = $this->buildHeader($drequest);
63 $crumbs = $this->buildCrumbs(
64 array(
65 'branch' => true,
66 'path' => true,
67 'view' => 'history',
68 ));
69 $crumbs->setBorder(true);
71 $title = array(
72 pht('History'),
73 $repository->getDisplayName(),
76 $pager = id(new PHUIBoxView())
77 ->addClass('mlb')
78 ->appendChild($pager);
80 $tabs = $this->buildTabsView('history');
82 $view = id(new PHUITwoColumnView())
83 ->setHeader($header)
84 ->setTabs($tabs)
85 ->setFooter(array(
86 $history_list,
87 $pager,
88 ));
90 return $this->newPage()
91 ->setTitle($title)
92 ->setCrumbs($crumbs)
93 ->appendChild($view)
94 ->addClass('diffusion-history-view');
97 private function buildHeader(DiffusionRequest $drequest) {
98 $viewer = $this->getViewer();
99 $repository = $drequest->getRepository();
101 $no_path = !strlen($drequest->getPath());
102 if ($no_path) {
103 $header_text = pht('History');
104 } else {
105 $header_text = $this->renderPathLinks($drequest, $mode = 'history');
108 $header = id(new PHUIHeaderView())
109 ->setUser($viewer)
110 ->setHeader($header_text)
111 ->setHeaderIcon('fa-clock-o');
113 if (!$repository->isSVN()) {
114 $branch_tag = $this->renderBranchTag($drequest);
115 $header->addTag($branch_tag);
118 if ($drequest->getSymbolicCommit()) {
119 $symbolic_tag = $this->renderSymbolicCommit($drequest);
120 $header->addTag($symbolic_tag);
123 return $header;