-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaction.php
172 lines (149 loc) · 4.99 KB
/
action.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* Page Buttons plugin
*
* @copyright (c) 2020 Cody Ernesti
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Cody Ernesti
*
* Modified from: https://github.com/dregad/dokuwiki-plugin-deletepagebutton
*
* Original license info:
*
* @copyright (c) 2020 Damien Regad
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Damien Regad
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
use dokuwiki\plugin\pagebuttons\DeletePageButton;
use dokuwiki\plugin\pagebuttons\NewPageButton;
use dokuwiki\plugin\pagebuttons\NewFolderButton;
/**
* Class action_plugin_pagebuttons
*
* @package dokuwiki\plugin\pagebuttons
*/
class action_plugin_pagebuttons extends DokuWiki_Action_Plugin {
/**
* Register event handlers.
*
* @param Doku_Event_Handler $controller The plugin controller
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addjsinfo');
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addNewPageButton' );
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addNewFolderButton' );
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addDeleteButton' );
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'actionPage' );
}
/**
* Adds details to JSINFO
*
*/
function addjsinfo($event, $params){
global $JSINFO;
global $conf;
$JSINFO['plugin_pagebuttons'] = array(
'usePrompt' => $this->getConf('usePrompt'),
'useslash' => $conf['useslash'],
'start' => $conf['start']
);
}
/**
* Hook for MENU_ITEMS_ASSEMBLY event.
*
* Adds 'Delete' button to DokuWiki's PageMenu.
*
* @param Doku_Event $event
*/
public function addDeleteButton(Doku_Event $event) {
global $ID;
if (
$event->data['view'] !== 'page'
|| $this->getConf('hideDelete')
|| !$this->canDelete($ID)
) {
return;
}
array_splice($event->data['items'], -1, 0, array(new DeletePageButton($this->getLang('delete_menu_item'))));
}
/**
* Hook for MENU_ITEMS_ASSEMBLY event.
*
* Adds 'New Page' button to DokuWiki's PageMenu.
*
* @param Doku_Event $event
*/
public function addNewPageButton(Doku_Event $event) {
global $ID;
global $conf;
if (
$event->data['view'] !== 'page'
|| $this->getConf('hideNewPage')
|| !page_exists($ID)
|| ($this->getConf('onlyShowNewButtonsOnStart') && !(substr_compare($ID, ":".$conf['start'], -strlen(":".$conf['start'])) === 0))
) {
return;
}
array_splice($event->data['items'], -1, 0, array(new NewPageButton($this->getLang('newpage_menu_item'))));
}
/**
* Hook for MENU_ITEMS_ASSEMBLY event.
*
* Adds 'New Page' button to DokuWiki's PageMenu.
*
* @param Doku_Event $event
*/
public function addNewFolderButton(Doku_Event $event) {
global $ID;
global $conf;
if (
$event->data['view'] !== 'page'
|| $this->getConf('hideNewFolder')
|| !page_exists($ID)
|| ($this->getConf('onlyShowNewButtonsOnStart') && !(substr_compare($ID, ":".$conf['start'], -strlen(":".$conf['start'])) === 0))
) {
return;
}
array_splice($event->data['items'], -1, 0, array(new NewFolderButton($this->getLang('newfolder_menu_item'))));
}
/**
* Determines whether the Delete button should be shown.
*
* @param $id
* @return bool
*/
protected function canDelete($id) {
global $ACT;
return ($ACT == 'show' || empty($ACT))
&& page_exists($id)
&& auth_quickaclcheck($id) >= AUTH_EDIT
&& checklock($id) === false && !@file_exists(wikiLockFN($id));
}
/**
* Hook for ACTION_ACT_PREPROCESS event.
*
* Handles the plugin's custom page deletion action: deletes the page and
* redirects to page view ('show' action).
*
* @param Doku_Event $event
*/
public function actionPage(Doku_Event $event) {
global $ID, $INFO, $lang;
// Ignore other actions
if ($event->data != 'deletepagebutton' && $event->data != 'newfolderbutton' && $event->data != 'newpagebutton') {
return;
};
if(checkSecurityToken() && $INFO['exists']) {
if($event->data == 'deletepagebutton'){
// Save the page with empty contents to delete it
saveWikiText($ID, null, $lang['deleted']);
// Display confirmation message
msg($this->getLang('deleted_ok'), 1);
}
}
// Redirect to page view
$event->data = 'redirect';
}
}