1
1
<?php
2
+
3
+ use dokuwiki \Extension \ActionPlugin ;
4
+ use dokuwiki \Extension \EventHandler ;
5
+ use dokuwiki \Extension \Event ;
6
+ use dokuwiki \plugin \move \MenuItem ;
7
+
2
8
/**
3
9
* Move Plugin Page Rename Functionality
4
10
*
5
11
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
12
* @author Andreas Gohr <[email protected] >
7
13
*/
14
+
8
15
// must be run within Dokuwiki
9
- if (!defined ('DOKU_INC ' )) die ();
16
+ if (!defined ('DOKU_INC ' )) die ();
10
17
11
18
/**
12
19
* Class action_plugin_move_rename
13
20
*/
14
- class action_plugin_move_rename extends DokuWiki_Action_Plugin {
15
-
21
+ class action_plugin_move_rename extends ActionPlugin
22
+ {
16
23
/**
17
24
* Register event handlers.
18
25
*
19
- * @param Doku_Event_Handler $controller The plugin controller
26
+ * @param EventHandler $controller The plugin controller
20
27
*/
21
- public function register (Doku_Event_Handler $ controller ) {
28
+ public function register (EventHandler $ controller )
29
+ {
22
30
$ controller ->register_hook ('DOKUWIKI_STARTED ' , 'AFTER ' , $ this , 'handle_init ' );
23
31
24
32
// TODO: DEPRECATED JAN 2018
25
33
$ controller ->register_hook ('TEMPLATE_PAGETOOLS_DISPLAY ' , 'BEFORE ' , $ this , 'handle_pagetools ' );
26
34
27
- $ controller ->register_hook ('MENU_ITEMS_ASSEMBLY ' , 'AFTER ' , $ this , 'addsvgbutton ' , array () );
35
+ $ controller ->register_hook ('MENU_ITEMS_ASSEMBLY ' , 'AFTER ' , $ this , 'addsvgbutton ' , [] );
28
36
$ controller ->register_hook ('AJAX_CALL_UNKNOWN ' , 'BEFORE ' , $ this , 'handle_ajax ' );
29
37
$ controller ->register_hook ('AJAX_CALL_UNKNOWN ' , 'BEFORE ' , $ this , 'handleAjaxMediaManager ' );
30
38
}
31
39
32
40
/**
33
41
* set JavaScript info if renaming of current page is possible
34
42
*/
35
- public function handle_init () {
43
+ public function handle_init ()
44
+ {
36
45
global $ JSINFO ;
37
46
global $ INFO ;
38
47
global $ INPUT ;
@@ -51,10 +60,11 @@ public function handle_init() {
51
60
*
52
61
* TODO: DEPRECATED JAN 2018
53
62
*
54
- * @param Doku_Event $event
63
+ * @param Event $event
55
64
*/
56
- public function handle_pagetools (Doku_Event $ event ) {
57
- if ($ event ->data ['view ' ] != 'main ' ) return ;
65
+ public function handle_pagetools (Event $ event )
66
+ {
67
+ if ($ event ->data ['view ' ] != 'main ' ) return ;
58
68
if (!$ this ->getConf ('pagetools_integration ' )) {
59
69
return ;
60
70
}
@@ -63,35 +73,37 @@ public function handle_pagetools(Doku_Event $event) {
63
73
$ offset = count ($ event ->data ['items ' ]) - 1 ;
64
74
$ event ->data ['items ' ] =
65
75
array_slice ($ event ->data ['items ' ], 0 , $ offset , true ) +
66
- array ( 'plugin_move ' => $ newitem) +
76
+ [ 'plugin_move ' => $ newitem] +
67
77
array_slice ($ event ->data ['items ' ], $ offset , null , true );
68
78
}
69
79
70
80
/**
71
81
* Add 'rename' button to page tools, new SVG based mechanism
72
82
*
73
- * @param Doku_Event $event
83
+ * @param Event $event
74
84
*/
75
- public function addsvgbutton (Doku_Event $ event ) {
85
+ public function addsvgbutton (Event $ event )
86
+ {
76
87
global $ INFO , $ JSINFO ;
77
- if (
88
+ if (
78
89
$ event ->data ['view ' ] !== 'page ' ||
79
90
!$ this ->getConf ('pagetools_integration ' ) ||
80
91
!$ JSINFO ['move_renameokay ' ]
81
92
) {
82
93
return ;
83
94
}
84
- if (!$ INFO ['exists ' ]) {
95
+ if (!$ INFO ['exists ' ]) {
85
96
return ;
86
97
}
87
- array_splice ($ event ->data ['items ' ], -1 , 0 , array ( new \ dokuwiki \ plugin \ move \ MenuItem ()) );
98
+ array_splice ($ event ->data ['items ' ], -1 , 0 , [ new MenuItem ()] );
88
99
}
89
100
90
101
/**
91
102
* Rename a single page
92
103
*/
93
- public function handle_ajax (Doku_Event $ event ) {
94
- if ($ event ->data != 'plugin_move_rename ' ) return ;
104
+ public function handle_ajax (Event $ event )
105
+ {
106
+ if ($ event ->data != 'plugin_move_rename ' ) return ;
95
107
$ event ->preventDefault ();
96
108
$ event ->stopPropagation ();
97
109
@@ -108,26 +120,26 @@ public function handle_ajax(Doku_Event $event) {
108
120
109
121
header ('Content-Type: application/json ' );
110
122
111
- if ($ this ->renameOkay ($ src ) && $ MoveOperator ->movePage ($ src , $ dst )) {
123
+ if ($ this ->renameOkay ($ src ) && $ MoveOperator ->movePage ($ src , $ dst )) {
112
124
// all went well, redirect
113
- echo $ JSON ->encode (array ( 'redirect_url ' => wl ($ dst , '' , true , '& ' )) );
125
+ echo $ JSON ->encode ([ 'redirect_url ' => wl ($ dst , '' , true , '& ' )] );
114
126
} else {
115
- if (isset ($ MSG [0 ])) {
127
+ if (isset ($ MSG [0 ])) {
116
128
$ error = $ MSG [0 ]; // first error
117
129
} else {
118
130
$ error = $ this ->getLang ('cantrename ' );
119
131
}
120
- echo $ JSON ->encode (array ( 'error ' => $ error) );
132
+ echo $ JSON ->encode ([ 'error ' => $ error] );
121
133
}
122
134
}
123
135
124
136
/**
125
137
* Handle media renames in media manager
126
138
*
127
- * @param Doku_Event $event
139
+ * @param Event $event
128
140
* @return void
129
141
*/
130
- public function handleAjaxMediaManager (Doku_Event $ event )
142
+ public function handleAjaxMediaManager (Event $ event )
131
143
{
132
144
if ($ event ->data !== 'plugin_move_rename_mediamanager ' ) return ;
133
145
@@ -186,17 +198,18 @@ public function handleAjaxMediaManager(Doku_Event $event)
186
198
* @param $id
187
199
* @return bool
188
200
*/
189
- public function renameOkay ($ id ) {
201
+ public function renameOkay ($ id )
202
+ {
190
203
global $ conf ;
191
204
global $ ACT ;
192
205
global $ USERINFO ;
193
- if (!( $ ACT == 'show ' || empty ($ ACT ) )) return false ;
194
- if (!page_exists ($ id )) return false ;
195
- if (auth_quickaclcheck ($ id ) < AUTH_EDIT ) return false ;
196
- if (checklock ($ id ) !== false || @file_exists (wikiLockFN ($ id ))) return false ;
197
- if (!$ conf ['useacl ' ]) return true ;
198
- if (!isset ($ _SERVER ['REMOTE_USER ' ])) return false ;
199
- if (!auth_isMember ($ this ->getConf ('allowrename ' ), $ _SERVER ['REMOTE_USER ' ], (array ) $ USERINFO ['grps ' ])) return false ;
206
+ if ( $ ACT != 'show ' && ! empty ($ ACT )) return false ;
207
+ if (!page_exists ($ id )) return false ;
208
+ if (auth_quickaclcheck ($ id ) < AUTH_EDIT ) return false ;
209
+ if (checklock ($ id ) !== false || @file_exists (wikiLockFN ($ id ))) return false ;
210
+ if (!$ conf ['useacl ' ]) return true ;
211
+ if (!isset ($ _SERVER ['REMOTE_USER ' ])) return false ;
212
+ if (!auth_isMember ($ this ->getConf ('allowrename ' ), $ _SERVER ['REMOTE_USER ' ], (array ) $ USERINFO ['grps ' ])) return false ;
200
213
201
214
return true ;
202
215
}
@@ -207,10 +220,10 @@ public function renameOkay($id) {
207
220
* Alternatively give anything the class "plugin_move_page" - it will automatically be hidden and shown and
208
221
* trigger the page move dialog.
209
222
*/
210
- public function tpl () {
223
+ public function tpl ()
224
+ {
211
225
echo '<a href="" class="plugin_move_page"> ' ;
212
226
echo $ this ->getLang ('renamepage ' );
213
227
echo '</a> ' ;
214
228
}
215
-
216
229
}
0 commit comments