jenkins-bot has submitted this change and it was merged.

Change subject: OpenSearch: Error for unsupported formats and adding 
format=jsonfm
......................................................................


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
---
M RELEASE-NOTES-1.21
M includes/api/ApiOpenSearch.php
2 files changed, 20 insertions(+), 3 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21
index ecb37d5..f8ce4a2 100644
--- a/RELEASE-NOTES-1.21
+++ b/RELEASE-NOTES-1.21
@@ -284,6 +284,8 @@
 * 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 caf361a..315ace3 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,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 @@
                                ApiBase::PARAM_ISMULTI => true
                        ),
                        'suggest' => false,
+                       'format' => array(
+                               ApiBase::PARAM_DFLT => 'json',
+                               ApiBase::PARAM_TYPE => array( 'json', 'jsonfm' 
),
+                       )
                );
        }
 
@@ -103,6 +117,7 @@
                        'limit' => 'Maximum amount of results to return',
                        'namespace' => 'Namespaces to search',
                        'suggest' => 'Do nothing if $wgEnableOpenSearchSuggest 
is false',
+                       'format' => 'The format of the output',
                );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/56320
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia98f54f41f39006312fb49ecd718f0f161f27c37
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to