Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
CargoRecreateDataAction | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
show | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
displayTab | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | use MediaWiki\Title\Title; |
5 | |
6 | /** |
7 | * Handles the 'recreatedata' action. |
8 | * |
9 | * @author Yaron Koren |
10 | * @ingroup Cargo |
11 | */ |
12 | |
13 | class CargoRecreateDataAction extends Action { |
14 | /** |
15 | * Return the name of the action this object responds to |
16 | * @return string lowercase |
17 | */ |
18 | public function getName() { |
19 | return 'recreatedata'; |
20 | } |
21 | |
22 | /** |
23 | * The main action entry point. Do all output for display and send it |
24 | * to the context output. |
25 | * $this->getOutput(), etc. |
26 | */ |
27 | public function show() { |
28 | $title = $this->getTitle(); |
29 | |
30 | // These tabs should only exist for template pages, that |
31 | // either call (or called) #cargo_declare, or call |
32 | // #cargo_attach. |
33 | [ $tableName, $isDeclared ] = CargoUtils::getTableNameForTemplate( $title ); |
34 | |
35 | if ( $tableName == '' ) { |
36 | $out = $this->getOutput(); |
37 | $out->setPageTitle( $this->msg( 'cargo-createdatatable' )->parse() ); |
38 | // @TODO - create an i18n message for this. |
39 | $out->addHTML( CargoUtils::formatError( 'This template does not declare any Cargo table.' ) ); |
40 | return; |
41 | } |
42 | |
43 | $recreateDataPage = new SpecialCargoRecreateData( $title, $tableName, $isDeclared ); |
44 | $recreateDataPage->execute(); |
45 | } |
46 | |
47 | /** |
48 | * Adds an "action" (i.e., a tab) to recreate the current article's data |
49 | * |
50 | * @param Title $obj |
51 | * @param array &$links |
52 | * @return bool |
53 | */ |
54 | public static function displayTab( $obj, &$links ) { |
55 | $title = $obj->getTitle(); |
56 | if ( !$title || $title->getNamespace() !== NS_TEMPLATE ) { |
57 | return true; |
58 | } |
59 | |
60 | $user = $obj->getUser(); |
61 | $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); |
62 | if ( !$permissionManager->userCan( 'recreatecargodata', $user, $title ) ) { |
63 | return true; |
64 | } |
65 | |
66 | $request = $obj->getRequest(); |
67 | |
68 | // Make sure that this is a template page, that it either |
69 | // has (or had) a #cargo_declare call or has a #cargo_attach |
70 | // call, and that the user is allowed to recreate its data. |
71 | [ $tableName, $isDeclared ] = CargoUtils::getTableNameForTemplate( $title ); |
72 | if ( $tableName == '' ) { |
73 | return true; |
74 | } |
75 | |
76 | // Check if table already exists, and set tab accordingly. |
77 | if ( CargoUtils::tableFullyExists( $tableName ) ) { |
78 | $recreateDataTabMsg = 'recreatedata'; |
79 | } else { |
80 | $recreateDataTabMsg = 'cargo-createdatatable'; |
81 | } |
82 | |
83 | $recreateDataTab = [ |
84 | 'class' => ( $request->getVal( 'action' ) == 'recreatedata' ) ? 'selected' : '', |
85 | 'text' => $obj->msg( $recreateDataTabMsg )->parse(), |
86 | 'href' => $title->getLocalURL( 'action=recreatedata' ) |
87 | ]; |
88 | |
89 | $links['views']['recreatedata'] = $recreateDataTab; |
90 | |
91 | return true; |
92 | } |
93 | |
94 | } |