Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / controller / DiffusionHistoryController.php
blob82eb8f63a37e911c73d957fd631b2cdb3bff6fa8
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 = ($drequest->getPath() === null
54 || !strlen($drequest->getPath()));
55 if ($show_graph) {
56 $history_list
57 ->setParents($history_results['parents'])
58 ->setIsHead(!$pager->getOffset())
59 ->setIsTail(!$pager->getHasMorePages());
62 $header = $this->buildHeader($drequest);
64 $crumbs = $this->buildCrumbs(
65 array(
66 'branch' => true,
67 'path' => true,
68 'view' => 'history',
69 ));
70 $crumbs->setBorder(true);
72 $title = array(
73 pht('History'),
74 $repository->getDisplayName(),
77 $pager = id(new PHUIBoxView())
78 ->addClass('mlb')
79 ->appendChild($pager);
81 $tabs = $this->buildTabsView('history');
83 $view = id(new PHUITwoColumnView())
84 ->setHeader($header)
85 ->setTabs($tabs)
86 ->setFooter(array(
87 $history_list,
88 $pager,
89 ));
91 return $this->newPage()
92 ->setTitle($title)
93 ->setCrumbs($crumbs)
94 ->appendChild($view)
95 ->addClass('diffusion-history-view');
98 private function buildHeader(DiffusionRequest $drequest) {
99 $viewer = $this->getViewer();
100 $repository = $drequest->getRepository();
102 $no_path = $drequest->getPath() === null || !strlen($drequest->getPath());
103 if ($no_path) {
104 $header_text = pht('History');
105 } else {
106 $header_text = $this->renderPathLinks($drequest, $mode = 'history');
109 $header = id(new PHUIHeaderView())
110 ->setUser($viewer)
111 ->setHeader($header_text)
112 ->setHeaderIcon('fa-clock-o');
114 if (!$repository->isSVN()) {
115 $branch_tag = $this->renderBranchTag($drequest);
116 $header->addTag($branch_tag);
119 if ($drequest->getSymbolicCommit()) {
120 $symbolic_tag = $this->renderSymbolicCommit($drequest);
121 $header->addTag($symbolic_tag);
124 return $header;