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 ;
@@ -56,10 +65,11 @@ public function handle_init() {
5665 *
5766 * TODO: DEPRECATED JAN 2018
5867 *
59- * @param Doku_Event $event
68+ * @param Event $event
6069 */
61- public function handle_pagetools (Doku_Event $ event ) {
62- if ($ event ->data ['view ' ] != 'main ' ) return ;
70+ public function handle_pagetools (Event $ event )
71+ {
72+ if ($ event ->data ['view ' ] != 'main ' ) return ;
6373 if (!$ this ->getConf ('pagetools_integration ' )) {
6474 return ;
6575 }
@@ -68,35 +78,37 @@ public function handle_pagetools(Doku_Event $event) {
6878 $ offset = count ($ event ->data ['items ' ]) - 1 ;
6979 $ event ->data ['items ' ] =
7080 array_slice ($ event ->data ['items ' ], 0 , $ offset , true ) +
71- array ( 'plugin_move ' => $ newitem) +
81+ [ 'plugin_move ' => $ newitem] +
7282 array_slice ($ event ->data ['items ' ], $ offset , null , true );
7383 }
7484
7585 /**
7686 * Add 'rename' button to page tools, new SVG based mechanism
7787 *
78- * @param Doku_Event $event
88+ * @param Event $event
7989 */
80- public function addsvgbutton (Doku_Event $ event ) {
90+ public function addsvgbutton (Event $ event )
91+ {
8192 global $ INFO , $ JSINFO ;
82- if (
93+ if (
8394 $ event ->data ['view ' ] !== 'page ' ||
8495 !$ this ->getConf ('pagetools_integration ' ) ||
8596 empty ($ JSINFO ['move_renameokay ' ])
8697 ) {
8798 return ;
8899 }
89- if (!$ INFO ['exists ' ]) {
100+ if (!$ INFO ['exists ' ]) {
90101 return ;
91102 }
92- array_splice ($ event ->data ['items ' ], -1 , 0 , array ( new \ dokuwiki \ plugin \ move \ MenuItem ()) );
103+ array_splice ($ event ->data ['items ' ], -1 , 0 , [ new MenuItem ()] );
93104 }
94105
95106 /**
96107 * Rename a single page
97108 */
98- public function handle_ajax (Doku_Event $ event ) {
99- if ($ event ->data != 'plugin_move_rename ' ) return ;
109+ public function handle_ajax (Event $ event )
110+ {
111+ if ($ event ->data != 'plugin_move_rename ' ) return ;
100112 $ event ->preventDefault ();
101113 $ event ->stopPropagation ();
102114
@@ -113,26 +125,26 @@ public function handle_ajax(Doku_Event $event) {
113125
114126 header ('Content-Type: application/json ' );
115127
116- if ($ this ->renameOkay ($ src ) && $ MoveOperator ->movePage ($ src , $ dst )) {
128+ if ($ this ->renameOkay ($ src ) && $ MoveOperator ->movePage ($ src , $ dst )) {
117129 // all went well, redirect
118- echo $ JSON ->encode (array ( 'redirect_url ' => wl ($ dst , '' , true , '& ' )) );
130+ echo $ JSON ->encode ([ 'redirect_url ' => wl ($ dst , '' , true , '& ' )] );
119131 } else {
120- if (isset ($ MSG [0 ])) {
132+ if (isset ($ MSG [0 ])) {
121133 $ error = $ MSG [0 ]; // first error
122134 } else {
123135 $ error = $ this ->getLang ('cantrename ' );
124136 }
125- echo $ JSON ->encode (array ( 'error ' => $ error) );
137+ echo $ JSON ->encode ([ 'error ' => $ error] );
126138 }
127139 }
128140
129141 /**
130142 * Handle media renames in media manager
131143 *
132- * @param Doku_Event $event
144+ * @param Event $event
133145 * @return void
134146 */
135- public function handleAjaxMediaManager (Doku_Event $ event )
147+ public function handleAjaxMediaManager (Event $ event )
136148 {
137149 if ($ event ->data !== 'plugin_move_rename_mediamanager ' ) return ;
138150
@@ -191,17 +203,18 @@ public function handleAjaxMediaManager(Doku_Event $event)
191203 * @param $id
192204 * @return bool
193205 */
194- public function renameOkay ($ id ) {
206+ public function renameOkay ($ id )
207+ {
195208 global $ conf ;
196209 global $ ACT ;
197210 global $ USERINFO ;
198- if (!( $ ACT == 'show ' || empty ($ ACT ) )) return false ;
199- if (!page_exists ($ id )) return false ;
200- if (auth_quickaclcheck ($ id ) < AUTH_EDIT ) return false ;
201- if (checklock ($ id ) !== false || @file_exists (wikiLockFN ($ id ))) return false ;
202- if (!$ conf ['useacl ' ]) return true ;
203- if (!isset ($ _SERVER ['REMOTE_USER ' ])) return false ;
204- if (!auth_isMember ($ this ->getConf ('allowrename ' ), $ _SERVER ['REMOTE_USER ' ], (array ) $ USERINFO ['grps ' ])) return false ;
211+ if ( $ ACT != 'show ' && ! empty ($ ACT )) return false ;
212+ if (!page_exists ($ id )) return false ;
213+ if (auth_quickaclcheck ($ id ) < AUTH_EDIT ) return false ;
214+ if (checklock ($ id ) !== false || @file_exists (wikiLockFN ($ id ))) return false ;
215+ if (!$ conf ['useacl ' ]) return true ;
216+ if (!isset ($ _SERVER ['REMOTE_USER ' ])) return false ;
217+ if (!auth_isMember ($ this ->getConf ('allowrename ' ), $ _SERVER ['REMOTE_USER ' ], (array ) $ USERINFO ['grps ' ])) return false ;
205218
206219 return true ;
207220 }
@@ -212,10 +225,10 @@ public function renameOkay($id) {
212225 * Alternatively give anything the class "plugin_move_page" - it will automatically be hidden and shown and
213226 * trigger the page move dialog.
214227 */
215- public function tpl () {
228+ public function tpl ()
229+ {
216230 echo '<a href="" class="plugin_move_page"> ' ;
217231 echo $ this ->getLang ('renamepage ' );
218232 echo '</a> ' ;
219233 }
220-
221234}
0 commit comments