- $search = null;
- extract($this->ExtractRequestParams());
-
- $title = Title :: newFromText($search);
- if(!$title)
- return; // Return empty result
-
- // Prepare nested request
- $params = new FauxRequest(array (
- 'action' => 'query',
- 'list' => 'allpages',
- 'apnamespace' => $title->getNamespace(),
- 'aplimit' => 10,
- 'apprefix' => $title->getDBkey()
- ));
-
- // Execute
- $module = new ApiMain($params);
- $module->execute();
-
- // Get resulting data
- $data = & $module->getResultData();
-
- // Reformat useful data for future printing by JSON engine
- $srchres = array ();
- foreach ($data['query']['allpages'] as $pageid => & $pageinfo) {
- // Note: this data will no be printable by the xml engine
- // because it does not support lists of unnamed items
- $srchres[] = $pageinfo['title'];
+ global $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry;
+ $params = $this->extractRequestParams();
+ $search = $params['search'];
+ $limit = $params['limit'];
+ $namespaces = $params['namespace'];
+ $suggest = $params['suggest'];
+
+ // MWSuggest or similar hit
+ if ( $suggest && !$wgEnableOpenSearchSuggest ) {
+ $srchres = array();
+ } else {
+ // Open search results may be stored for a very long
+ // time
+ $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry );
+ $this->getMain()->setCacheControl( array( 'must-revalidate' => false ) );
+
+ $srchres = PrefixSearch::titleSearch( $search, $limit,
+ $namespaces );