3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
4 * Copyright © 2008 Brooke Vibber <bvibber@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
25 namespace MediaWiki\Api
;
30 class ApiOpenSearchFormatJson
extends ApiFormatJson
{
32 private $warningsAsError;
34 public function __construct( ApiMain
$main, string $fm, $warningsAsError ) {
35 parent
::__construct( $main, "json$fm" );
36 $this->warningsAsError
= $warningsAsError;
39 public function execute() {
40 $result = $this->getResult();
41 if ( !$result->getResultData( 'error' ) && !$result->getResultData( 'errors' ) ) {
42 // Ignore warnings or treat as errors, as requested
43 $warnings = $result->removeValue( 'warnings', null );
44 if ( $this->warningsAsError
&& $warnings ) {
46 'apierror-opensearch-json-warnings',
48 [ 'warnings' => $warnings ]
52 // Ignore any other unexpected keys (e.g. from $wgDebugToolbar)
53 $remove = array_keys( array_diff_key(
54 $result->getResultData(),
55 [ 0 => 'search', 1 => 'terms', 2 => 'descriptions', 3 => 'urls' ]
57 foreach ( $remove as $key ) {
58 $result->removeValue( $key, null );
66 /** @deprecated class alias since 1.43 */
67 class_alias( ApiOpenSearchFormatJson
::class, 'ApiOpenSearchFormatJson' );