@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
3abstract class DiffusionView extends AphrontView {
4
5 private $diffusionRequest;
6
7 final public function setDiffusionRequest(DiffusionRequest $request) {
8 $this->diffusionRequest = $request;
9 return $this;
10 }
11
12 final public function getDiffusionRequest() {
13 return $this->diffusionRequest;
14 }
15
16 final public function linkHistory($path) {
17 $href = $this->getDiffusionRequest()->generateURI(
18 array(
19 'action' => 'history',
20 'path' => $path,
21 ));
22
23 return $this->renderHistoryLink($href);
24 }
25
26 final public function linkBranchHistory($branch) {
27 $href = $this->getDiffusionRequest()->generateURI(
28 array(
29 'action' => 'history',
30 'branch' => $branch,
31 ));
32
33 return $this->renderHistoryLink($href);
34 }
35
36 final public function linkTagHistory($tag) {
37 $href = $this->getDiffusionRequest()->generateURI(
38 array(
39 'action' => 'history',
40 'commit' => $tag,
41 ));
42
43 return $this->renderHistoryLink($href);
44 }
45
46 private function renderHistoryLink($href) {
47 return javelin_tag(
48 'a',
49 array(
50 'href' => $href,
51 'class' => 'diffusion-link-icon',
52 'sigil' => 'has-tooltip',
53 'meta' => array(
54 'tip' => pht('History'),
55 'align' => 'E',
56 ),
57 ),
58 id(new PHUIIconView())->setIcon('fa-history bluegrey'));
59 }
60
61 final public function linkBrowse(
62 $path,
63 array $details = array(),
64 $button = false) {
65 require_celerity_resource('diffusion-icons-css');
66 Javelin::initBehavior('phabricator-tooltips');
67
68 $file_type = idx($details, 'type');
69 unset($details['type']);
70
71 $display_name = idx($details, 'name');
72 unset($details['name']);
73
74 if (phutil_nonempty_string($display_name)) {
75 $display_name = phutil_tag(
76 'span',
77 array(
78 'class' => 'diffusion-browse-name',
79 ),
80 $display_name);
81 }
82
83 if (isset($details['external'])) {
84 $params = array(
85 'uri' => idx($details, 'external'),
86 'id' => idx($details, 'hash'),
87 );
88
89 $href = new PhutilURI('/diffusion/external/', $params);
90 $tip = pht('Browse External');
91 } else {
92 $href = $this->getDiffusionRequest()->generateURI(
93 $details + array(
94 'action' => 'browse',
95 'path' => $path,
96 ));
97 $tip = pht('Browse');
98 }
99
100 $icon = DifferentialChangeType::getIconForFileType($file_type);
101 $color = DifferentialChangeType::getIconColorForFileType($file_type);
102 $icon_view = id(new PHUIIconView())
103 ->setIcon($icon.' '.$color);
104
105 // If we're rendering a file or directory name, don't show the tooltip.
106 if ($display_name !== null) {
107 $sigil = null;
108 $meta = null;
109 } else {
110 $sigil = 'has-tooltip';
111 $meta = array(
112 'tip' => $tip,
113 'align' => 'E',
114 );
115 }
116
117 if ($button) {
118 return id(new PHUIButtonView())
119 ->setTag('a')
120 ->setIcon('fa-code')
121 ->setHref($href)
122 ->setToolTip(pht('Browse'))
123 ->setButtonType(PHUIButtonView::BUTTONTYPE_SIMPLE);
124 }
125
126 return javelin_tag(
127 'a',
128 array(
129 'href' => $href,
130 'class' => 'diffusion-link-icon',
131 'sigil' => $sigil,
132 'meta' => $meta,
133 ),
134 array(
135 $icon_view,
136 $display_name,
137 ));
138 }
139
140 final public static function linkCommit(
141 PhabricatorRepository $repository,
142 $commit,
143 $summary = '') {
144
145 $commit_name = $repository->formatCommitName($commit, $local = true);
146
147 if (strlen($summary)) {
148 $commit_name .= ': '.$summary;
149 }
150
151 return phutil_tag(
152 'a',
153 array(
154 'href' => $repository->getCommitURI($commit),
155 ),
156 $commit_name);
157 }
158
159 final public static function linkDetail(
160 PhabricatorRepository $repository,
161 $commit,
162 $detail) {
163
164 return phutil_tag(
165 'a',
166 array(
167 'href' => $repository->getCommitURI($commit),
168 ),
169 $detail);
170 }
171
172 final public static function renderName($name) {
173 $email = new PhutilEmailAddress($name);
174 if ($email->getDisplayName() && $email->getDomainName()) {
175 Javelin::initBehavior('phabricator-tooltips', array());
176 require_celerity_resource('aphront-tooltip-css');
177 return javelin_tag(
178 'span',
179 array(
180 'sigil' => 'has-tooltip',
181 'meta' => array(
182 'tip' => $email->getAddress(),
183 'align' => 'S',
184 'size' => 'auto',
185 ),
186 ),
187 $email->getDisplayName());
188 }
189 return hsprintf('%s', $name);
190 }
191
192 final protected function renderBuildable(
193 HarbormasterBuildable $buildable,
194 $type = null) {
195 Javelin::initBehavior('phabricator-tooltips');
196
197 $icon = $buildable->getStatusIcon();
198 $color = $buildable->getStatusColor();
199 $name = $buildable->getStatusDisplayName();
200
201 if ($type == 'button') {
202 return id(new PHUIButtonView())
203 ->setTag('a')
204 ->setText($name)
205 ->setIcon($icon)
206 ->setColor($color)
207 ->setHref('/'.$buildable->getMonogram())
208 ->addClass('mmr')
209 ->setButtonType(PHUIButtonView::BUTTONTYPE_SIMPLE)
210 ->addClass('diffusion-list-build-status');
211 }
212
213 return id(new PHUIIconView())
214 ->setIcon($icon.' '.$color)
215 ->addSigil('has-tooltip')
216 ->setHref('/'.$buildable->getMonogram())
217 ->setMetadata(
218 array(
219 'tip' => $name,
220 ));
221
222 }
223
224 /**
225 * @param array<PhabricatorRepositoryCommit> $commits
226 */
227 final protected function loadBuildables(array $commits) {
228 assert_instances_of($commits, PhabricatorRepositoryCommit::class);
229
230 if (!$commits) {
231 return array();
232 }
233
234 $viewer = $this->getUser();
235
236 $harbormaster_app = PhabricatorHarbormasterApplication::class;
237 $have_harbormaster = PhabricatorApplication::isClassInstalledForViewer(
238 $harbormaster_app,
239 $viewer);
240
241 if ($have_harbormaster) {
242 $buildables = id(new HarbormasterBuildableQuery())
243 ->setViewer($viewer)
244 ->withBuildablePHIDs(mpull($commits, 'getPHID'))
245 ->withManualBuildables(false)
246 ->execute();
247 $buildables = mpull($buildables, null, 'getBuildablePHID');
248 } else {
249 $buildables = array();
250 }
251
252 return $buildables;
253 }
254
255}