diff --git a/_test/namespace_move.test.php b/_test/namespace_move.test.php new file mode 100644 index 0000000..d6d51d1 --- /dev/null +++ b/_test/namespace_move.test.php @@ -0,0 +1,40 @@ +pluginsEnabled[] = 'pagemove'; + parent::setUp(); + } + + public function test_move_wiki_namespace() { + global $AUTH_ACL; + + $AUTH_ACL[] = "wiki:*\t@ALL\t16"; + + idx_addPage('wiki:dokuwiki'); + idx_addPage('wiki:syntax'); + + /** @var helper_plugin_pagemove $pagemove */ + $pagemove = plugin_load('helper', 'pagemove'); + $opts = array( + 'ns' => 'wiki', + 'newns' => 'foo', + 'media' => true + ); + + $this->assertSame(3, $pagemove->start_namespace_move($opts)); + $this->assertSame(1, $pagemove->continue_namespace_move()); + $this->assertSame(0, $pagemove->continue_namespace_move()); + + $this->assertFileExists(wikiFN('foo:dokuwiki')); + $this->assertFileNotExists(wikiFN('wiki:syntax')); + $this->assertFileExists(mediaFN('foo:dokuwiki-128.png')); + } +} diff --git a/action.php b/action.php index 3033301..09ae870 100644 --- a/action.php +++ b/action.php @@ -22,6 +22,7 @@ public function register($controller) { $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_cache', array()); $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'handle_index_version'); $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'index_media_use'); + $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call'); } /** @@ -151,4 +152,71 @@ private function get_media_references_from_instructions($instructions, &$media_r } } } + + /** + * Handle the plugin_pagemove_ns_continue ajax call + * + * @param Doku_Event $event The event that is handled + * @param array $params Optional parameters (unused) + */ + public function handle_ajax_call(Doku_Event $event, $params) { + if ($event->data == 'plugin_pagemove_ns_continue') { + $event->preventDefault(); + $event->stopPropagation(); + + /** @var helper_plugin_pagemove $helper */ + $helper = $this->loadHelper('pagemove', false); + $opts = $helper->get_namespace_move_opts(); + $id = cleanID((string)$_POST['id']); + $skip = (int)$_POST['skip']; + if ($opts !== false) { + if ($skip) { + $helper->skip_namespace_move_item(); + } + $remaining = $helper->continue_namespace_move(); + $newid = $helper->getNewID($id, $opts['ns'], $opts['newns']); + + $result = array(); + $result['remaining'] = $remaining; + $result['pages'] = $opts['num_pages']; + $result['media'] = $opts['num_media']; + $result['redirect_url'] = wl($newid, '', true); + ob_start(); + html_msgarea(); + if ($remaining === false) { + $form = new Doku_Form(array('action' => wl($id), 'method' => 'post', 'class' => 'pagemove__nsform pagemove__nscontinue')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $id); + $form->addHidden('continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_tryagain'))); + $form->printForm(); + $form = new Doku_Form(array('action' => wl($id), 'method' => 'post', 'class' => 'pagemove__nsform')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $id); + $form->addHidden('abort_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_abort'))); + $form->printForm(); + $form = new Doku_Form(array('action' => wl($id), 'method' => 'post', 'class' => 'pagemove__nsform pagemove__nsskip')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $id); + $form->addHidden('skip_continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_skip'))); + $form->printForm(); + ptln('
'.sprintf($this->getLang('pm_ns_move_error'), $opts['ns'], $opts['newns']).'
'); + } else { + ptln(''.sprintf($this->getLang('pm_ns_move_continued'), $opts['ns'], $opts['newns'], $remaining).'
'); + } + $result['html'] = ob_get_clean(); + } else { + $result = array(); + $result['remaining'] = 0; + $result['pages'] = 0; + $result['media'] = 0; + $result['redirect_url'] = wl('', '', true); + $result['html'] = ''; + } + $json = new JSON(); + echo $json->encode($result); + } + } } \ No newline at end of file diff --git a/admin.php b/admin.php index 07b41bd..f6a723e 100644 --- a/admin.php +++ b/admin.php @@ -16,6 +16,7 @@ class admin_plugin_pagemove extends DokuWiki_Admin_Plugin { var $opts = array(); + private $ns_opts = false; /** * Get the sort number that defines the position in the admin menu. @@ -62,9 +63,71 @@ function getMenuText() { * @author Gary Owen'); + ptln(sprintf($this->getLang('pm_ns_move_started'), hsc($this->ns_opts['ns']), hsc($this->ns_opts['newns']), $this->ns_opts['num_pages'], $this->ns_opts['num_media'])); + ptln('
'); + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform pagemove__nscontinue')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_continue'))); + $form->printForm(); + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('abort_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_abort'))); + $form->printForm(); + } elseif ($this->ns_opts !== false && isset($this->ns_opts['remaining'])) { + if ($this->ns_opts['remaining'] === false) { + ptln(''); + ptln(sprintf($this->getLang('pm_ns_move_error'), $this->ns_opts['ns'], $this->ns_opts['newns'])); + ptln('
'); + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform pagemove__nscontinue')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_tryagain'))); + $form->printForm(); + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('abort_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_abort'))); + $form->printForm(); + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('skip_continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_skip'))); + $form->printForm(); + } else { + ptln(''); + ptln(sprintf($this->getLang('pm_ns_move_continued'), $this->ns_opts['ns'], $this->ns_opts['newns'], $this->ns_opts['remaining'])); + ptln('
'); + + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_continue'))); + $form->printForm(); + $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__nsform')); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $ID); + $form->addHidden('abort_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_abort'))); + $form->printForm(); + } + } else { + $this->printForm(); + } + ptln('