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