-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaction.php
106 lines (90 loc) · 2.75 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
<?php
/**
* Delete Page Button plugin
*
* @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\deletepagebutton\DeletePageButton;
/**
* Class action_plugin_deletepagebutton
*
* @package dokuwiki\plugin\deletepagebutton
*/
class action_plugin_deletepagebutton 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, 'addButton' );
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'deletePage' );
}
/**
* Hook for DOKUWIKI_STARTED event.
*
* Adds current template to $JSINFO
*/
public function addJsInfo() {
global $JSINFO, $conf;
$JSINFO['deletepagebutton_template'] = $conf['template'];
}
/**
* Hook for MENU_ITEMS_ASSEMBLY event.
*
* Adds 'Delete' button to DokuWiki's PageMenu.
*
* @param Doku_Event $event
*/
public function addButton(Doku_Event $event) {
global $ID;
if (
$event->data['view'] !== 'page'
|| !$this->canDelete($ID)
) {
return;
}
array_splice($event->data['items'], -1, 0, array(new DeletePageButton()));
}
/**
* 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 deletePage(Doku_Event $event) {
global $ID, $INFO, $lang;
// Ignore other actions
if ($event->data != 'deletepagebutton') {
return;
};
if(checkSecurityToken() && $INFO['exists']) {
// 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';
}
}