From: Brion Vibber Date: Sat, 29 Dec 2007 00:14:22 +0000 (+0000) Subject: Add an optional limit parameter (range 1 to 100) to the OpenSearch suggestion interface. X-Git-Tag: 1.31.0-rc.0~50236 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=21e46f5f3aa4b2052599a42167b8f6d8679eae4e;p=lhc%2Fweb%2Fwiklou.git Add an optional limit parameter (range 1 to 100) to the OpenSearch suggestion interface. Will be using this in adaptor to the Apple Dictionary widget's search, since we're having performance problems with the special-purpose search backend. --- diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index fe8217b704..9553a85527 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -44,6 +44,10 @@ 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); @@ -57,7 +61,7 @@ class ApiOpenSearch extends ApiBase { 'action' => 'query', 'list' => 'allpages', 'apnamespace' => $title->getNamespace(), - 'aplimit' => 10, + 'aplimit' => $limit, 'apprefix' => $title->getDBkey() )); @@ -84,13 +88,15 @@ class ApiOpenSearch extends ApiBase { protected function getAllowedParams() { return array ( - 'search' => null + 'search' => null, + 'limit' => 10 ); } protected function getParamDescription() { return array ( - 'search' => 'Search string' + 'search' => 'Search string', + 'limit' => 'Optional limit (default 10)' ); }