@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 PhabricatorAppSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 public function getResultTypeDescription() {
7 return pht('Applications');
8 }
9
10 public function getApplicationClassName() {
11 return PhabricatorApplicationsApplication::class;
12 }
13
14 public function getPageSize(PhabricatorSavedQuery $saved) {
15 return INF;
16 }
17
18 public function buildSavedQueryFromRequest(AphrontRequest $request) {
19 $saved = new PhabricatorSavedQuery();
20
21 $saved->setParameter('name', $request->getStr('name'));
22
23 $saved->setParameter(
24 'installed',
25 $this->readBoolFromRequest($request, 'installed'));
26 $saved->setParameter(
27 'prototypes',
28 $this->readBoolFromRequest($request, 'prototypes'));
29 $saved->setParameter(
30 'firstParty',
31 $this->readBoolFromRequest($request, 'firstParty'));
32 $saved->setParameter(
33 'launchable',
34 $this->readBoolFromRequest($request, 'launchable'));
35 $saved->setParameter(
36 'appemails',
37 $this->readBoolFromRequest($request, 'appemails'));
38
39 return $saved;
40 }
41
42 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
43 $query = id(new PhabricatorApplicationQuery())
44 ->setOrder(PhabricatorApplicationQuery::ORDER_NAME)
45 ->withUnlisted(false);
46
47 $name = $saved->getParameter('name');
48 if (phutil_nonempty_string($name)) {
49 $query->withNameContains($name);
50 }
51
52 $installed = $saved->getParameter('installed');
53 if ($installed !== null) {
54 $query->withInstalled($installed);
55 }
56
57 $prototypes = $saved->getParameter('prototypes');
58
59 if ($prototypes === null) {
60 // NOTE: This is the old name of the 'prototypes' option, see T6084.
61 $prototypes = $saved->getParameter('beta');
62 $saved->setParameter('prototypes', $prototypes);
63 }
64
65 if ($prototypes !== null) {
66 $query->withPrototypes($prototypes);
67 }
68
69 $first_party = $saved->getParameter('firstParty');
70 if ($first_party !== null) {
71 $query->withFirstParty($first_party);
72 }
73
74 $launchable = $saved->getParameter('launchable');
75 if ($launchable !== null) {
76 $query->withLaunchable($launchable);
77 }
78
79 $appemails = $saved->getParameter('appemails');
80 if ($appemails !== null) {
81 $query->withApplicationEmailSupport($appemails);
82 }
83
84 return $query;
85 }
86
87 public function buildSearchForm(
88 AphrontFormView $form,
89 PhabricatorSavedQuery $saved) {
90
91 $form
92 ->appendChild(
93 id(new AphrontFormTextControl())
94 ->setLabel(pht('Name Contains'))
95 ->setName('name')
96 ->setValue($saved->getParameter('name')))
97 ->appendChild(
98 id(new AphrontFormSelectControl())
99 ->setLabel(pht('Enabled'))
100 ->setName('installed')
101 ->setValue($this->getBoolFromQuery($saved, 'installed'))
102 ->setOptions(
103 array(
104 '' => pht('Show All Applications'),
105 'true' => pht('Show Enabled Applications'),
106 'false' => pht('Show Disabled Applications'),
107 )))
108 ->appendChild(
109 id(new AphrontFormSelectControl())
110 ->setLabel(pht('Prototypes'))
111 ->setName('prototypes')
112 ->setValue($this->getBoolFromQuery($saved, 'prototypes'))
113 ->setOptions(
114 array(
115 '' => pht('Show All Applications'),
116 'true' => pht('Show Prototype Applications'),
117 'false' => pht('Show Released Applications'),
118 )))
119 ->appendChild(
120 id(new AphrontFormSelectControl())
121 ->setLabel(pht('Provenance'))
122 ->setName('firstParty')
123 ->setValue($this->getBoolFromQuery($saved, 'firstParty'))
124 ->setOptions(
125 array(
126 '' => pht('Show All Applications'),
127 'true' => pht('Show First-Party Applications'),
128 'false' => pht('Show Third-Party Applications'),
129 )))
130 ->appendChild(
131 id(new AphrontFormSelectControl())
132 ->setLabel(pht('Launchable'))
133 ->setName('launchable')
134 ->setValue($this->getBoolFromQuery($saved, 'launchable'))
135 ->setOptions(
136 array(
137 '' => pht('Show All Applications'),
138 'true' => pht('Show Launchable Applications'),
139 'false' => pht('Show Non-Launchable Applications'),
140 )))
141 ->appendChild(
142 id(new AphrontFormSelectControl())
143 ->setLabel(pht('Application Emails'))
144 ->setName('appemails')
145 ->setValue($this->getBoolFromQuery($saved, 'appemails'))
146 ->setOptions(
147 array(
148 '' => pht('Show All Applications'),
149 'true' => pht('Show Applications w/ App Email Support'),
150 'false' => pht('Show Applications w/o App Email Support'),
151 )));
152 }
153
154 protected function getURI($path) {
155 return '/applications/'.$path;
156 }
157
158 protected function getBuiltinQueryNames() {
159 return array(
160 'launcher' => pht('Launcher'),
161 'all' => pht('All Applications'),
162 );
163 }
164
165 public function buildSavedQueryFromBuiltin($query_key) {
166 $query = $this->newSavedQuery();
167 $query->setQueryKey($query_key);
168
169 switch ($query_key) {
170 case 'launcher':
171 return $query
172 ->setParameter('installed', true)
173 ->setParameter('launchable', true);
174 case 'all':
175 return $query;
176 }
177
178 return parent::buildSavedQueryFromBuiltin($query_key);
179 }
180
181 /**
182 * @param array<PhabricatorApplication> $all_applications
183 * @param PhabricatorSavedQuery $query
184 * @param array<PhabricatorObjectHandle> $handles
185 */
186 protected function renderResultList(
187 array $all_applications,
188 PhabricatorSavedQuery $query,
189 array $handles) {
190 assert_instances_of($all_applications, PhabricatorApplication::class);
191
192 $all_applications = msort($all_applications, 'getName');
193
194 if ($query->getQueryKey() == 'launcher') {
195 $groups = mgroup($all_applications, 'getApplicationGroup');
196 } else {
197 $groups = array($all_applications);
198 }
199
200 $group_names = PhabricatorApplication::getApplicationGroups();
201 $groups = array_select_keys($groups, array_keys($group_names)) + $groups;
202
203 $results = array();
204 foreach ($groups as $group => $applications) {
205 if (count($groups) > 1) {
206 $results[] = phutil_tag(
207 'h1',
208 array(
209 'class' => 'phui-oi-list-header',
210 ),
211 idx($group_names, $group, $group));
212 }
213
214 $list = new PHUIObjectItemListView();
215
216 foreach ($applications as $application) {
217 $icon = $application->getIcon();
218 if (!$icon) {
219 $icon = 'application';
220 }
221
222 $description = $application->getShortDescription();
223
224 $configure = id(new PHUIButtonView())
225 ->setTag('a')
226 ->setIcon('fa-gears')
227 ->setHref('/applications/view/'.get_class($application).'/')
228 ->setText(pht('Configure'))
229 ->setColor(PHUIButtonView::GREY);
230
231 $name = $application->getName();
232
233 $item = id(new PHUIObjectItemView())
234 ->setHeader($name)
235 ->setImageIcon($icon)
236 ->setSideColumn($configure);
237
238 if (!$application->isFirstParty()) {
239 $extension_tag = id(new PHUITagView())
240 ->setName(pht('Extension'))
241 ->setIcon('fa-plug')
242 ->setColor(PHUITagView::COLOR_INDIGO)
243 ->setType(PHUITagView::TYPE_SHADE)
244 ->setSlimShady(true);
245 $item->addAttribute($extension_tag);
246 }
247
248 if ($application->isPrototype()) {
249 $prototype_tag = id(new PHUITagView())
250 ->setName(pht('Prototype'))
251 ->setIcon('fa-exclamation-circle')
252 ->setColor(PHUITagView::COLOR_ORANGE)
253 ->setType(PHUITagView::TYPE_SHADE)
254 ->setSlimShady(true);
255 $item->addAttribute($prototype_tag);
256 }
257
258 if ($application->isDeprecated()) {
259 $deprecated_tag = id(new PHUITagView())
260 ->setName(pht('Deprecated'))
261 ->setIcon('fa-exclamation-triangle')
262 ->setColor(PHUITagView::COLOR_RED)
263 ->setType(PHUITagView::TYPE_SHADE)
264 ->setSlimShady(true);
265 $item->addAttribute($deprecated_tag);
266 }
267
268 $item->addAttribute($description);
269
270 if ($application->getBaseURI() && $application->isInstalled()) {
271 $item->setHref($application->getBaseURI());
272 }
273
274 if (!$application->isInstalled()) {
275 $item->addAttribute(pht('Disabled'));
276 $item->setDisabled(true);
277 }
278
279 $list->addItem($item);
280 }
281
282 $results[] = $list;
283 }
284
285 $result = new PhabricatorApplicationSearchResultView();
286 $result->setContent($results);
287
288 return $result;
289 }
290
291}