Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ApiOpenSearchFormatJson | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | /** |
3 | * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" |
4 | * Copyright © 2008 Brooke Vibber <bvibber@wikimedia.org> |
5 | * Copyright © 2014 Wikimedia Foundation and contributors |
6 | * |
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. |
11 | * |
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. |
16 | * |
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 |
21 | * |
22 | * @file |
23 | */ |
24 | |
25 | /** |
26 | * @ingroup API |
27 | */ |
28 | class ApiOpenSearchFormatJson extends ApiFormatJson { |
29 | private $warningsAsError; |
30 | |
31 | public function __construct( ApiMain $main, $fm, $warningsAsError ) { |
32 | parent::__construct( $main, "json$fm" ); |
33 | $this->warningsAsError = $warningsAsError; |
34 | } |
35 | |
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 ) { |
42 | $this->dieWithError( |
43 | 'apierror-opensearch-json-warnings', |
44 | 'warnings', |
45 | [ 'warnings' => $warnings ] |
46 | ); |
47 | } |
48 | |
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' ] |
53 | ) ); |
54 | foreach ( $remove as $key ) { |
55 | $result->removeValue( $key, null ); |
56 | } |
57 | } |
58 | |
59 | parent::execute(); |
60 | } |
61 | } |