@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up "ids" and "phids" handling in SearchEngines

Summary:
Ref T9964. I added several hacks to get these working. Clean them up and pull this into a proper extension.

The behavior in the web UI is:

- they work in all applications; but
- they only show up in the UI if a value is specified.

So if you visit `/view/?ids=1,2` you get the field, but normally it's not present. We could refine this later. I'm going to add documentation about how to prefill these forms regardless, which should make this discoverable by reading the documentation.

There's one teensey weensey hack: in the API, I push these fields to the top of the table. That one feels OK, since it's purely a convenience/display adjustment.

Test Plan: Queried by IDs, reviewed docs.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9964

Differential Revision: https://secure.phabricator.com/D14769

+142 -43
+6
src/__phutil_library_map__.php
··· 2349 2349 'PhabricatorHovercardView' => 'view/widget/hovercard/PhabricatorHovercardView.php', 2350 2350 'PhabricatorHunksManagementMigrateWorkflow' => 'applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php', 2351 2351 'PhabricatorHunksManagementWorkflow' => 'applications/differential/management/PhabricatorHunksManagementWorkflow.php', 2352 + 'PhabricatorIDsSearchEngineExtension' => 'applications/search/engineextension/PhabricatorIDsSearchEngineExtension.php', 2353 + 'PhabricatorIDsSearchField' => 'applications/search/field/PhabricatorIDsSearchField.php', 2352 2354 'PhabricatorIRCProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php', 2353 2355 'PhabricatorIconRemarkupRule' => 'applications/macro/markup/PhabricatorIconRemarkupRule.php', 2354 2356 'PhabricatorImageMacroRemarkupRule' => 'applications/macro/markup/PhabricatorImageMacroRemarkupRule.php', ··· 2625 2627 'PhabricatorPHIDResolver' => 'applications/phid/resolver/PhabricatorPHIDResolver.php', 2626 2628 'PhabricatorPHIDType' => 'applications/phid/type/PhabricatorPHIDType.php', 2627 2629 'PhabricatorPHIDTypeTestCase' => 'applications/phid/type/__tests__/PhabricatorPHIDTypeTestCase.php', 2630 + 'PhabricatorPHIDsSearchField' => 'applications/search/field/PhabricatorPHIDsSearchField.php', 2628 2631 'PhabricatorPHPASTApplication' => 'applications/phpast/application/PhabricatorPHPASTApplication.php', 2629 2632 'PhabricatorPHPConfigSetupCheck' => 'applications/config/check/PhabricatorPHPConfigSetupCheck.php', 2630 2633 'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php', ··· 6539 6542 'PhabricatorHovercardView' => 'AphrontView', 6540 6543 'PhabricatorHunksManagementMigrateWorkflow' => 'PhabricatorHunksManagementWorkflow', 6541 6544 'PhabricatorHunksManagementWorkflow' => 'PhabricatorManagementWorkflow', 6545 + 'PhabricatorIDsSearchEngineExtension' => 'PhabricatorSearchEngineExtension', 6546 + 'PhabricatorIDsSearchField' => 'PhabricatorSearchField', 6542 6547 'PhabricatorIRCProtocolAdapter' => 'PhabricatorProtocolAdapter', 6543 6548 'PhabricatorIconRemarkupRule' => 'PhutilRemarkupRule', 6544 6549 'PhabricatorImageMacroRemarkupRule' => 'PhutilRemarkupRule', ··· 6847 6852 'PhabricatorPHIDResolver' => 'Phobject', 6848 6853 'PhabricatorPHIDType' => 'Phobject', 6849 6854 'PhabricatorPHIDTypeTestCase' => 'PhutilTestCase', 6855 + 'PhabricatorPHIDsSearchField' => 'PhabricatorSearchField', 6850 6856 'PhabricatorPHPASTApplication' => 'PhabricatorApplication', 6851 6857 'PhabricatorPHPConfigSetupCheck' => 'PhabricatorSetupCheck', 6852 6858 'PhabricatorPHPMailerConfigOptions' => 'PhabricatorApplicationConfigOptions',
+1 -1
src/applications/conduit/parametertype/ConduitIntListParameterType.php
··· 18 18 } 19 19 } 20 20 21 - return $this->validateIntList($request, $key, $list); 21 + return $list; 22 22 } 23 23 24 24 protected function getParameterTypeName() {
+1 -1
src/applications/conduit/parametertype/ConduitParameterType.php
··· 26 26 27 27 28 28 final public function getExists(array $request, $key) { 29 - return $this->getValueExists($request, $key); 29 + return $this->getParameterExists($request, $key); 30 30 } 31 31 32 32
+1 -1
src/applications/conduit/query/ConduitResultSearchEngineExtension.php
··· 10 10 } 11 11 12 12 public function getExtensionOrder() { 13 - return 1000; 13 + return 1500; 14 14 } 15 15 16 16 public function getExtensionName() {
-3
src/applications/maniphest/query/ManiphestTaskSearchEngine.php
··· 94 94 ->setLabel(pht('Group By')) 95 95 ->setKey('group') 96 96 ->setOptions($this->getGroupOptions()), 97 - id(new PhabricatorSearchStringListField()) 98 - ->setLabel(pht('Task IDs')) 99 - ->setKey('ids'), 100 97 id(new PhabricatorSearchDateField()) 101 98 ->setLabel(pht('Created After')) 102 99 ->setKey('createdStart'),
-35
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 1070 1070 1071 1071 // These are handled separately for Conduit, so don't show them as 1072 1072 // supported. 1073 - unset($fields['ids']); 1074 - unset($fields['phids']); 1075 1073 unset($fields['order']); 1076 1074 unset($fields['limit']); 1077 - 1078 - // TODO: Clean these up, shortly. 1079 - $fields = array( 1080 - 'ids' => id(new PhabricatorSearchDatasourceField()) 1081 - ->setKey('ids') 1082 - ->setLabel(pht('IDs')) 1083 - ->setDescription( 1084 - pht('Search for objects with specific IDs.')) 1085 - ->setConduitParameterType(new ConduitIntListParameterType()), 1086 - 'phids' => id(new PhabricatorSearchDatasourceField()) 1087 - ->setKey('phids') 1088 - ->setLabel(pht('PHIDs')) 1089 - ->setDescription( 1090 - pht('Search for objects with specific PHIDs.')) 1091 - ->setConduitParameterType(new ConduitPHIDListParameterType()), 1092 - ) + $fields; 1093 1075 1094 1076 $viewer = $this->requireViewer(); 1095 1077 foreach ($fields as $key => $field) { ··· 1145 1127 $query = $this->buildQueryFromSavedQuery($saved_query); 1146 1128 $pager = $this->newPagerForSavedQuery($saved_query); 1147 1129 1148 - $this->setAutomaticConstraintsForConduit($query, $request, $constraints); 1149 1130 $this->setQueryOrderForConduit($query, $request); 1150 1131 $this->setPagerLimitForConduit($pager, $request); 1151 1132 $this->setPagerOffsetsForConduit($pager, $request); ··· 1220 1201 } 1221 1202 1222 1203 return $extensions; 1223 - } 1224 - 1225 - private function setAutomaticConstraintsForConduit( 1226 - $query, 1227 - ConduitAPIRequest $request, 1228 - array $constraints) { 1229 - 1230 - $with_ids = idx($constraints, 'ids'); 1231 - if ($with_ids) { 1232 - $query->withIDs($with_ids); 1233 - } 1234 - 1235 - $with_phids = idx($constraints, 'phids'); 1236 - if ($with_phids) { 1237 - $query->withPHIDs($with_phids); 1238 - } 1239 1204 } 1240 1205 1241 1206 private function setQueryOrderForConduit($query, ConduitAPIRequest $request) {
+7
src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php
··· 163 163 164 164 $fields = $engine->getSearchFieldsForConduit(); 165 165 166 + // As a convenience, put these fields at the very top, even if the engine 167 + // specifies and alternate display order for the web UI. These fields are 168 + // very important in the API and nearly useless in the web UI. 169 + $fields = array_select_keys( 170 + $fields, 171 + array('ids', 'phids')) + $fields; 172 + 166 173 $rows = array(); 167 174 foreach ($fields as $field) { 168 175 $key = $field->getConduitKey();
+55
src/applications/search/engineextension/PhabricatorIDsSearchEngineExtension.php
··· 1 + <?php 2 + 3 + final class PhabricatorIDsSearchEngineExtension 4 + extends PhabricatorSearchEngineExtension { 5 + 6 + const EXTENSIONKEY = 'ids'; 7 + 8 + public function isExtensionEnabled() { 9 + return true; 10 + } 11 + 12 + public function getExtensionName() { 13 + return pht('Supports ID/PHID Queries'); 14 + } 15 + 16 + public function getExtensionOrder() { 17 + return 1000; 18 + } 19 + 20 + public function supportsObject($object) { 21 + return true; 22 + } 23 + 24 + public function getSearchFields($object) { 25 + return array( 26 + id(new PhabricatorIDsSearchField()) 27 + ->setKey('ids') 28 + ->setLabel(pht('IDs')) 29 + ->setDescription( 30 + pht('Search for objects with specific IDs.')), 31 + id(new PhabricatorPHIDsSearchField()) 32 + ->setKey('phids') 33 + ->setLabel(pht('PHIDs')) 34 + ->setDescription( 35 + pht('Search for objects with specific PHIDs.')), 36 + ); 37 + } 38 + 39 + public function applyConstraintsToQuery( 40 + $object, 41 + $query, 42 + PhabricatorSavedQuery $saved, 43 + array $map) { 44 + 45 + if ($map['ids']) { 46 + $query->withIDs($map['ids']); 47 + } 48 + 49 + if ($map['phids']) { 50 + $query->withPHIDs($map['phids']); 51 + } 52 + 53 + } 54 + 55 + }
+30
src/applications/search/field/PhabricatorIDsSearchField.php
··· 1 + <?php 2 + 3 + final class PhabricatorIDsSearchField 4 + extends PhabricatorSearchField { 5 + 6 + protected function getDefaultValue() { 7 + return array(); 8 + } 9 + 10 + protected function getValueFromRequest(AphrontRequest $request, $key) { 11 + return $request->getStrList($key); 12 + } 13 + 14 + protected function newControl() { 15 + if (strlen($this->getValueForControl())) { 16 + return new AphrontFormTextControl(); 17 + } else { 18 + return null; 19 + } 20 + } 21 + 22 + protected function getValueForControl() { 23 + return implode(', ', parent::getValueForControl()); 24 + } 25 + 26 + protected function newConduitParameterType() { 27 + return new ConduitIntListParameterType(); 28 + } 29 + 30 + }
+30
src/applications/search/field/PhabricatorPHIDsSearchField.php
··· 1 + <?php 2 + 3 + final class PhabricatorPHIDsSearchField 4 + extends PhabricatorSearchField { 5 + 6 + protected function getDefaultValue() { 7 + return array(); 8 + } 9 + 10 + protected function getValueFromRequest(AphrontRequest $request, $key) { 11 + return $request->getStrList($key); 12 + } 13 + 14 + protected function newControl() { 15 + if (strlen($this->getValueForControl())) { 16 + return new AphrontFormTextControl(); 17 + } else { 18 + return null; 19 + } 20 + } 21 + 22 + protected function getValueForControl() { 23 + return implode(', ', parent::getValueForControl()); 24 + } 25 + 26 + protected function newConduitParameterType() { 27 + return new ConduitPHIDListParameterType(); 28 + } 29 + 30 + }
+11 -2
src/applications/search/field/PhabricatorSearchField.php
··· 273 273 274 274 275 275 protected function renderControl() { 276 + $control = $this->newControl(); 277 + 278 + if (!$control) { 279 + return null; 280 + } 281 + 276 282 // TODO: We should `setError($this->getShortError())` here, but it looks 277 283 // terrible in the form layout. 278 284 279 - return $this->newControl() 285 + return $control 280 286 ->setValue($this->getValueForControl()) 281 287 ->setName($this->getKey()) 282 288 ->setLabel($this->getLabel()); 283 289 } 284 290 285 291 public function appendToForm(AphrontFormView $form) { 286 - $form->appendControl($this->renderControl()); 292 + $control = $this->renderControl(); 293 + if ($control !== null) { 294 + $form->appendControl($this->renderControl()); 295 + } 287 296 return $this; 288 297 } 289 298