3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
4 * Copyright © 2008 Brion Vibber <brion@wikimedia.org>
5 * Copyright © 2014 Wikimedia Foundation and contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
28 class ApiOpenSearchFormatJson
extends ApiFormatJson
{
29 private $warningsAsError = false;
31 public function __construct( ApiMain
$main, $fm, $warningsAsError ) {
32 parent
::__construct( $main, "json$fm" );
33 $this->warningsAsError
= $warningsAsError;
36 public function execute() {
37 $result = $this->getResult();
38 if ( !$result->getResultData( 'error' ) && !$result->getResultData( 'errors' ) ) {
39 // Ignore warnings or treat as errors, as requested
40 $warnings = $result->removeValue( 'warnings', null );
41 if ( $this->warningsAsError
&& $warnings ) {
43 'apierror-opensearch-json-warnings',
45 [ 'warnings' => $warnings ]
49 // Ignore any other unexpected keys (e.g. from $wgDebugToolbar)
50 $remove = array_keys( array_diff_key(
51 $result->getResultData(),
52 [ 0 => 'search', 1 => 'terms', 2 => 'descriptions', 3 => 'urls' ]
54 foreach ( $remove as $key ) {
55 $result->removeValue( $key, null );