@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 PhrictionDocumentSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 public function getResultTypeDescription() {
7 return pht('Wiki Documents');
8 }
9
10 public function getApplicationClassName() {
11 return PhabricatorPhrictionApplication::class;
12 }
13
14 public function newQuery() {
15 return id(new PhrictionDocumentQuery())
16 ->needContent(true);
17 }
18
19 protected function buildQueryFromParameters(array $map) {
20 $query = $this->newQuery();
21
22 if ($map['statuses']) {
23 $query->withStatuses($map['statuses']);
24 }
25
26 if ($map['paths']) {
27 $query->withSlugs($map['paths']);
28 }
29
30 if ($map['parentPaths']) {
31 $query->withParentPaths($map['parentPaths']);
32 }
33
34 if ($map['ancestorPaths']) {
35 $query->withAncestorPaths($map['ancestorPaths']);
36 }
37
38 return $query;
39 }
40
41 protected function buildCustomSearchFields() {
42 return array(
43 id(new PhabricatorSearchCheckboxesField())
44 ->setKey('statuses')
45 ->setLabel(pht('Status'))
46 ->setDescription(pht('Search for objects with given statuses.'))
47 ->setOptions(PhrictionDocumentStatus::getStatusMap()),
48 id(new PhabricatorSearchStringListField())
49 ->setKey('paths')
50 ->setIsHidden(true)
51 ->setDescription(
52 pht('Find documents with specified paths (slugs).'))
53 ->setLabel(pht('Paths')),
54 id(new PhabricatorSearchStringListField())
55 ->setKey('parentPaths')
56 ->setIsHidden(true)
57 ->setDescription(
58 pht('Find documents beneath specified parent paths.'))
59 ->setLabel(pht('Parent Paths')),
60 id(new PhabricatorSearchStringListField())
61 ->setKey('ancestorPaths')
62 ->setIsHidden(true)
63 ->setDescription(
64 pht('Find documents beneath specified ancestor paths.'))
65 ->setLabel(pht('Ancestor Paths')),
66 );
67 }
68
69 protected function getURI($path) {
70 return '/phriction/'.$path;
71 }
72
73 protected function getBuiltinQueryNames() {
74 $names = array(
75 'active' => pht('Active'),
76 'all' => pht('All'),
77 );
78
79 return $names;
80 }
81
82 public function buildSavedQueryFromBuiltin($query_key) {
83
84 $query = $this->newSavedQuery();
85 $query->setQueryKey($query_key);
86
87 switch ($query_key) {
88 case 'all':
89 return $query;
90 case 'active':
91 return $query->setParameter(
92 'statuses',
93 array(
94 PhrictionDocumentStatus::STATUS_EXISTS,
95 ));
96 }
97
98 return parent::buildSavedQueryFromBuiltin($query_key);
99 }
100
101 protected function getRequiredHandlePHIDsForResultList(
102 array $documents,
103 PhabricatorSavedQuery $query) {
104
105 $phids = array();
106 foreach ($documents as $document) {
107 $content = $document->getContent();
108 $phids[] = $content->getAuthorPHID();
109 }
110
111 return $phids;
112 }
113
114 /**
115 * @param array<PhrictionDocument> $documents
116 * @param PhabricatorSavedQuery $query
117 * @param array<PhabricatorObjectHandle> $handles
118 */
119 protected function renderResultList(
120 array $documents,
121 PhabricatorSavedQuery $query,
122 array $handles) {
123 assert_instances_of($documents, PhrictionDocument::class);
124
125 $viewer = $this->requireViewer();
126
127 $list = new PHUIObjectItemListView();
128 $list->setViewer($viewer);
129 foreach ($documents as $document) {
130 $content = $document->getContent();
131 $slug = $document->getSlug();
132 $author_phid = $content->getAuthorPHID();
133 $slug_uri = PhrictionDocument::getSlugURI($slug);
134
135 $byline = pht(
136 'Edited by %s',
137 $handles[$author_phid]->renderLink());
138
139 $updated = phabricator_datetime(
140 $content->getDateCreated(),
141 $viewer);
142
143 $item = id(new PHUIObjectItemView())
144 ->setHeader($content->getTitle())
145 ->setObject($document)
146 ->setHref($slug_uri)
147 ->addByline($byline)
148 ->addIcon('none', $updated);
149
150 $item->addAttribute($slug_uri);
151
152 $icon = $document->getStatusIcon();
153 $color = $document->getStatusColor();
154 $label = $document->getStatusDisplayName();
155
156 $item->setStatusIcon("{$icon} {$color}", $label);
157
158 if (!$document->isActive()) {
159 $item->setDisabled(true);
160 }
161
162 $list->addItem($item);
163 }
164
165 $result = new PhabricatorApplicationSearchResultView();
166 $result->setObjectList($list);
167 $result->setNoDataString(pht('No documents found.'));
168
169 return $result;
170 }
171
172}