Add an optional limit parameter (range 1 to 100) to the OpenSearch suggestion interface.
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 29 Dec 2007 00:14:22 +0000 (00:14 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 29 Dec 2007 00:14:22 +0000 (00:14 +0000)
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

index fe8217b..9553a85 100644 (file)
@@ -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)'
                );
        }