3 * API for MediaWiki 1.8+
5 * Created on Oct 13, 2006
7 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 // Eclipse helper - will be ignored in production
29 require_once( "ApiBase.php" );
35 class ApiOpenSearch
extends ApiBase
{
37 public function __construct( $main, $action ) {
38 parent
::__construct( $main, $action );
41 public function getCustomPrinter() {
42 return $this->getMain()->createPrinterByName( 'json' );
45 public function execute() {
46 global $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry;
47 $params = $this->extractRequestParams();
48 $search = $params['search'];
49 $limit = $params['limit'];
50 $namespaces = $params['namespace'];
51 $suggest = $params['suggest'];
53 // MWSuggest or similar hit
54 if ( $suggest && !$wgEnableOpenSearchSuggest ) {
57 // Open search results may be stored for a very long
59 $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry );
60 $this->getMain()->setCacheMode( 'public' );
62 $srchres = PrefixSearch
::titleSearch( $search, $limit,
65 // Set top level elements
66 $result = $this->getResult();
67 $result->addValue( null, 0, $search );
68 $result->addValue( null, 1, $srchres );
71 public function getAllowedParams() {
75 ApiBase
::PARAM_DFLT
=> 10,
76 ApiBase
::PARAM_TYPE
=> 'limit',
77 ApiBase
::PARAM_MIN
=> 1,
78 ApiBase
::PARAM_MAX
=> 100,
79 ApiBase
::PARAM_MAX2
=> 100
82 ApiBase
::PARAM_DFLT
=> NS_MAIN
,
83 ApiBase
::PARAM_TYPE
=> 'namespace',
84 ApiBase
::PARAM_ISMULTI
=> true
90 public function getParamDescription() {
92 'search' => 'Search string',
93 'limit' => 'Maximum amount of results to return',
94 'namespace' => 'Namespaces to search',
95 'suggest' => 'Do nothing if $wgEnableOpenSearchSuggest is false',
99 public function getDescription() {
100 return 'This module implements OpenSearch protocol';
103 protected function getExamples() {
105 'api.php?action=opensearch&search=Te'
109 public function getVersion() {
110 return __CLASS__
. ': $Id$';