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

Restore viewer() function to "Responsible Users" tokenizer in Differential

Summary:
Ref T10939. This makes the `viewer()` function work again. It retains its own meaning (viewer, plus all their projects and packages).

There's no `exact-viewer()` function; we could conceivably add one eventually if we need it.

Test Plan:
- Queried for `viewer()`, got the same results as querying by my own username.
- Browsed function in token browser.
- Reviewed autogenerated documentation.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10939

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

+118 -31
+2
src/__phutil_library_map__.php
··· 495 495 'DifferentialRequiredSignaturesField' => 'applications/differential/customfield/DifferentialRequiredSignaturesField.php', 496 496 'DifferentialResponsibleDatasource' => 'applications/differential/typeahead/DifferentialResponsibleDatasource.php', 497 497 'DifferentialResponsibleUserDatasource' => 'applications/differential/typeahead/DifferentialResponsibleUserDatasource.php', 498 + 'DifferentialResponsibleViewerFunctionDatasource' => 'applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php', 498 499 'DifferentialRevertPlanField' => 'applications/differential/customfield/DifferentialRevertPlanField.php', 499 500 'DifferentialReviewedByField' => 'applications/differential/customfield/DifferentialReviewedByField.php', 500 501 'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php', ··· 4720 4721 'DifferentialRequiredSignaturesField' => 'DifferentialCoreCustomField', 4721 4722 'DifferentialResponsibleDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 4722 4723 'DifferentialResponsibleUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 4724 + 'DifferentialResponsibleViewerFunctionDatasource' => 'PhabricatorTypeaheadDatasource', 4723 4725 'DifferentialRevertPlanField' => 'DifferentialStoredCustomField', 4724 4726 'DifferentialReviewedByField' => 'DifferentialCoreCustomField', 4725 4727 'DifferentialReviewer' => 'Phobject',
+36
src/applications/differential/typeahead/DifferentialResponsibleDatasource.php
··· 18 18 public function getComponentDatasources() { 19 19 return array( 20 20 new DifferentialResponsibleUserDatasource(), 21 + new DifferentialResponsibleViewerFunctionDatasource(), 21 22 new DifferentialExactUserFunctionDatasource(), 22 23 new PhabricatorProjectDatasource(), 23 24 new PhabricatorOwnersPackageDatasource(), 24 25 ); 26 + } 27 + 28 + public static function expandResponsibleUsers( 29 + PhabricatorUser $viewer, 30 + array $values) { 31 + 32 + $phids = array(); 33 + foreach ($values as $value) { 34 + if (phid_get_type($value) == PhabricatorPeopleUserPHIDType::TYPECONST) { 35 + $phids[] = $value; 36 + } 37 + } 38 + 39 + if (!$phids) { 40 + return $values; 41 + } 42 + 43 + $projects = id(new PhabricatorProjectQuery()) 44 + ->setViewer($viewer) 45 + ->withMemberPHIDs($phids) 46 + ->execute(); 47 + foreach ($projects as $project) { 48 + $phids[] = $project->getPHID(); 49 + $values[] = $project->getPHID(); 50 + } 51 + 52 + $packages = id(new PhabricatorOwnersPackageQuery()) 53 + ->setViewer($viewer) 54 + ->withOwnerPHIDs($phids) 55 + ->execute(); 56 + foreach ($packages as $package) { 57 + $values[] = $package->getPHID(); 58 + } 59 + 60 + return $values; 25 61 } 26 62 27 63 }
+3 -31
src/applications/differential/typeahead/DifferentialResponsibleUserDatasource.php
··· 22 22 } 23 23 24 24 protected function evaluateValues(array $values) { 25 - $viewer = $this->getViewer(); 26 - 27 - $phids = array(); 28 - foreach ($values as $value) { 29 - if (phid_get_type($value) == PhabricatorPeopleUserPHIDType::TYPECONST) { 30 - $phids[] = $value; 31 - } 32 - } 33 - 34 - if (!$phids) { 35 - return $values; 36 - } 37 - 38 - $projects = id(new PhabricatorProjectQuery()) 39 - ->setViewer($viewer) 40 - ->withMemberPHIDs($phids) 41 - ->execute(); 42 - foreach ($projects as $project) { 43 - $phids[] = $project->getPHID(); 44 - $values[] = $project->getPHID(); 45 - } 46 - 47 - $packages = id(new PhabricatorOwnersPackageQuery()) 48 - ->setViewer($viewer) 49 - ->withOwnerPHIDs($phids) 50 - ->execute(); 51 - foreach ($packages as $package) { 52 - $values[] = $package->getPHID(); 53 - } 54 - 55 - return $values; 25 + return DifferentialResponsibleDatasource::expandResponsibleUsers( 26 + $this->getViewer(), 27 + $values); 56 28 } 57 29 58 30 }
+77
src/applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php
··· 1 + <?php 2 + 3 + final class DifferentialResponsibleViewerFunctionDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getBrowseTitle() { 7 + return pht('Browse Viewer'); 8 + } 9 + 10 + public function getPlaceholderText() { 11 + return pht('Type viewer()...'); 12 + } 13 + 14 + public function getDatasourceApplicationClass() { 15 + return 'PhabricatorPeopleApplication'; 16 + } 17 + 18 + public function getDatasourceFunctions() { 19 + return array( 20 + 'viewer' => array( 21 + 'name' => pht('Current Viewer'), 22 + 'summary' => pht('Use the current viewing user.'), 23 + 'description' => pht( 24 + 'Show revisions the current viewer is responsible for. This '. 25 + 'function inclues revisions the viewer is responsible for through '. 26 + 'membership in projects and packages.'), 27 + ), 28 + ); 29 + } 30 + 31 + public function loadResults() { 32 + if ($this->getViewer()->getPHID()) { 33 + $results = array($this->renderViewerFunctionToken()); 34 + } else { 35 + $results = array(); 36 + } 37 + 38 + return $this->filterResultsAgainstTokens($results); 39 + } 40 + 41 + protected function canEvaluateFunction($function) { 42 + if (!$this->getViewer()->getPHID()) { 43 + return false; 44 + } 45 + 46 + return parent::canEvaluateFunction($function); 47 + } 48 + 49 + protected function evaluateFunction($function, array $argv_list) { 50 + $results = array(); 51 + foreach ($argv_list as $argv) { 52 + $results[] = $this->getViewer()->getPHID(); 53 + } 54 + 55 + return DifferentialResponsibleDatasource::expandResponsibleUsers( 56 + $this->getViewer(), 57 + $results); 58 + } 59 + 60 + public function renderFunctionTokens($function, array $argv_list) { 61 + $tokens = array(); 62 + foreach ($argv_list as $argv) { 63 + $tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( 64 + $this->renderViewerFunctionToken()); 65 + } 66 + return $tokens; 67 + } 68 + 69 + private function renderViewerFunctionToken() { 70 + return $this->newFunctionResult() 71 + ->setName(pht('Current Viewer')) 72 + ->setPHID('viewer()') 73 + ->setIcon('fa-user') 74 + ->setUnique(true); 75 + } 76 + 77 + }