'ApiModuleManager' => __DIR__ . '/includes/api/ApiModuleManager.php',
'ApiMove' => __DIR__ . '/includes/api/ApiMove.php',
'ApiOpenSearch' => __DIR__ . '/includes/api/ApiOpenSearch.php',
+ 'ApiOpenSearchFormatJson' => __DIR__ . '/includes/api/ApiOpenSearch.php',
'ApiOptions' => __DIR__ . '/includes/api/ApiOptions.php',
'ApiPageSet' => __DIR__ . '/includes/api/ApiPageSet.php',
'ApiParamInfo' => __DIR__ . '/includes/api/ApiParamInfo.php',
public function getCustomPrinter() {
switch ( $this->getFormat() ) {
case 'json':
- return $this->getMain()->createPrinterByName( 'json' . $this->fm );
+ return new ApiOpenSearchFormatJson(
+ $this->getMain(), $this->fm, $this->getParameter( 'warningsaserror' )
+ );
case 'xml':
$printer = $this->getMain()->createPrinterByName( 'xml' . $this->fm );
switch ( $this->getFormat() ) {
case 'json':
// http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.1
- $result->addArrayType( null, 'BCarray' );
+ $result->addArrayType( null, 'array' );
$result->addValue( null, 0, strval( $search ) );
$terms = array();
$descriptions = array();
'format' => array(
ApiBase::PARAM_DFLT => 'json',
ApiBase::PARAM_TYPE => array( 'json', 'jsonfm', 'xml', 'xmlfm' ),
- )
+ ),
+ 'warningsaserror' => false,
);
}
}
}
}
+
+class ApiOpenSearchFormatJson extends ApiFormatJson {
+ private $warningsAsError = false;
+
+ public function __construct( ApiMain $main, $fm, $warningsAsError ) {
+ parent::__construct( $main, "json$fm" );
+ $this->warningsAsError = $warningsAsError;
+ }
+
+ public function execute() {
+ if ( !$this->getResult()->getResultData( 'error' ) ) {
+ $warnings = $this->getResult()->removeValue( 'warnings' );
+ if ( $this->warningsAsError && $warnings ) {
+ $this->dieUsage(
+ 'Warnings cannot be represented in OpenSearch JSON format', 'warnings', 0,
+ array( 'warnings' => $warnings )
+ );
+ }
+ }
+
+ parent::execute();
+ }
+}
"apihelp-opensearch-param-suggest": "Do nothing if <var>[[mw:Manual:$wgEnableOpenSearchSuggest|$wgEnableOpenSearchSuggest]]</var> is false.",
"apihelp-opensearch-param-redirects": "How to handle redirects:\n;return:Return the redirect itself.\n;resolve:Return the target page. May return fewer than $1limit results.\nFor historical reasons, the default is \"return\" for $1format=json and \"resolve\" for other formats.",
"apihelp-opensearch-param-format": "The format of the output.",
+ "apihelp-opensearch-param-warningsaserror": "If warnings are raised with <kbd>format=json</kbd>, return an API error instead of ignoring them.",
"apihelp-opensearch-example-te": "Find pages beginning with <kbd>Te</kbd>.",
"apihelp-options-description": "Change preferences of the current user.\n\nOnly options which are registered in core or in one of installed extensions, or options with keys prefixed with \"userjs-\" (intended to be used by user scripts), can be set.",
"apihelp-opensearch-param-suggest": "{{doc-apihelp-param|opensearch|suggest}}",
"apihelp-opensearch-param-redirects": "{{doc-apihelp-param|opensearch|redirects}}",
"apihelp-opensearch-param-format": "{{doc-apihelp-param|opensearch|format}}",
+ "apihelp-opensearch-param-warningsaserror": "{{doc-apihelp-param|opensearch|warningsaserror}}",
"apihelp-opensearch-example-te": "{{doc-apihelp-example|opensearch}}",
"apihelp-options-description": "{{doc-apihelp-description|options}}",
"apihelp-options-param-reset": "{{doc-apihelp-param|options|reset}}",