From 21e46f5f3aa4b2052599a42167b8f6d8679eae4e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 29 Dec 2007 00:14:22 +0000 Subject: [PATCH] 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. --- includes/api/ApiOpenSearch.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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)' ); } -- 2.20.1