@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhrictionHistoryController
4 extends PhrictionController {
5
6 public function shouldAllowPublic() {
7 return true;
8 }
9
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $slug = $request->getURIData('slug');
13
14 $document = id(new PhrictionDocumentQuery())
15 ->setViewer($viewer)
16 ->withSlugs(array(PhabricatorSlug::normalize($slug)))
17 ->needContent(true)
18 ->executeOne();
19 if (!$document) {
20 return new Aphront404Response();
21 }
22
23 $current = $document->getContent();
24
25 $pager = id(new AphrontCursorPagerView())
26 ->readFromRequest($request);
27
28 $history = id(new PhrictionContentQuery())
29 ->setViewer($viewer)
30 ->withDocumentPHIDs(array($document->getPHID()))
31 ->executeWithCursorPager($pager);
32
33 $author_phids = mpull($history, 'getAuthorPHID');
34 $handles = $viewer->loadHandles($author_phids);
35
36 $max_version = (int)$document->getMaxVersion();
37 $current_version = $document->getContent()->getVersion();
38
39 $list = new PHUIObjectItemListView();
40 $list->setFlush(true);
41 foreach ($history as $content) {
42 $slug_uri = PhrictionDocument::getSlugURI($document->getSlug());
43 $version = $content->getVersion();
44
45 $base_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/');
46
47 $change_type = PhrictionChangeType::getChangeTypeLabel(
48 $content->getChangeType());
49 switch ($content->getChangeType()) {
50 case PhrictionChangeType::CHANGE_DELETE:
51 $color = 'red';
52 break;
53 case PhrictionChangeType::CHANGE_EDIT:
54 $color = 'lightbluetext';
55 break;
56 case PhrictionChangeType::CHANGE_MOVE_HERE:
57 $color = 'yellow';
58 break;
59 case PhrictionChangeType::CHANGE_MOVE_AWAY:
60 $color = 'orange';
61 break;
62 case PhrictionChangeType::CHANGE_STUB:
63 $color = 'green';
64 break;
65 default:
66 $color = 'indigo';
67 break;
68 }
69
70 $version_uri = $slug_uri.'?v='.$version;
71
72 $item = id(new PHUIObjectItemView())
73 ->setHref($version_uri);
74
75 if ($version > $current_version) {
76 $icon = 'fa-spinner';
77 $color = 'pink';
78 $header = pht('Draft %d', $version);
79 } else {
80 $icon = 'fa-file-o';
81 $header = pht('Version %d', $version);
82 }
83
84 if ($version == $current_version) {
85 $item->setEffect('selected');
86 }
87
88 $item
89 ->setHeader($header)
90 ->setStatusIcon($icon.' '.$color);
91
92 $description = $content->getDescription();
93 if (strlen($description)) {
94 $item->addAttribute($description);
95 }
96
97 $item->addIcon(
98 null,
99 phabricator_datetime($content->getDateCreated(), $viewer));
100
101 $author_phid = $content->getAuthorPHID();
102 $item->addByline($viewer->renderHandle($author_phid));
103
104 $diff_uri = null;
105 if ($version > 1) {
106 $diff_uri = $base_uri
107 ->alter('l', $version - 1)
108 ->alter('r', $version);
109 } else {
110 $diff_uri = null;
111 }
112
113 if ($content->getVersion() != $max_version) {
114 $compare_uri = $base_uri
115 ->alter('l', $version)
116 ->alter('r', $max_version);
117 } else {
118 $compare_uri = null;
119 }
120
121 $button_bar = id(new PHUIButtonBarView())
122 ->addButton(
123 id(new PHUIButtonView())
124 ->setTag('a')
125 ->setColor('grey')
126 ->setIcon('fa-chevron-down')
127 ->setDisabled(!$diff_uri)
128 ->setHref($diff_uri)
129 ->setText(pht('Diff')))
130 ->addButton(
131 id(new PHUIButtonView())
132 ->setTag('a')
133 ->setColor('grey')
134 ->setIcon('fa-chevron-circle-up')
135 ->setDisabled(!$compare_uri)
136 ->setHref($compare_uri)
137 ->setText(pht('Compare')));
138
139 $item->setSideColumn($button_bar);
140
141 $list->addItem($item);
142 }
143
144 $crumbs = $this->buildApplicationCrumbs();
145 $crumb_views = $this->renderBreadcrumbs($document->getSlug());
146 foreach ($crumb_views as $view) {
147 $crumbs->addCrumb($view);
148 }
149 $crumbs->addTextCrumb(
150 pht('History'),
151 PhrictionDocument::getSlugURI($document->getSlug(), 'history'));
152 $crumbs->setBorder(true);
153
154 $header = new PHUIHeaderView();
155 $header->setHeader(phutil_tag(
156 'a',
157 array('href' => PhrictionDocument::getSlugURI($document->getSlug())),
158 head($history)->getTitle()));
159 $header->setSubheader(pht('Document History'));
160
161 $obj_box = id(new PHUIObjectBoxView())
162 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
163 ->setObjectList($list);
164
165 $pager = id(new PHUIBoxView())
166 ->addClass('ml')
167 ->appendChild($pager);
168
169 $header = id(new PHUIHeaderView())
170 ->setHeader(pht('Document History: %s', head($history)->getTitle()))
171 ->setHeaderIcon('fa-history');
172
173 $view = id(new PHUITwoColumnView())
174 ->setHeader($header)
175 ->setFooter(array(
176 $obj_box,
177 $pager,
178 ));
179
180 $title = pht('Document History');
181
182 return $this->newPage()
183 ->setTitle($title)
184 ->setCrumbs($crumbs)
185 ->appendChild($view);
186
187 }
188
189}