-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new namespace move functionality including ajax
Namespace moves are now split into junks of at maximum 10 pages
- Loading branch information
Showing
6 changed files
with
498 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
// must be run within Dokuwiki | ||
if (!defined('DOKU_INC')) die(); | ||
|
||
/** | ||
* Test cases for namespace move functionality of the pagemove plugin | ||
*/ | ||
class plugin_pagemove_namespace_move_test extends DokuWikiTest { | ||
|
||
public function setUp() { | ||
$this->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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
function html() { | ||
global $ID; | ||
ptln('<!-- Pagemove Plugin start -->'); | ||
ptln( $this->locale_xhtml('pagemove') ); | ||
$this->printForm(); | ||
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(); | ||
} 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(); | ||
} 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(); | ||
} | ||
} else { | ||
$this->printForm(); | ||
} | ||
ptln('</div>'); | ||
ptln('<!-- Pagemove Plugin end -->'); | ||
} | ||
|
||
|
@@ -93,16 +156,39 @@ function printForm() { | |
$form->endFieldset(); | ||
$form->printForm(); | ||
|
||
$form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__form')); | ||
$form->addHidden('page', $this->getPluginName()); | ||
$form->addHidden('id', $ID); | ||
$form->addHidden('move_type', 'namespace'); | ||
$form->startFieldset($this->getLang('pm_movens')); | ||
$form->addElement(form_makeMenuField('targetns', $ns_select_data, $this->opts['targetns'], $this->getLang('pm_targetns'), '', 'block')); | ||
$form->addElement(form_makeTextField('newnsname', $this->opts['newnsname'], $this->getLang('pm_newnsname'), '', 'block')); | ||
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_submit'))); | ||
$form->endFieldset(); | ||
$form->printForm(); | ||
if ($this->ns_opts !== false && !isset($this->ns_opts['remaining'])) { | ||
ptln('<fieldset>'); | ||
ptln('<legend>'); | ||
ptln($this->getLang('pm_movens')); | ||
ptln('</legend>'); | ||
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('</fieldset>'); | ||
} else { | ||
$form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'pagemove__form')); | ||
$form->addHidden('page', $this->getPluginName()); | ||
$form->addHidden('id', $ID); | ||
$form->addHidden('move_type', 'namespace'); | ||
$form->startFieldset($this->getLang('pm_movens')); | ||
$form->addElement(form_makeMenuField('targetns', $ns_select_data, $this->opts['targetns'], $this->getLang('pm_targetns'), '', 'block')); | ||
$form->addElement(form_makeTextField('newnsname', $this->opts['newnsname'], $this->getLang('pm_newnsname'), '', 'block')); | ||
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_submit'))); | ||
$form->endFieldset(); | ||
$form->printForm(); | ||
} | ||
} | ||
|
||
|
||
|
@@ -153,11 +239,35 @@ function handle() { | |
$this->opts['newnsname'] = ''; | ||
$this->opts['move_type'] = 'page'; | ||
|
||
/** @var helper_plugin_pagemove $helper */ | ||
$helper = $this->loadHelper('pagemove', true); | ||
if (!$helper) return; | ||
|
||
$this->ns_opts = $helper->get_namespace_move_opts(); | ||
|
||
// Only continue when the form was submitted | ||
if ($_SERVER['REQUEST_METHOD'] != 'POST') { | ||
return; | ||
} | ||
|
||
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->ns_opts['remaining'] = $helper->continue_namespace_move(); | ||
if ($this->ns_opts['remaining'] === 0) { | ||
$ID = $helper->getNewID($INFO['id'], $this->opts['ns'], $this->opts['newns']); | ||
$ACT = 'show'; | ||
} | ||
|
||
return; | ||
} elseif (isset($_POST['abort_namespace_move'])) { | ||
$helper->abort_namespace_move(); | ||
$this->ns_opts = false; | ||
|
||
return; | ||
} | ||
|
||
// Store the form data in the options and clean the submitted data. | ||
if (isset($_POST['ns_for_page'])) $this->opts['ns_for_page'] = cleanID((string)$_POST['ns_for_page']); | ||
if (isset($_POST['newns'])) $this->opts['newns'] = cleanID((string)$_POST['newns']); | ||
|
@@ -166,22 +276,20 @@ function handle() { | |
if (isset($_POST['newnsname'])) $this->opts['newnsname'] = cleanID((string)$_POST['newnsname']); | ||
if (isset($_POST['move_type'])) $this->opts['move_type'] = (string)$_POST['move_type']; | ||
|
||
/** @var helper_plugin_pagemove $helper */ | ||
$helper = $this->loadHelper('pagemove', true); | ||
if (!$helper) return; | ||
|
||
// check the input for completeness | ||
if( $this->opts['move_type'] == 'namespace' ) { | ||
$this->opts['media'] = true; // FIXME: add checkbox later! | ||
|
||
if ($this->opts['targetns'] == '') { | ||
$this->opts['newns'] = $this->opts['newnsname']; | ||
} else { | ||
$this->opts['newns'] = $this->opts['targetns'].':'.$this->opts['newnsname']; | ||
} | ||
|
||
if ($helper->move_namespace($this->opts, true) && | ||
$helper->move_namespace($this->opts)) { | ||
$ID = $helper->getNewID($INFO['id'], $this->opts['ns'], $this->opts['newns']); | ||
$ACT = 'show'; | ||
$started = $helper->start_namespace_move($this->opts); | ||
if ($started !== false) { | ||
$this->ns_opts = $helper->get_namespace_move_opts(); | ||
$this->ns_opts['started'] = $started; | ||
} | ||
} else { | ||
// check that the pagename is valid | ||
|
Oops, something went wrong.