@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 DifferentialChangesetSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 private $diff;
7
8 public function setDiff(DifferentialDiff $diff) {
9 $this->diff = $diff;
10 return $this;
11 }
12
13 public function getDiff() {
14 return $this->diff;
15 }
16
17 public function getResultTypeDescription() {
18 return pht('Differential Changesets');
19 }
20
21 public function getApplicationClassName() {
22 return PhabricatorDifferentialApplication::class;
23 }
24
25 public function canUseInPanelContext() {
26 return false;
27 }
28
29 public function newQuery() {
30 $query = new DifferentialChangesetQuery();
31
32 if ($this->diff) {
33 $query->withDiffs(array($this->diff));
34 }
35
36 return $query;
37 }
38
39 protected function buildQueryFromParameters(array $map) {
40 $query = $this->newQuery();
41
42 if ($map['diffPHIDs']) {
43 $query->withDiffPHIDs($map['diffPHIDs']);
44 }
45
46 return $query;
47 }
48
49 protected function buildCustomSearchFields() {
50 return array(
51 id(new PhabricatorPHIDsSearchField())
52 ->setLabel(pht('Diffs'))
53 ->setKey('diffPHIDs')
54 ->setAliases(array('diff', 'diffs', 'diffPHID'))
55 ->setDescription(
56 pht('Find changesets attached to a particular diff.')),
57 );
58 }
59
60 protected function getURI($path) {
61 $diff = $this->getDiff();
62 if ($diff) {
63 return '/differential/diff/'.$diff->getID().'/changesets/'.$path;
64 }
65
66 throw new PhutilMethodNotImplementedException();
67 }
68
69 protected function getBuiltinQueryNames() {
70 $names = array();
71 $names['all'] = pht('All Changesets');
72 return $names;
73 }
74
75 public function buildSavedQueryFromBuiltin($query_key) {
76 $query = $this->newSavedQuery();
77 $query->setQueryKey($query_key);
78
79 $viewer = $this->requireViewer();
80
81 switch ($query_key) {
82 case 'all':
83 return $query->setParameter('order', 'oldest');
84 }
85
86 return parent::buildSavedQueryFromBuiltin($query_key);
87 }
88
89 /**
90 * @param array<DifferentialChangeset> $changesets
91 * @param PhabricatorSavedQuery $query
92 * @param array<PhabricatorObjectHandle> $handles
93 */
94 protected function renderResultList(
95 array $changesets,
96 PhabricatorSavedQuery $query,
97 array $handles) {
98
99 assert_instances_of($changesets, DifferentialChangeset::class);
100 $viewer = $this->requireViewer();
101
102 $rows = array();
103 foreach ($changesets as $changeset) {
104 $link = phutil_tag(
105 'a',
106 array(
107 'href' => '/differential/changeset/?ref='.$changeset->getID(),
108 ),
109 $changeset->getDisplayFilename());
110
111 $type = $changeset->getChangeType();
112
113 $title = DifferentialChangeType::getFullNameForChangeType($type);
114
115 $add_lines = $changeset->getAddLines();
116 if (!$add_lines) {
117 $add_lines = null;
118 } else {
119 $add_lines = '+'.$add_lines;
120 }
121
122 $rem_lines = $changeset->getDelLines();
123 if (!$rem_lines) {
124 $rem_lines = null;
125 } else {
126 $rem_lines = '-'.$rem_lines;
127 }
128
129 $rows[] = array(
130 $changeset->newFileTreeIcon(),
131 $title,
132 $link,
133 );
134 }
135
136 $table = id(new AphrontTableView($rows))
137 ->setHeaders(
138 array(
139 null,
140 pht('Change'),
141 pht('Path'),
142 ))
143 ->setColumnClasses(
144 array(
145 null,
146 null,
147 'pri wide',
148 ));
149
150 return id(new PhabricatorApplicationSearchResultView())
151 ->setTable($table);
152 }
153
154}