Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
CargoFieldsAPI | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
getAllowedParams | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParamDescription | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Adds the 'cargofields' action to the MediaWiki API |
4 | * |
5 | * @ingroup Cargo |
6 | * @author Sanjay Thiyagarajan |
7 | * |
8 | */ |
9 | class CargoFieldsAPI extends ApiBase { |
10 | |
11 | public function __construct( $query, $moduleName ) { |
12 | parent::__construct( $query, $moduleName ); |
13 | } |
14 | |
15 | public function execute() { |
16 | $params = $this->extractRequestParams(); |
17 | $tableName = $params['table']; |
18 | |
19 | if ( $tableName == '' ) { |
20 | $this->dieWithError( 'The table name must be specified', 'param_substr' ); |
21 | } |
22 | |
23 | try { |
24 | $queryResults = CargoUtils::getTableSchemas( [ $tableName ] )[ $tableName ]->mFieldDescriptions; |
25 | } catch ( Exception $e ) { |
26 | $this->dieWithError( $e->getMessage(), 'db_error' ); |
27 | } |
28 | |
29 | // Format data as the API requires it. |
30 | $formattedData = []; |
31 | foreach ( $queryResults as $fieldName => $fieldDescription ) { |
32 | $formattedData[ $fieldName ] = $fieldDescription->toDBArray(); |
33 | } |
34 | |
35 | // Set top-level elements. |
36 | $result = $this->getResult(); |
37 | $result->setIndexedTagName( $formattedData, 'p' ); |
38 | $result->addValue( null, $this->getModuleName(), $formattedData ); |
39 | } |
40 | |
41 | protected function getAllowedParams() { |
42 | return [ |
43 | 'table' => [ |
44 | ApiBase::PARAM_TYPE => 'string' |
45 | ] |
46 | ]; |
47 | } |
48 | |
49 | protected function getDescription() { |
50 | return 'Fetches all the fields in the specified table'; |
51 | } |
52 | |
53 | protected function getParamDescription() { |
54 | return [ |
55 | 'table' => 'The Cargo database table on which to search' |
56 | ]; |
57 | } |
58 | |
59 | } |