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