diff options
Diffstat (limited to 'includes/api/ApiOpenSearch.php')
-rw-r--r-- | includes/api/ApiOpenSearch.php | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index ef562741..315ace37 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -1,7 +1,5 @@ <?php /** - * - * * Created on Oct 13, 2006 * * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" @@ -29,12 +27,20 @@ */ class ApiOpenSearch extends ApiBase { - public function __construct( $main, $action ) { - parent::__construct( $main, $action ); - } - + /** + * Override built-in handling of format parameter. + * Only JSON is supported. + * + * @return ApiFormatBase + */ public function getCustomPrinter() { - return $this->getMain()->createPrinterByName( 'json' ); + $params = $this->extractRequestParams(); + $format = $params['format']; + $allowed = array( 'json', 'jsonfm' ); + if ( in_array( $format, $allowed ) ) { + return $this->getMain()->createPrinterByName( $format ); + } + return $this->getMain()->createPrinterByName( $allowed[0] ); } public function execute() { @@ -98,6 +104,10 @@ class ApiOpenSearch extends ApiBase { ApiBase::PARAM_ISMULTI => true ), 'suggest' => false, + 'format' => array( + ApiBase::PARAM_DFLT => 'json', + ApiBase::PARAM_TYPE => array( 'json', 'jsonfm' ), + ) ); } @@ -107,6 +117,7 @@ class ApiOpenSearch extends ApiBase { 'limit' => 'Maximum amount of results to return', 'namespace' => 'Namespaces to search', 'suggest' => 'Do nothing if $wgEnableOpenSearchSuggest is false', + 'format' => 'The format of the output', ); } @@ -123,8 +134,4 @@ class ApiOpenSearch extends ApiBase { public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/API:Opensearch'; } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } } |