diff --git a/MenuItem.php b/MenuItem.php index 9bad087f..9055e730 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -1,6 +1,9 @@ getLang('renamepage'); } diff --git a/action/progress.php b/action/progress.php index 6b007826..ea1a98b5 100644 --- a/action/progress.php +++ b/action/progress.php @@ -1,66 +1,70 @@ */ + // must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); +if (!defined('DOKU_INC')) die(); /** * Class action_plugin_move_progress */ -class action_plugin_move_progress extends DokuWiki_Action_Plugin { - +class action_plugin_move_progress extends ActionPlugin +{ /** * Register event handlers. * - * @param Doku_Event_Handler $controller The plugin controller + * @param EventHandler $controller The plugin controller */ - public function register(Doku_Event_Handler $controller) { + public function register(EventHandler $controller) + { $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); } /** * Step up * - * @param Doku_Event $event + * @param Event $event */ - public function handle_ajax(Doku_Event $event) { - if($event->data != 'plugin_move_progress') return; + public function handle_ajax(Event $event) + { + if ($event->data != 'plugin_move_progress') return; $event->preventDefault(); $event->stopPropagation(); global $INPUT; global $USERINFO; - if(!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { + if (!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { http_status(403); exit; } - $return = array( - 'error' => '', - 'complete' => false, - 'progress' => 0 - ); + $return = ['error' => '', 'complete' => false, 'progress' => 0]; /** @var helper_plugin_move_plan $plan */ $plan = plugin_load('helper', 'move_plan'); - if(!$plan->isCommited()) { + if (!$plan->isCommited()) { // There is no plan. Something went wrong $return['complete'] = true; } else { $todo = $plan->nextStep($INPUT->bool('skip')); $return['progress'] = $plan->getProgress(); $return['error'] = $plan->getLastError(); - if($todo === 0) $return['complete'] = true; + if ($todo === 0) $return['complete'] = true; } $json = new JSON(); header('Content-Type: application/json'); echo $json->encode($return); } -} \ No newline at end of file +} diff --git a/action/rename.php b/action/rename.php index ca7cb0d5..0906394a 100644 --- a/action/rename.php +++ b/action/rename.php @@ -1,30 +1,38 @@ */ + // must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); +if (!defined('DOKU_INC')) die(); /** * Class action_plugin_move_rename */ -class action_plugin_move_rename extends DokuWiki_Action_Plugin { - +class action_plugin_move_rename extends ActionPlugin +{ /** * Register event handlers. * - * @param Doku_Event_Handler $controller The plugin controller + * @param EventHandler $controller The plugin controller */ - public function register(Doku_Event_Handler $controller) { + public function register(EventHandler $controller) + { $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_init'); // TODO: DEPRECATED JAN 2018 $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'handle_pagetools'); - $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', array()); + $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', []); $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjaxMediaManager'); } @@ -32,7 +40,8 @@ public function register(Doku_Event_Handler $controller) { /** * set JavaScript info if renaming of current page is possible */ - public function handle_init() { + public function handle_init() + { global $JSINFO; global $INFO; global $INPUT; @@ -56,10 +65,11 @@ public function handle_init() { * * TODO: DEPRECATED JAN 2018 * - * @param Doku_Event $event + * @param Event $event */ - public function handle_pagetools(Doku_Event $event) { - if($event->data['view'] != 'main') return; + public function handle_pagetools(Event $event) + { + if ($event->data['view'] != 'main') return; if (!$this->getConf('pagetools_integration')) { return; } @@ -68,35 +78,37 @@ public function handle_pagetools(Doku_Event $event) { $offset = count($event->data['items']) - 1; $event->data['items'] = array_slice($event->data['items'], 0, $offset, true) + - array('plugin_move' => $newitem) + + ['plugin_move' => $newitem] + array_slice($event->data['items'], $offset, null, true); } /** * Add 'rename' button to page tools, new SVG based mechanism * - * @param Doku_Event $event + * @param Event $event */ - public function addsvgbutton(Doku_Event $event) { + public function addsvgbutton(Event $event) + { global $INFO, $JSINFO; - if( + if ( $event->data['view'] !== 'page' || !$this->getConf('pagetools_integration') || empty($JSINFO['move_renameokay']) ) { return; } - if(!$INFO['exists']) { + if (!$INFO['exists']) { return; } - array_splice($event->data['items'], -1, 0, array(new \dokuwiki\plugin\move\MenuItem())); + array_splice($event->data['items'], -1, 0, [new MenuItem()]); } /** * Rename a single page */ - public function handle_ajax(Doku_Event $event) { - if($event->data != 'plugin_move_rename') return; + public function handle_ajax(Event $event) + { + if ($event->data != 'plugin_move_rename') return; $event->preventDefault(); $event->stopPropagation(); @@ -113,26 +125,26 @@ public function handle_ajax(Doku_Event $event) { header('Content-Type: application/json'); - if($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) { + if ($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) { // all went well, redirect - echo $JSON->encode(array('redirect_url' => wl($dst, '', true, '&'))); + echo $JSON->encode(['redirect_url' => wl($dst, '', true, '&')]); } else { - if(isset($MSG[0])) { + if (isset($MSG[0])) { $error = $MSG[0]; // first error } else { $error = $this->getLang('cantrename'); } - echo $JSON->encode(array('error' => $error)); + echo $JSON->encode(['error' => $error]); } } /** * Handle media renames in media manager * - * @param Doku_Event $event + * @param Event $event * @return void */ - public function handleAjaxMediaManager(Doku_Event $event) + public function handleAjaxMediaManager(Event $event) { if ($event->data !== 'plugin_move_rename_mediamanager') return; @@ -191,17 +203,18 @@ public function handleAjaxMediaManager(Doku_Event $event) * @param $id * @return bool */ - public function renameOkay($id) { + public function renameOkay($id) + { global $conf; global $ACT; global $USERINFO; - if(!($ACT == 'show' || empty($ACT))) return false; - if(!page_exists($id)) return false; - if(auth_quickaclcheck($id) < AUTH_EDIT) return false; - if(checklock($id) !== false || @file_exists(wikiLockFN($id))) return false; - if(!$conf['useacl']) return true; - if(!isset($_SERVER['REMOTE_USER'])) return false; - if(!auth_isMember($this->getConf('allowrename'), $_SERVER['REMOTE_USER'], (array) $USERINFO['grps'])) return false; + if ($ACT != 'show' && !empty($ACT)) return false; + if (!page_exists($id)) return false; + if (auth_quickaclcheck($id) < AUTH_EDIT) return false; + if (checklock($id) !== false || @file_exists(wikiLockFN($id))) return false; + if (!$conf['useacl']) return true; + if (!isset($_SERVER['REMOTE_USER'])) return false; + if (!auth_isMember($this->getConf('allowrename'), $_SERVER['REMOTE_USER'], (array) $USERINFO['grps'])) return false; return true; } @@ -212,10 +225,10 @@ public function renameOkay($id) { * Alternatively give anything the class "plugin_move_page" - it will automatically be hidden and shown and * trigger the page move dialog. */ - public function tpl() { + public function tpl() + { echo ''; echo $this->getLang('renamepage'); echo ''; } - } diff --git a/action/rewrite.php b/action/rewrite.php index 10979507..1b73ba9c 100644 --- a/action/rewrite.php +++ b/action/rewrite.php @@ -1,63 +1,72 @@ */ + // must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); +if (!defined('DOKU_INC')) die(); /** * Class action_plugin_move_rewrite */ -class action_plugin_move_rewrite extends DokuWiki_Action_Plugin { - +class action_plugin_move_rewrite extends ActionPlugin +{ /** * Register event handlers. * - * @param Doku_Event_Handler $controller The plugin controller + * @param EventHandler $controller The plugin controller */ - public function register(Doku_Event_Handler $controller) { - $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_read', array()); - $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_cache', array()); + public function register(EventHandler $controller) + { + $controller->register_hook('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_read', []); + $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_cache', []); } /** * Rewrite pages when they are read and they need to be updated. * - * @param Doku_Event $event The event object + * @param Event $event The event object * @param mixed $param Optional parameters (not used) */ - function handle_read(Doku_Event $event, $param) { + public function handle_read(Event $event, $param) + { global $ACT, $conf; - static $stack = array(); + static $stack = []; // handle only reads of the current revision - if($event->data[3]) return; + if ($event->data[3]) return; // only rewrite if not in move already $save = true; - if(helper_plugin_move_rewrite::isLocked()) { + if (helper_plugin_move_rewrite::isLocked()) { $save = false; } $id = $event->data[2]; - if($event->data[1]) $id = $event->data[1] . ':' . $id; + if ($event->data[1]) $id = $event->data[1] . ':' . $id; - if(!$id) { + if (!$id) { // try to reconstruct the id from the filename $path = $event->data[0][0]; - if(strpos($path, $conf['datadir']) === 0) { + if (strpos($path, (string) $conf['datadir']) === 0) { $path = substr($path, strlen($conf['datadir']) + 1); $id = pathID($path); } } - if(isset($stack[$id])) return; + if (isset($stack[$id])) return; // Don't change the page when the user is currently changing the page content or the page is locked - $forbidden_actions = array('save', 'preview', 'recover', 'revert'); - if((isset($ACT) && ( + $forbidden_actions = ['save', 'preview', 'recover', 'revert']; + if ( + (isset($ACT) && ( in_array($ACT, $forbidden_actions) || (is_array($ACT) && in_array(key($ACT), $forbidden_actions) ))) // checklock checks if the page lock hasn't expired and the page hasn't been locked by another user @@ -68,7 +77,7 @@ function handle_read(Doku_Event $event, $param) { /** @var helper_plugin_move_rewrite $helper */ $helper = plugin_load('helper', 'move_rewrite', true); - if(!is_null($helper)) { + if (!is_null($helper)) { $stack[$id] = true; $event->result = $helper->rewritePage($id, $event->result, $save); unset($stack[$id]); @@ -78,30 +87,31 @@ function handle_read(Doku_Event $event, $param) { /** * Handle the cache events, it looks if a page needs to be rewritten so it can expire the cache of the page * - * @param Doku_Event $event The even object + * @param Event $event The even object * @param mixed $param Optional parameters (not used) */ - function handle_cache(Doku_Event $event, $param) { + public function handle_cache(Event $event, $param) + { global $conf; /** @var $cache cache_parser */ $cache = $event->data; $id = $cache->page; - if(!$id) { + if (!$id) { // try to reconstruct the id from the filename $path = $cache->file; - if(strpos($path, $conf['datadir']) === 0) { + if (strpos($path, (string) $conf['datadir']) === 0) { $path = substr($path, strlen($conf['datadir']) + 1); $id = pathID($path); } } - if($id) { + if ($id) { /** @var helper_plugin_move_rewrite $helper */ $helper = $this->loadHelper('move_rewrite'); - if(!is_null($helper)) { + if (!is_null($helper)) { $meta = $helper->getMoveMeta($id); - if($meta && ($meta['pages'] || $meta['media'])) { + if ($meta && ($meta['pages'] || $meta['media'])) { $file = wikiFN($id, '', false); - if(is_writable($file)) + if (is_writable($file)) $cache->depends['purge'] = true; else // FIXME: print error here or fail silently? msg('Error: Page ' . hsc($id) . ' needs to be rewritten because of page renames but is not writable.', -1); diff --git a/action/tree.php b/action/tree.php index 644c9789..b6ee484e 100644 --- a/action/tree.php +++ b/action/tree.php @@ -1,42 +1,50 @@ */ + // must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); +if (!defined('DOKU_INC')) die(); /** * Class action_plugin_move_rewrite */ -class action_plugin_move_tree extends DokuWiki_Action_Plugin { - +class action_plugin_move_tree extends ActionPlugin +{ /** * Register event handlers. * - * @param Doku_Event_Handler $controller The plugin controller + * @param EventHandler $controller The plugin controller */ - public function register(Doku_Event_Handler $controller) { + public function register(EventHandler $controller) + { $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call'); } /** * Render a subtree * - * @param Doku_Event $event + * @param Event $event * @param $params */ - public function handle_ajax_call(Doku_Event $event, $params) { - if($event->data != 'plugin_move_tree') return; + public function handle_ajax_call(Event $event, $params) + { + if ($event->data != 'plugin_move_tree') return; $event->preventDefault(); $event->stopPropagation(); global $INPUT; global $USERINFO; - if(!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { + if (!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { http_status(403); exit; } @@ -45,7 +53,7 @@ public function handle_ajax_call(Doku_Event $event, $params) { $plugin = plugin_load('admin', 'move_tree'); $ns = cleanID($INPUT->str('ns')); - if($INPUT->bool('is_media')) { + if ($INPUT->bool('is_media')) { $type = admin_plugin_move_tree::TYPE_MEDIA; } else { $type = admin_plugin_move_tree::TYPE_PAGES; @@ -54,10 +62,10 @@ public function handle_ajax_call(Doku_Event $event, $params) { $data = $plugin->tree($type, $ns, $ns); echo html_buildlist( - $data, 'tree_list', - array($plugin, 'html_list'), - array($plugin, 'html_li') + $data, + 'tree_list', + [$plugin, 'html_list'], + [$plugin, 'html_li'] ); } - -} \ No newline at end of file +} diff --git a/admin/main.php b/admin/main.php index 87a1b0d2..c3c28bcc 100644 --- a/admin/main.php +++ b/admin/main.php @@ -1,4 +1,7 @@ plan = plugin_load('helper', 'move_plan'); } @@ -26,9 +30,10 @@ public function __construct() { * @param $language * @return string */ - public function getMenuText($language) { + public function getMenuText($language) + { $label = $this->getLang('menu'); - if($this->plan->isCommited()) $label .= ' '.$this->getLang('inprogress'); + if ($this->plan->isCommited()) $label .= ' ' . $this->getLang('inprogress'); return $label; } @@ -38,7 +43,8 @@ public function getMenuText($language) { * * @return int The sort number */ - function getMenuSort() { + public function getMenuSort() + { return 1011; } @@ -47,23 +53,25 @@ function getMenuSort() { * * @return bool false */ - function forAdminOnly() { + public function forAdminOnly() + { return false; } /** * Handle the input */ - function handle() { + public function handle() + { global $INPUT; // create a new plan if possible and sufficient data was given $this->createPlanFromInput(); // handle workflow button presses - if($this->plan->isCommited()) { + if ($this->plan->isCommited()) { helper_plugin_move_rewrite::addLock(); //todo: right place? - switch($INPUT->str('ctl')) { + switch ($INPUT->str('ctl')) { case 'continue': $this->plan->nextStep(); break; @@ -80,9 +88,10 @@ function handle() { /** * Display the interface */ - function html() { + public function html() + { // decide what to do based on the plan's state - if($this->plan->isCommited()) { + if ($this->plan->isCommited()) { $this->GUI_progress(); } else { // display form @@ -95,32 +104,33 @@ function html() { * * @return bool */ - protected function createPlanFromInput() { + protected function createPlanFromInput() + { global $INPUT; global $ID; - if($this->plan->isCommited()) return false; + if ($this->plan->isCommited()) return false; $this->plan->setOption('autoskip', $INPUT->bool('autoskip')); $this->plan->setOption('autorewrite', $INPUT->bool('autorewrite')); - if($ID && $INPUT->has('dst')) { + if ($ID && $INPUT->has('dst')) { $dst = trim($INPUT->str('dst')); - if($dst == '') { + if ($dst == '') { msg($this->getLang('nodst'), -1); return false; } // input came from form - if($INPUT->str('class') == 'namespace') { + if ($INPUT->str('class') == 'namespace') { $src = getNS($ID); - if($INPUT->str('type') == 'both') { + if ($INPUT->str('type') == 'both') { $this->plan->addPageNamespaceMove($src, $dst); $this->plan->addMediaNamespaceMove($src, $dst); - } else if($INPUT->str('type') == 'page') { + } elseif ($INPUT->str('type') == 'page') { $this->plan->addPageNamespaceMove($src, $dst); - } else if($INPUT->str('type') == 'media') { + } elseif ($INPUT->str('type') == 'media') { $this->plan->addMediaNamespaceMove($src, $dst); } } else { @@ -128,22 +138,22 @@ protected function createPlanFromInput() { } $this->plan->commit(); return true; - } elseif($INPUT->has('json')) { + } elseif ($INPUT->has('json')) { // input came via JSON from tree manager $json = new JSON(JSON_LOOSE_TYPE); $data = $json->decode($INPUT->str('json')); - foreach((array) $data as $entry) { - if($entry['class'] == 'ns') { - if($entry['type'] == 'page') { + foreach ((array) $data as $entry) { + if ($entry['class'] == 'ns') { + if ($entry['type'] == 'page') { $this->plan->addPageNamespaceMove($entry['src'], $entry['dst']); - } elseif($entry['type'] == 'media') { + } elseif ($entry['type'] == 'media') { $this->plan->addMediaNamespaceMove($entry['src'], $entry['dst']); } - } elseif($entry['class'] == 'doc') { - if($entry['type'] == 'page') { + } elseif ($entry['class'] == 'doc') { + if ($entry['type'] == 'page') { $this->plan->addPageMove($entry['src'], $entry['dst']); - } elseif($entry['type'] == 'media') { + } elseif ($entry['type'] == 'media') { $this->plan->addMediaMove($entry['src'], $entry['dst']); } } @@ -159,30 +169,31 @@ protected function createPlanFromInput() { /** * Display the simple move form */ - protected function GUI_simpleForm() { + protected function GUI_simpleForm() + { global $ID; echo $this->locale_xhtml('move'); - $treelink = wl($ID, array('do'=>'admin', 'page'=>'move_tree')); + $treelink = wl($ID, ['do' => 'admin', 'page' => 'move_tree']); echo '
'; printf($this->getLang('treelink'), $treelink); echo '
'; - $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'plugin_move_form')); + $form = new Doku_Form(['action' => wl($ID), 'method' => 'post', 'class' => 'plugin_move_form']); $form->addHidden('page', 'move_main'); $form->addHidden('id', $ID); $form->startFieldset($this->getLang('legend')); - $form->addElement(form_makeRadioField('class', 'page', $this->getLang('movepage') . '' . $ID . '
', '', 'block radio click-page', array('checked' => 'checked')));
+ $form->addElement(form_makeRadioField('class', 'page', $this->getLang('movepage') . ' ' . $ID . '
', '', 'block radio click-page', ['checked' => 'checked']));
$form->addElement(form_makeRadioField('class', 'namespace', $this->getLang('movens') . ' ' . getNS($ID) . '
', '', 'block radio click-ns'));
$form->addElement(form_makeTextField('dst', $ID, $this->getLang('dst'), '', 'block indent'));
- $form->addElement(form_makeMenuField('type', array('pages' => $this->getLang('move_pages'), 'media' => $this->getLang('move_media'), 'both' => $this->getLang('move_media_and_pages')), 'both', $this->getLang('content_to_move'), '', 'block indent select'));
+ $form->addElement(form_makeMenuField('type', ['pages' => $this->getLang('move_pages'), 'media' => $this->getLang('move_media'), 'both' => $this->getLang('move_media_and_pages')], 'both', $this->getLang('content_to_move'), '', 'block indent select'));
- $form->addElement(form_makeCheckboxField('autoskip', '1', $this->getLang('autoskip'), '', 'block', ($this->getConf('autoskip') ? array('checked' => 'checked') : array())));
- $form->addElement(form_makeCheckboxField('autorewrite', '1', $this->getLang('autorewrite'), '', 'block', ($this->getConf('autorewrite') ? array('checked' => 'checked') : array())));
+ $form->addElement(form_makeCheckboxField('autoskip', '1', $this->getLang('autoskip'), '', 'block', ($this->getConf('autoskip') ? ['checked' => 'checked'] : [])));
+ $form->addElement(form_makeCheckboxField('autorewrite', '1', $this->getLang('autorewrite'), '', 'block', ($this->getConf('autorewrite') ? ['checked' => 'checked'] : [])));
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('btn_start')));
$form->endFieldset();
@@ -192,14 +203,15 @@ protected function GUI_simpleForm() {
/**
* Display the GUI while the move progresses
*/
- protected function GUI_progress() {
+ protected function GUI_progress()
+ {
echo ''; echo '' . $this->getLang('intro') . ' '; @@ -207,13 +219,12 @@ protected function GUI_progress() { echo '
'; echo $this->plan->previewHTML(); echo '