-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCargoRecreateDataAction.php
100 lines (83 loc) · 2.55 KB
/
CargoRecreateDataAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Handles the 'recreatedata' action.
*
* @author Yaron Koren
* @ingroup Cargo
*/
class CargoRecreateDataAction {
/**
* Return the name of the action this object responds to
* @return String lowercase
*/
public function getName(){
return 'recreatedata';
}
/**
* The main action entry point. Do all output for display and send it to the context
* output.
* $this->getOutput(), etc.
*/
public static function show( $action, Article $article ) {
$title = $article->getTitle();
// These tabs should only exist for template pages, that
// either call (or called) #cargo_declare, or call
// #cargo_attach.
list( $tableName, $isDeclared ) = CargoUtils::getTableNameForTemplate( $title );
if ( $tableName == '' ) {
return true;
}
if ( $action == 'recreatedata' ) {
$recreateDataPage = new CargoRecreateData( $title, $tableName, $isDeclared );
$recreateDataPage->execute();
return false;
}
return true;
}
/**
* Adds an "action" (i.e., a tab) to edit the current article with
* a form
*/
static function displayTab( $obj, &$content_actions ) {
global $wgRequest;
$title = $obj->getTitle();
if ( !$title ) {
return true;
}
// Make sure that this is a template page, that it either
// has (or had) a #cargo_declare call or has a #cargo_attach
// call, and that the user is allowed to recreate its data.
list( $tableName, $isDeclared ) = CargoUtils::getTableNameForTemplate( $title );
if ( $tableName == '' ) {
return true;
}
if ( !$title->userCan( 'recreatecargodata' ) ) {
return true;
}
// Check if table already exists, and set tab accordingly.
if ( CargoUtils::tableExists( $tableName ) ) {
$recreateDataTabText = wfMessage( 'recreatedata' )->parse();
} else {
$recreateDataTabText = wfMessage( 'cargo-createdatatable' )->parse();
}
$recreateDataTab = array(
'class' => ( $wgRequest->getVal( 'action' ) == 'recreatdata' ) ? 'selected' : '',
'text' => $recreateDataTabText,
'href' => $title->getLocalURL( 'action=recreatedata' )
);
$content_actions['recreatedata'] = $recreateDataTab;
return true; // always return true, in order not to stop MW's hook processing!
}
/**
* Like displayTab(), but called with a different hook - this one is
* called for the 'Vector' skin, and others.
*/
static function displayTab2( $obj, &$links ) {
// The old '$content_actions' array is thankfully just a
// sub-array of this one.
$views_links = $links['actions'];
self::displayTab( $obj, $views_links );
$links['actions'] = $views_links;
return true;
}
}