Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiOpenSearchFormatJson
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
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 * @license GPL-2.0-or-later
8 * @file
9 */
10
11namespace MediaWiki\Api;
12
13/**
14 * @ingroup API
15 */
16class ApiOpenSearchFormatJson extends ApiFormatJson {
17
18    private bool $warningsAsError;
19
20    public function __construct( ApiMain $main, string $format, bool $warningsAsError ) {
21        parent::__construct( $main, $format );
22        $this->warningsAsError = $warningsAsError;
23    }
24
25    public function execute() {
26        $result = $this->getResult();
27        if ( !$result->getResultData( 'error' ) && !$result->getResultData( 'errors' ) ) {
28            // Ignore warnings or treat as errors, as requested
29            $warnings = $result->removeValue( 'warnings', null );
30            if ( $this->warningsAsError && $warnings ) {
31                $this->dieWithError(
32                    'apierror-opensearch-json-warnings',
33                    'warnings',
34                    [ 'warnings' => $warnings ]
35                );
36            }
37
38            // Ignore any other unexpected keys (e.g. from $wgDebugToolbar)
39            $remove = array_keys( array_diff_key(
40                $result->getResultData(),
41                [ 0 => 'search', 1 => 'terms', 2 => 'descriptions', 3 => 'urls' ]
42            ) );
43            foreach ( $remove as $key ) {
44                $result->removeValue( $key, null );
45            }
46        }
47
48        parent::execute();
49    }
50}
51
52/** @deprecated class alias since 1.43 */
53class_alias( ApiOpenSearchFormatJson::class, 'ApiOpenSearchFormatJson' );