Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoFormatParamsAPI
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 4
30
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 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getExamples
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Adds the 'cargoformatparams' action to the MediaWiki API.
4 *
5 * @ingroup Cargo
6 */
7class CargoFormatParamsAPI extends ApiBase {
8
9    public function __construct( $query, $moduleName ) {
10        parent::__construct( $query, $moduleName );
11    }
12
13    public function execute() {
14        $params = $this->extractRequestParams();
15        $queryFormat = $params['queryformat'];
16        $formatClasses = CargoQueryDisplayer::getAllFormatClasses();
17        if ( !array_key_exists( $queryFormat, $formatClasses ) ) {
18            $this->dieWithError( "Format \"$queryFormat\" not found." );
19        }
20        /** @var CargoDisplayFormat $formatClass */
21        $formatClass = $formatClasses[$queryFormat];
22        $data = $formatClass::allowedParameters();
23
24        // Set top-level elements.
25        $result = $this->getResult();
26        $result->setIndexedTagName( $data, 'p' );
27        $result->addValue( null, $this->getModuleName(), $data );
28    }
29
30    protected function getAllowedParams() {
31        return [
32            'queryformat' => null
33        ];
34    }
35
36    protected function getExamples() {
37        return [
38            'api.php?action=cargoformatparams&format=json&queryformat=calendar'
39        ];
40    }
41
42}