diff --git a/src/applications/conduit/query/PhabricatorConduitMethodQuery.php b/src/applications/conduit/query/PhabricatorConduitMethodQuery.php index 512dc70e6f..0409e4ceb3 100644 --- a/src/applications/conduit/query/PhabricatorConduitMethodQuery.php +++ b/src/applications/conduit/query/PhabricatorConduitMethodQuery.php @@ -1,173 +1,157 @@ methods = $methods; return $this; } public function withNameContains($name_contains) { $this->nameContains = $name_contains; return $this; } - public function withApplicationNames(array $application_names) { - $this->applicationNames = $application_names; - return $this; - } - public function withIsStable($is_stable) { $this->isStable = $is_stable; return $this; } public function withIsUnstable($is_unstable) { $this->isUnstable = $is_unstable; return $this; } public function withIsDeprecated($is_deprecated) { $this->isDeprecated = $is_deprecated; return $this; } public function withIsInternal($is_internal) { $this->isInternal = $is_internal; return $this; } protected function loadPage() { $methods = $this->getAllMethods(); $methods = $this->filterMethods($methods); return $methods; } private function getAllMethods() { return id(new PhutilClassMapQuery()) ->setAncestorClass('ConduitAPIMethod') ->setSortMethod('getSortOrder') ->execute(); } private function filterMethods(array $methods) { foreach ($methods as $key => $method) { $application = $method->getApplication(); if (!$application) { continue; } if (!$application->isInstalled()) { unset($methods[$key]); } } $status = array( ConduitAPIMethod::METHOD_STATUS_STABLE => $this->isStable, ConduitAPIMethod::METHOD_STATUS_DEPRECATED => $this->isDeprecated, ConduitAPIMethod::METHOD_STATUS_UNSTABLE => $this->isUnstable, ); // Only apply status filters if any of them are set. if (array_filter($status)) { foreach ($methods as $key => $method) { $keep = idx($status, $method->getMethodStatus()); if (!$keep) { unset($methods[$key]); } } } - if ($this->applicationNames) { - $map = array_fuse($this->applicationNames); - foreach ($methods as $key => $method) { - $needle = $method->getApplicationName(); - $needle = phutil_utf8_strtolower($needle); - if (empty($map[$needle])) { - unset($methods[$key]); - } - } - } - if ($this->nameContains) { $needle = phutil_utf8_strtolower($this->nameContains); foreach ($methods as $key => $method) { $haystack = $method->getAPIMethodName(); $haystack = phutil_utf8_strtolower($haystack); if (strpos($haystack, $needle) === false) { unset($methods[$key]); } } } if ($this->methods) { $map = array_fuse($this->methods); foreach ($methods as $key => $method) { $needle = $method->getAPIMethodName(); if (empty($map[$needle])) { unset($methods[$key]); } } } if ($this->isInternal !== null) { foreach ($methods as $key => $method) { if ($method->isInternalAPI() !== $this->isInternal) { unset($methods[$key]); } } } return $methods; } protected function willFilterPage(array $methods) { $application_phids = array(); foreach ($methods as $method) { $application = $method->getApplication(); if ($application === null) { continue; } $application_phids[] = $application->getPHID(); } if ($application_phids) { $applications = id(new PhabricatorApplicationQuery()) ->setParentQuery($this) ->setViewer($this->getViewer()) ->withPHIDs($application_phids) ->execute(); $applications = mpull($applications, null, 'getPHID'); } else { $applications = array(); } // Remove methods which belong to an application the viewer can not see. foreach ($methods as $key => $method) { $application = $method->getApplication(); if ($application === null) { continue; } if (empty($applications[$application->getPHID()])) { $this->didRejectResult($method); unset($methods[$key]); } } return $methods; } public function getQueryApplicationClass() { return 'PhabricatorConduitApplication'; } } diff --git a/src/applications/conduit/query/PhabricatorConduitSearchEngine.php b/src/applications/conduit/query/PhabricatorConduitSearchEngine.php index 22e4e19e53..3c01005722 100644 --- a/src/applications/conduit/query/PhabricatorConduitSearchEngine.php +++ b/src/applications/conduit/query/PhabricatorConduitSearchEngine.php @@ -1,206 +1,184 @@ setParameter('isStable', $request->getStr('isStable')); $saved->setParameter('isUnstable', $request->getStr('isUnstable')); $saved->setParameter('isDeprecated', $request->getStr('isDeprecated')); - - $saved->setParameter( - 'applicationNames', - $request->getStrList('applicationNames')); - $saved->setParameter('nameContains', $request->getStr('nameContains')); return $saved; } public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { $query = id(new PhabricatorConduitMethodQuery()); $query->withIsStable($saved->getParameter('isStable')); $query->withIsUnstable($saved->getParameter('isUnstable')); $query->withIsDeprecated($saved->getParameter('isDeprecated')); $query->withIsInternal(false); - $names = $saved->getParameter('applicationNames', array()); - if ($names) { - $query->withApplicationNames($names); - } - $contains = $saved->getParameter('nameContains'); if (strlen($contains)) { $query->withNameContains($contains); } return $query; } public function buildSearchForm( AphrontFormView $form, PhabricatorSavedQuery $saved) { $form ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name Contains')) ->setName('nameContains') ->setValue($saved->getParameter('nameContains'))); - $names = $saved->getParameter('applicationNames', array()); - $form - ->appendChild( - id(new AphrontFormTextControl()) - ->setLabel(pht('Applications')) - ->setName('applicationNames') - ->setValue(implode(', ', $names)) - ->setCaption( - pht( - 'Example: %s', - phutil_tag('tt', array(), 'differential, paste')))); - $is_stable = $saved->getParameter('isStable'); $is_unstable = $saved->getParameter('isUnstable'); $is_deprecated = $saved->getParameter('isDeprecated'); $form ->appendChild( id(new AphrontFormCheckboxControl()) ->setLabel('Stability') ->addCheckbox( 'isStable', 1, hsprintf( '%s: %s', pht('Stable Methods'), pht('Show established API methods with stable interfaces.')), $is_stable) ->addCheckbox( 'isUnstable', 1, hsprintf( '%s: %s', pht('Unstable Methods'), pht('Show new methods which are subject to change.')), $is_unstable) ->addCheckbox( 'isDeprecated', 1, hsprintf( '%s: %s', pht('Deprecated Methods'), pht( 'Show old methods which will be deleted in a future '. 'version of Phabricator.')), $is_deprecated)); } protected function getURI($path) { return '/conduit/'.$path; } protected function getBuiltinQueryNames() { return array( 'modern' => pht('Modern Methods'), 'all' => pht('All Methods'), ); } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'modern': return $query ->setParameter('isStable', true) ->setParameter('isUnstable', true); case 'all': return $query ->setParameter('isStable', true) ->setParameter('isUnstable', true) ->setParameter('isDeprecated', true); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $methods, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($methods, 'ConduitAPIMethod'); $viewer = $this->requireViewer(); $out = array(); $last = null; $list = null; foreach ($methods as $method) { $app = $method->getApplicationName(); if ($app !== $last) { $last = $app; if ($list) { $out[] = $list; } $list = id(new PHUIObjectItemListView()); $list->setHeader($app); $app_object = $method->getApplication(); if ($app_object) { $app_name = $app_object->getName(); } else { $app_name = $app; } } $method_name = $method->getAPIMethodName(); $item = id(new PHUIObjectItemView()) ->setHeader($method_name) ->setHref($this->getApplicationURI('method/'.$method_name.'/')) ->addAttribute($method->getMethodSummary()); switch ($method->getMethodStatus()) { case ConduitAPIMethod::METHOD_STATUS_STABLE: break; case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: $item->addIcon('fa-warning', pht('Unstable')); $item->setStatusIcon('fa-warning yellow'); break; case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: $item->addIcon('fa-warning', pht('Deprecated')); $item->setStatusIcon('fa-warning red'); break; } $list->addItem($item); } if ($list) { $out[] = $list; } $result = new PhabricatorApplicationSearchResultView(); $result->setContent($out); return $result; } }