From e1f0ca77b3884c38dbb0fcbd5e1a095eb997f273 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 29 Dec 2007 21:43:30 +0000 Subject: [PATCH] Using ApiBase's parameter framework handle ApiOpenSearch's limit parameter. --- includes/api/ApiOpenSearch.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 9553a85527..7ecf922ec2 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -44,10 +44,6 @@ class ApiOpenSearch extends ApiBase { public function execute() { $params = $this->extractRequestParams(); $search = $params['search']; - $limit = intval( $params['limit'] ); - if( $limit < 1 || $limit > 100 ) { - $limit = 10; - } // Open search results may be stored for a very long time $this->getMain()->setCacheMaxAge(1200); @@ -61,7 +57,7 @@ class ApiOpenSearch extends ApiBase { 'action' => 'query', 'list' => 'allpages', 'apnamespace' => $title->getNamespace(), - 'aplimit' => $limit, + 'aplimit' => $params['limit'], 'apprefix' => $title->getDBkey() )); @@ -89,14 +85,20 @@ class ApiOpenSearch extends ApiBase { protected function getAllowedParams() { return array ( 'search' => null, - 'limit' => 10 + 'limit' => array ( + ApiBase :: PARAM_DFLT => 10, + ApiBase :: PARAM_TYPE => 'limit', + ApiBase :: PARAM_MIN => 1, + ApiBase :: PARAM_MAX => 100, + ApiBase :: PARAM_MAX2 => 100 + ) ); } protected function getParamDescription() { return array ( 'search' => 'Search string', - 'limit' => 'Optional limit (default 10)' + 'limit' => 'Maximum amount of results to return' ); } -- 2.20.1