-
Notifications
You must be signed in to change notification settings - Fork 17
/
admin.php
137 lines (119 loc) · 4.61 KB
/
admin.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Extension\Event;
class admin_plugin_approve extends AdminPlugin
{
/**
* @return int sort number in admin menu
*/
public function getMenuSort()
{
return 1;
}
/**
* Should carry out any processing required by the plugin.
*/
public function handle()
{
global $ID;
/* @var Input */
global $INPUT;
/** @var helper_plugin_approve_db $db */
$db = $this->loadHelper('approve_db');
if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) {
$assignment = $INPUT->arr('assignment');
//insert empty string as NULL
if ($INPUT->str('action') === 'delete') {
$db->deleteMaintainer((int) $assignment['id']);
$db->updatePagesAssignments();
} else if ($INPUT->str('action') === 'add' && !blank($assignment['assign'])) {
$approver = '';
if (!blank($assignment['approver'])) {
$approver = $assignment['approver'];
} elseif (!blank($assignment['approver_fb'])) {
$approver = $assignment['approver_fb'];
}
$db->addMaintainer($assignment['assign'], $approver);
$db->updatePagesAssignments();
}
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'approve'), true, '&'));
}
}
/**
* Render HTML output, e.g. helpful text and a form
*/
public function html()
{
global $ID;
/* @var DokuWiki_Auth_Plugin $auth */
global $auth;
echo $this->locale_xhtml('assignments_intro');
echo '<form action="' . wl($ID) . '" action="post">';
echo '<input type="hidden" name="do" value="admin" />';
echo '<input type="hidden" name="page" value="approve" />';
echo '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
echo '<table class="inline">';
// header
echo '<tr>';
echo '<th>'.$this->getLang('admin h_assignment_namespace').'</th>';
echo '<th>'.$this->getLang('admin h_assignment_approver').'</th>';
echo '<th></th>';
echo '</tr>';
/** @var helper_plugin_approve_db $db */
$db = $this->loadHelper('approve_db');
$assignments = $db->getMaintainers();
foreach($assignments as $assignment) {
$id = $assignment['id'];
$namespace = $assignment['namespace'];
$approver = $assignment['approver'] ?: '---';
$link = wl(
$ID, array(
'do' => 'admin',
'page' => 'approve',
'action' => 'delete',
'sectok' => getSecurityToken(),
'assignment[id]' => $id
)
);
echo '<tr>';
echo '<td>' . hsc($namespace) . '</td>';
$user = $auth->getUserData($approver);
if ($user) {
echo '<td>' . hsc($user['name']) . '</td>';
} else {
echo '<td>' . hsc($approver) . '</td>';
}
echo '<td><a href="' . $link . '">'.$this->getLang('admin btn_delete').'</a></td>';
echo '</tr>';
}
// new assignment form
echo '<tr>';
echo '<td><input type="text" name="assignment[assign]" /></td>';
echo '<td>';
if ($auth->canDo('getUsers')) {
echo '<select name="assignment[approver]">';
echo '<option value="">---</option>';
if ($auth->canDo('getGroups')) {
foreach($auth->retrieveGroups() as $group) {
echo '<option value="@' . hsc($group) . '">' . '@' . hsc($group) . '</option>';
}
}
foreach($auth->retrieveUsers() as $login => $data) {
echo '<option value="' . hsc($login) . '">' . hsc($data['name']) . '</option>';
}
echo '</select>';
// in case your auth plugin can do groups, but not list them (like the default one),
// leave a text field as backup
if (!$auth->canDo('getGroups')) {
echo '<input name="assignment[approver_fb]" id="plugin__approve_group_input">';
}
} else {
echo '<input name="assignment[approver]">';
}
echo '</td>';
echo '<td><button type="submit" name="action" value="add">'.$this->getLang('admin btn_add').'</button></td>';
echo '</tr>';
echo '</table>';
}
}
// vim:ts=4:sw=4:et: