Merge "Add function to clear mPreparedEdit, to use in cases of mutable content"
[lhc/web/wiklou.git] / includes / api / ApiOpenSearch.php
index caf361a..433b743 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 /**
- *
- *
  * Created on Oct 13, 2006
  *
  * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  */
 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 +105,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 +118,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',
                );
        }