Skip to content

Commit

Permalink
Code cleanup: Add new helper function for creating a namespace move b…
Browse files Browse the repository at this point in the history
…utton
  • Loading branch information
michitux committed Mar 31, 2013
1 parent 68f1b01 commit e4d6c6a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 84 deletions.
21 changes: 3 additions & 18 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>'.sprintf($this->getLang('pm_ns_move_error'), $opts['ns'], $opts['newns']).'</p>');
echo $helper->getNSMoveButton('tryagain', $id);
echo $helper->getNSMoveButton('skip', $id);
echo $helper->getNSMoveButton('abort', $id);
} else {
ptln('<p>'.sprintf($this->getLang('pm_ns_move_continued'), $opts['ns'], $opts['newns'], $remaining).'</p>');
}
Expand Down
89 changes: 23 additions & 66 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -63,66 +65,32 @@ function getMenuText() {
* @author Gary Owen <[email protected]>
*/
function html() {
global $ID;
if (!$this->helper) return;
ptln('<!-- Pagemove Plugin start -->');
ptln( $this->locale_xhtml('pagemove') );
ptln('<div class="plugin__pagemove_forms">');

if ($this->ns_opts !== false && isset($this->ns_opts['started'])) {
ptln('<p>');
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('</p>');
$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('<p>');
ptln(sprintf($this->getLang('pm_ns_move_error'), $this->ns_opts['ns'], $this->ns_opts['newns']));
ptln('</p>');
$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('<p>');
ptln(sprintf($this->getLang('pm_ns_move_continued'), $this->ns_opts['ns'], $this->ns_opts['newns'], $this->ns_opts['remaining']));
ptln('</p>');

$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();
Expand Down Expand Up @@ -164,18 +132,8 @@ function printForm() {
ptln('<p>');
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('</p>');
$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('</fieldset>');
} else {
$form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__form'));
Expand Down Expand Up @@ -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') {
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down

0 comments on commit e4d6c6a

Please sign in to comment.