From: Timo Tijhof Date: Wed, 27 Mar 2013 21:31:05 +0000 (+0100) Subject: OpenSearch: Error for unsupported formats and adding format=jsonfm X-Git-Tag: 1.31.0-rc.0~20181^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=0509c1ed0e5fea34818fc003bfb985ec59b3f533;p=lhc%2Fweb%2Fwiklou.git OpenSearch: Error for unsupported formats and adding format=jsonfm Previously it would just completely ignore the format parameter. Making it always serve JSON no matter the value of the format parameter. Now it properly errors when doing (for example) format=txt or format=xml. Also adding support for jsonfm. Change-Id: Ia98f54f41f39006312fb49ecd718f0f161f27c37 --- diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index ecb37d53c5..f8ce4a2b57 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -284,6 +284,8 @@ production. * The JSON output formatter now leaves forward slashes unescaped to improve human readability of URLs and similar strings. Also, a "utf8" option is now provided to use UTF-8 encoding instead of hex escape codes for most non-ASCII characters. +* action=opensearch no longer silently ignores the format parameter. +* action=opensearch now supports format=jsonfm. === API internal changes in 1.21 === * For debugging only, a new global $wgDebugAPI removes many API restrictions when true. diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index caf361aca9..315ace3715 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -1,7 +1,5 @@ @gmail.com" @@ -29,8 +27,20 @@ */ class ApiOpenSearch extends ApiBase { + /** + * 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() { @@ -94,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' ), + ) ); } @@ -103,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', ); }