diff --git a/action.php b/action.php index 09ae870..1fe9244 100644 --- a/action.php +++ b/action.php @@ -184,25 +184,10 @@ public function handle_ajax_call(Doku_Event $event, $params) { 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']).'
'); + echo $helper->getNSMoveButton('tryagain', $id); + echo $helper->getNSMoveButton('skip', $id); + echo $helper->getNSMoveButton('abort', $id); } else { ptln(''.sprintf($this->getLang('pm_ns_move_continued'), $opts['ns'], $opts['newns'], $remaining).'
'); } diff --git a/admin.php b/admin.php index f6a723e..e8b8f7c 100644 --- a/admin.php +++ b/admin.php @@ -17,6 +17,8 @@ class admin_plugin_pagemove extends DokuWiki_Admin_Plugin { var $opts = array(); private $ns_opts = false; + /** @var helper_plugin_pagemove $helper */ + private $helper = null; /** * Get the sort number that defines the position in the admin menu. @@ -63,66 +65,32 @@ 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(); + ptln($this->helper->getNSMoveButton('continue')); + ptln($this->helper->getNSMoveButton('abort')); } 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(); + ptln($this->helper->getNSMoveButton('tryagain')); + ptln($this->helper->getNSMoveButton('skip')); + ptln($this->helper->getNSMoveButton('abort')); } 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(); + ptln($this->helper->getNSMoveButton('continue')); + ptln($this->helper->getNSMoveButton('abort')); } } else { $this->printForm(); @@ -164,18 +132,8 @@ function printForm() { ptln(''); ptln(sprintf($this->getLang('pm_ns_move_in_progress'), $this->ns_opts['num_pages'], $this->ns_opts['num_media'], ':'.hsc($this->ns_opts['ns']), ':'.hsc($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_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(); + ptln($this->helper->getNSMoveButton('continue')); + ptln($this->helper->getNSMoveButton('abort')); ptln(''); } else { $form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__form')); @@ -239,11 +197,10 @@ function handle() { $this->opts['newnsname'] = ''; $this->opts['move_type'] = 'page'; - /** @var helper_plugin_pagemove $helper */ - $helper = $this->loadHelper('pagemove', true); - if (!$helper) return; + $this->helper = $this->loadHelper('pagemove', true); + if (!$this->helper) return; - $this->ns_opts = $helper->get_namespace_move_opts(); + $this->ns_opts = $this->helper->get_namespace_move_opts(); // Only continue when the form was submitted if ($_SERVER['REQUEST_METHOD'] != 'POST') { @@ -252,17 +209,17 @@ function handle() { if (isset($_POST['continue_namespace_move']) || isset($_POST['skip_continue_namespace_move'])) { if (isset($_POST['skip_continue_namespace_move'])) { - $helper->skip_namespace_move_item(); + $this->helper->skip_namespace_move_item(); } - $this->ns_opts['remaining'] = $helper->continue_namespace_move(); + $this->ns_opts['remaining'] = $this->helper->continue_namespace_move(); if ($this->ns_opts['remaining'] === 0) { - $ID = $helper->getNewID($INFO['id'], $this->opts['ns'], $this->opts['newns']); + $ID = $this->helper->getNewID($INFO['id'], $this->opts['ns'], $this->opts['newns']); $ACT = 'show'; } return; } elseif (isset($_POST['abort_namespace_move'])) { - $helper->abort_namespace_move(); + $this->helper->abort_namespace_move(); $this->ns_opts = false; return; @@ -286,9 +243,9 @@ function handle() { $this->opts['newns'] = $this->opts['targetns'].':'.$this->opts['newnsname']; } - $started = $helper->start_namespace_move($this->opts); + $started = $this->helper->start_namespace_move($this->opts); if ($started !== false) { - $this->ns_opts = $helper->get_namespace_move_opts(); + $this->ns_opts = $this->helper->get_namespace_move_opts(); $this->ns_opts['started'] = $started; } } else { @@ -302,7 +259,7 @@ function handle() { $this->opts['newns'] = $this->opts['ns_for_page']; } - if ($helper->move_page($this->opts)) { + if ($this->helper->move_page($this->opts)) { // Set things up to display the new page. $ID = $this->opts['new_id']; $ACT = 'show'; // this triggers a redirect to the page diff --git a/helper.php b/helper.php index 8c15517..f81c8ea 100644 --- a/helper.php +++ b/helper.php @@ -752,6 +752,56 @@ protected function resolve_moves($moves, $id) { } return $moves; } + + /** + * Get the HTML code of a namespace move button + * @param string $action The desired action of the button (continue, tryagain, skip, abort) + * @param string|null $id The id of the target page, null if $ID shall be used + * @return bool|string The HTML of code of the form or false if an invalid action was supplied + */ + public function getNSMoveButton($action, $id = NULL) { + if ($id === NULL) { + global $ID; + $id = $ID; + } + + $class = 'pagemove__nsform'; + switch ($action) { + case 'continue': + case 'tryagain': + $class .= ' pagemove__nscontinue'; + break; + case 'skip': + $class .= ' pagemove__nsskip'; + break; + } + + $form = new Doku_Form(array('action' => wl($id), 'method' => 'post', 'class' => $class)); + $form->addHidden('page', $this->getPluginName()); + $form->addHidden('id', $id); + switch ($action) { + case 'continue': + case 'tryagain': + $form->addHidden('continue_namespace_move', true); + if ($action == 'tryagain') { + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_tryagain'))); + } else { + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_continue'))); + } + break; + case 'skip': + $form->addHidden('skip_continue_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_skip'))); + break; + case 'abort': + $form->addHidden('abort_namespace_move', true); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_ns_move_abort'))); + break; + default: + return false; + } + return $form->getForm(); + } } /**