Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoRecreateTablesAPI
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 8
132
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 / 17
0.00% covered (danger)
0.00%
0 / 1
20
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getParamDescription
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getDescription
0.00% covered (danger)
0.00%
0 / 2
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
 mustBePosted
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 needsToken
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Adds and handles the 'cargorecreatetables' action to the MediaWiki API.
4 *
5 * @ingroup Cargo
6 * @author Yaron Koren
7 */
8
9class CargoRecreateTablesAPI extends ApiBase {
10
11    public function __construct( $query, $moduleName ) {
12        parent::__construct( $query, $moduleName );
13    }
14
15    public function execute() {
16        $user = $this->getUser();
17
18        if ( !$user->isAllowed( 'recreatecargodata' ) || $user->getBlock() !== null ) {
19            $this->dieWithError( [ 'badaccess-groups' ] );
20        }
21
22        $params = $this->extractRequestParams();
23        $templateStr = $params['template'];
24        if ( $templateStr == '' ) {
25            $this->dieWithError( 'The template must be specified', 'param_substr' );
26        }
27        $createReplacement = $params['createReplacement'];
28
29        $templateTitle = Title::makeTitleSafe( NS_TEMPLATE, $templateStr );
30        $templatePageID = $templateTitle->getArticleID();
31        CargoUtils::recreateDBTablesForTemplate(
32            $templatePageID,
33            $createReplacement,
34            $user
35        );
36
37        // Set top-level elements.
38        $result = $this->getResult();
39        $result->addValue( null, 'success', true );
40    }
41
42    protected function getAllowedParams() {
43        return [
44            'template' => [
45                ApiBase::PARAM_TYPE => 'string',
46            ],
47            'createReplacement' => [
48                ApiBase::PARAM_TYPE => 'boolean',
49            ],
50        ];
51    }
52
53    protected function getParamDescription() {
54        return [
55            'template' => 'The template whose declared Cargo table(s) should be recreated',
56            'createReplacement' => 'Whether to put data into a replacement table',
57        ];
58    }
59
60    protected function getDescription() {
61        return 'An API module to recreate tables for the Cargo extension '
62            . '(https://www.mediawiki.org/Extension:Cargo)';
63    }
64
65    protected function getExamples() {
66        return [
67            'api.php?action=cargorecreatetables&template=City'
68        ];
69    }
70
71    public function mustBePosted() {
72        return true;
73    }
74
75    public function needsToken() {
76        return 'csrf';
77    }
78
79}