11<?php
2+
3+ use dokuwiki \Extension \ActionPlugin ;
4+ use dokuwiki \Extension \EventHandler ;
5+ use dokuwiki \Extension \Event ;
6+ use dokuwiki \plugin \move \MenuItem ;
7+
28/**
39 * Move Plugin Page Rename Functionality
410 *
511 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
612 * @author Andreas Gohr <[email protected] > 713 */
14+
815// must be run within Dokuwiki
9- if (!defined ('DOKU_INC ' )) die ();
16+ if (!defined ('DOKU_INC ' )) die ();
1017
1118/**
1219 * Class action_plugin_move_rename
1320 */
14- class action_plugin_move_rename extends DokuWiki_Action_Plugin {
15-
21+ class action_plugin_move_rename extends ActionPlugin
22+ {
1623 /**
1724 * Register event handlers.
1825 *
19- * @param Doku_Event_Handler $controller The plugin controller
26+ * @param EventHandler $controller The plugin controller
2027 */
21- public function register (Doku_Event_Handler $ controller ) {
28+ public function register (EventHandler $ controller )
29+ {
2230 $ controller ->register_hook ('DOKUWIKI_STARTED ' , 'AFTER ' , $ this , 'handle_init ' );
2331
2432 // TODO: DEPRECATED JAN 2018
2533 $ controller ->register_hook ('TEMPLATE_PAGETOOLS_DISPLAY ' , 'BEFORE ' , $ this , 'handle_pagetools ' );
2634
27- $ controller ->register_hook ('MENU_ITEMS_ASSEMBLY ' , 'AFTER ' , $ this , 'addsvgbutton ' , array () );
35+ $ controller ->register_hook ('MENU_ITEMS_ASSEMBLY ' , 'AFTER ' , $ this , 'addsvgbutton ' , [] );
2836 $ controller ->register_hook ('AJAX_CALL_UNKNOWN ' , 'BEFORE ' , $ this , 'handle_ajax ' );
2937 $ controller ->register_hook ('AJAX_CALL_UNKNOWN ' , 'BEFORE ' , $ this , 'handleAjaxMediaManager ' );
3038 }
3139
3240 /**
3341 * set JavaScript info if renaming of current page is possible
3442 */
35- public function handle_init () {
43+ public function handle_init ()
44+ {
3645 global $ JSINFO ;
3746 global $ INFO ;
3847 global $ INPUT ;
@@ -51,10 +60,11 @@ public function handle_init() {
5160 *
5261 * TODO: DEPRECATED JAN 2018
5362 *
54- * @param Doku_Event $event
63+ * @param Event $event
5564 */
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 ;
5868 if (!$ this ->getConf ('pagetools_integration ' )) {
5969 return ;
6070 }
@@ -63,35 +73,37 @@ public function handle_pagetools(Doku_Event $event) {
6373 $ offset = count ($ event ->data ['items ' ]) - 1 ;
6474 $ event ->data ['items ' ] =
6575 array_slice ($ event ->data ['items ' ], 0 , $ offset , true ) +
66- array ( 'plugin_move ' => $ newitem) +
76+ [ 'plugin_move ' => $ newitem] +
6777 array_slice ($ event ->data ['items ' ], $ offset , null , true );
6878 }
6979
7080 /**
7181 * Add 'rename' button to page tools, new SVG based mechanism
7282 *
73- * @param Doku_Event $event
83+ * @param Event $event
7484 */
75- public function addsvgbutton (Doku_Event $ event ) {
85+ public function addsvgbutton (Event $ event )
86+ {
7687 global $ INFO , $ JSINFO ;
77- if (
88+ if (
7889 $ event ->data ['view ' ] !== 'page ' ||
7990 !$ this ->getConf ('pagetools_integration ' ) ||
8091 !$ JSINFO ['move_renameokay ' ]
8192 ) {
8293 return ;
8394 }
84- if (!$ INFO ['exists ' ]) {
95+ if (!$ INFO ['exists ' ]) {
8596 return ;
8697 }
87- array_splice ($ event ->data ['items ' ], -1 , 0 , array ( new \ dokuwiki \ plugin \ move \ MenuItem ()) );
98+ array_splice ($ event ->data ['items ' ], -1 , 0 , [ new MenuItem ()] );
8899 }
89100
90101 /**
91102 * Rename a single page
92103 */
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 ;
95107 $ event ->preventDefault ();
96108 $ event ->stopPropagation ();
97109
@@ -108,26 +120,26 @@ public function handle_ajax(Doku_Event $event) {
108120
109121 header ('Content-Type: application/json ' );
110122
111- if ($ this ->renameOkay ($ src ) && $ MoveOperator ->movePage ($ src , $ dst )) {
123+ if ($ this ->renameOkay ($ src ) && $ MoveOperator ->movePage ($ src , $ dst )) {
112124 // all went well, redirect
113- echo $ JSON ->encode (array ( 'redirect_url ' => wl ($ dst , '' , true , '& ' )) );
125+ echo $ JSON ->encode ([ 'redirect_url ' => wl ($ dst , '' , true , '& ' )] );
114126 } else {
115- if (isset ($ MSG [0 ])) {
127+ if (isset ($ MSG [0 ])) {
116128 $ error = $ MSG [0 ]; // first error
117129 } else {
118130 $ error = $ this ->getLang ('cantrename ' );
119131 }
120- echo $ JSON ->encode (array ( 'error ' => $ error) );
132+ echo $ JSON ->encode ([ 'error ' => $ error] );
121133 }
122134 }
123135
124136 /**
125137 * Handle media renames in media manager
126138 *
127- * @param Doku_Event $event
139+ * @param Event $event
128140 * @return void
129141 */
130- public function handleAjaxMediaManager (Doku_Event $ event )
142+ public function handleAjaxMediaManager (Event $ event )
131143 {
132144 if ($ event ->data !== 'plugin_move_rename_mediamanager ' ) return ;
133145
@@ -186,17 +198,18 @@ public function handleAjaxMediaManager(Doku_Event $event)
186198 * @param $id
187199 * @return bool
188200 */
189- public function renameOkay ($ id ) {
201+ public function renameOkay ($ id )
202+ {
190203 global $ conf ;
191204 global $ ACT ;
192205 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 ;
200213
201214 return true ;
202215 }
@@ -207,10 +220,10 @@ public function renameOkay($id) {
207220 * Alternatively give anything the class "plugin_move_page" - it will automatically be hidden and shown and
208221 * trigger the page move dialog.
209222 */
210- public function tpl () {
223+ public function tpl ()
224+ {
211225 echo '<a href="" class="plugin_move_page"> ' ;
212226 echo $ this ->getLang ('renamepage ' );
213227 echo '</a> ' ;
214228 }
215-
216229}
0 commit comments