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