From 77e946e392dc585196e826722d55c8734b66fe93 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 29 Dec 2012 23:26:02 +0100 Subject: [PATCH] New user interface and handler for changed backend This updates the (English) user interface because of the changed functionality of the backend. --- admin.php | 325 +++++++++++-------------------------------- lang/en/lang.php | 31 ++--- lang/en/pagemove.txt | 15 +- script.js | 42 ++++++ 4 files changed, 144 insertions(+), 269 deletions(-) create mode 100644 script.js diff --git a/admin.php b/admin.php index 19c660a..105d89b 100644 --- a/admin.php +++ b/admin.php @@ -51,17 +51,13 @@ function getInfo(){ */ function getMenuText() { global $INFO; - global $ID; - global $conf; if( !$INFO['exists'] ) - return $this->lang['menu'].' ('.$this->lang['pm_notexist'].')'; - elseif( $ID == $conf['start'] ) - return $this->lang['menu'].' ('.$this->lang['pm_notstart'].')'; + return $this->getLang('menu').' ('.$this->getLang('pm_notexist').')'; elseif( !$INFO['writable'] ) - return $this->lang['menu'].' ('.$this->lang['pm_notwrite'].')'; + return $this->getLang('menu').' ('.$this->getLang('pm_notwrite').')'; else - return $this->lang['menu']; + return $this->getLang('menu'); } @@ -72,39 +68,9 @@ function getMenuText() { * @author Gary Owen */ function html() { - global $ID; - global $lang; - ptln(''); - if( $this->show_form ) { - ptln( $this->locale_xhtml('pagemove') ); - //We didn't get here from submit. - if( $this->have_rights && count($this->locked_files) == 0 ) { - $this->_pm_form(); - } - else { - ptln( '

' ); - if ( !$this->have_rights ) { - ptln( $this->errors[0].'
' ); - } - $c = count($this->locked_files); - if ( $c == 1 ) { - ptln( $this->lang['pm_filelocked'].$this->locked_files[0].'
'.$this->lang['pm_tryagain'] ); - } - elseif ( $c > 1 ) { - ptln( $this->lang['pm_fileslocked'] ); - for ( $i = 0 ; $i < $c ; $i++ ) { - ptln ( ($i > 0 ? ', ' : '').$this->locked_files[$i] ); - } - ptln( '
'.$this->lang['pm_tryagain'] ); - } - ptln ( '

' ); - } - } - else { - // display the moved/renamed page - p_wiki_xhtml($ID); - } + ptln( $this->locale_xhtml('pagemove') ); + $this->_pm_form(); ptln(''); } @@ -115,273 +81,148 @@ function html() { */ function _pm_form() { global $ID; - global $lang; - global $conf; $ns = getNS($ID); - $name = noNS($ID); - - ptln('
'); - ptln(' '); - ptln('
'); - // output hidden values to ensure dokuwiki will return back to this plugin - ptln(' '); - ptln(' '); - ptln(' '); - ptln('
'); - ptln(' '. $this->lang['pm_movepage'] .''); - ptln(' '); - - //Show any errors - if (count($this->errors) > 0) { - ptln (''); - } - //create a list of namespaces - ptln( ' '); - ptln( ' '); - ptln( ' \n "); - - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln(' '); // - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( '
'); - foreach($this->errors as $error) { - ptln ($error.'
'); - } - ptln ('
' ? 'CHECKED' : '').'>
'); - ptln( '
'); - - ptln('
'); - ptln('
'); - ptln(' '. $this->lang['pm_movens'] .''); - ptln(' '); - ptln( ' '); - ptln( ' \n "); - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( ' '); - ptln( '
'); - ptln('
'); - ptln( '
'); - ptln( '
'); - - ptln(''); - - ptln(' "); - - ptln( '
'); + + $ns_select_data = $this->build_namespace_select_content($ns); + + $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', 'page'); + $form->startFieldset($this->getLang('pm_movepage')); + $form->addElement(form_makeMenuField('ns_for_page', $ns_select_data, $this->opts['ns_for_page'], $this->getLang('pm_targetns'), '', 'block')); + $form->addElement(form_makeTextField('newns', $this->opts['newns'], $this->getLang('pm_newtargetns'), '', 'block')); + $form->addElement(form_makeTextField('newname', $this->opts['newname'], $this->getLang('pm_newname'), '', 'block')); + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('pm_submit'))); + $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(); } /** * create a list of namespaces for the html form * + * @author Michael Hamann * @author Gary Owen * @author Arno Puschmann (bin out of _pm_form) */ - function _pm_form_create_list_ns($ns) { + private function build_namespace_select_content($ns) { global $conf; + $result = array(); + $namesp = array( 0 => array('id' => '') ); //Include root search($namesp, $conf['datadir'], 'search_namespaces', array()); sort($namesp); foreach($namesp as $row) { if ( auth_quickaclcheck($row['id'].':*') >= AUTH_CREATE || $row['id'] == $ns ) { - ptln ( ' " ); + + $result[($row['id'] ? $row['id'] : ':')] = ($row['id'] ? $row['id'].':' : ": ".$this->getLang('pm_root')). + ($row['id'] == $ns ? ' '.$this->getLang('pm_current') : ''); } } + return $result; } /** * handle user request * + * @author Michael Hamann * @author Gary Owen */ function handle() { - - global $conf; - global $lang; global $ID; - global $INFO; global $ACT; + global $INFO; - // check we have rights to move this document - if( !$INFO['exists'] ) { - $this->have_rights = false; - $this->errors[] = $this->lang['pm_notexist']; - return; - } - // do not move start page - if( $ID == $conf['start'] ) { - $this->have_rights = false; - $this->errors[] = $this->lang['pm_notstart']; - return; - } - - // was a form send? - if (! array_key_exists('page_ns', $_REQUEST)) { - // @fixme do something more intelligent like showing in message + // populate options with default values + $this->opts['ns'] = getNS($ID); + $this->opts['name'] = noNS($ID); + $this->opts['ns_for_page'] = $INFO['namespace']; + $this->opts['newns'] = ''; + $this->opts['newname'] = noNS($ID); + $this->opts['targetns'] = getNS($ID); + $this->opts['newnsname'] = ''; + $this->opts['move_type'] = 'page'; + + // Only continue when the form was submitted + if ($_SERVER['REQUEST_METHOD'] != 'POST') { return; } - // extract namespace and document name from ID - $this->opts['ns'] = getNS($ID); - $this->opts['name'] = noNS($ID); - $this->opts['page_ns'] = $_REQUEST['page_ns']; + // 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']); + if (isset($_POST['newname'])) $this->opts['newname'] = cleanID((string)$_POST['newname']); + if (isset($_POST['targetns'])) $this->opts['targetns'] = cleanID((string)$_POST['targetns']); + if (isset($_POST['newnsname'])) $this->opts['newnsname'] = cleanID((string)$_POST['newnsname']); + if (isset($_POST['move_type'])) $this->opts['move_type'] = (string)$_POST['move_type']; // check the input for completeness - if( $this->opts['page_ns'] == 'ns' ) { - // @todo Target namespace needn't be new (check pages for overwrite!) - if( $_REQUEST['namespacename'] == '' ) { - $this->errors[] = $this->lang['pm_emptynamespace']; - return; - } - $this->opts['newnsname'] = $_REQUEST['namespacename']; - if ( cleanID($this->opts['newnsname']) == '' ) { - $this->errors[] = $this->lang['pm_badns']; - return; - } - if ($_REQUEST['ns'] == ':') { + if( $this->opts['move_type'] == 'namespace' ) { + if ($this->opts['targetns'] == '') { $this->opts['newns'] = $this->opts['newnsname']; - } - else { - $this->opts['newns'] = $_REQUEST['ns'].':'.$this->opts['newnsname']; + } else { + $this->opts['newns'] = $this->opts['targetns'].':'.$this->opts['newnsname']; } - $nsRelPath = utf8_encodeFN(str_replace(':', '/', $this->opts['ns'])); - $this->_pm_move_recursive($nsRelPath, $this->opts); - } - elseif( $this->opts['page_ns'] == 'page' ) { - if( $_REQUEST['pagename'] == '' ) { - $this->errors[] = $this->lang['pm_emptypagename']; + if ($this->_pm_move_recursive($this->opts, true) && + $this->_pm_move_recursive($this->opts)) { + $ID = $this->getNewID($INFO['id'], $this->opts['ns'], $this->opts['newns']); + $ACT = 'show'; + } else { return; } - $this->opts['newname'] = $_REQUEST['pagename']; + } else { // check that the pagename is valid - if ( cleanID($this->opts['newname']) == '' ) { - $this->errors[] = $this->lang['pm_badname']; + if ($this->opts['newname'] == '' ) { + msg($this->getLang('pm_badname'), -1); return; } - if ($_REQUEST['nsr'] == '') { - $this->opts['newns'] = ($_REQUEST['ns_for_page'] == ':' ? '' : $_REQUEST['ns_for_page']); - } - elseif ($_REQUEST['nsr'] =='') { - // if a new namespace was requested, check and use it - if ($_REQUEST['newns'] != '') { - $this->opts['newns'] = $_REQUEST['newns']; - // check that the new namespace is valid - if ( cleanID($this->opts['newns']) == '' ) { - $this->errors[] = $this->lang['pm_badns']; - return; - } - } - else { - $this->errors[] = $this->lang['pm_badns']; - return; - } - } - else { - $this->errors[] = $this->lang['pm_fatal']; - return; + if ($this->opts['newns'] === '') { + $this->opts['newns'] = $this->opts['ns_for_page']; } - $this->_pm_move_page($this->opts); - - // @todo if the namespace is now empty, delete it - - // Set things up to display the new page. - $ID = $this->opts['new_id']; - $ACT = 'show'; - $INFO = pageinfo(); - $this->show_form = false; - } - else { - $this->errors[] = $this->lang['pm_fatal']; - return; - } + if ($this->_pm_move_page($this->opts)) { + // @todo if the namespace is now empty, delete it - - // only go on if no errors occured and inputs are not empty - if (count($this->errors) != 0 ) { - return; - } - // delete empty namespaces if possible - // @fixme does not work like that - foreach ($this->idsToDelete as $idToDelete) { - io_sweepNS($idToDelete); + // Set things up to display the new page. + $ID = $this->opts['new_id']; + $ACT = 'show'; // this triggers a redirect to the page + } else { + return; + } } - } /** * * @author Bastian Wolf - * @param $pathToSearch * @param array $opts Options for moving the page * @param bool $checkonly If only the checks if all pages can be moved shall be executed * @return bool if the move was executed */ - function _pm_move_recursive($pathToSearch, &$opts, $checkonly = false) { + function _pm_move_recursive(&$opts, $checkonly = false) { global $ID; global $conf; $pagelist = array(); + $pathToSearch = utf8_encodeFN(str_replace(':', '/', $opts['ns'])); $searchOpts = array('depth' => 0, 'skipacl' => true); search($pagelist, $conf['datadir'], 'search_allpages', $searchOpts, $pathToSearch); diff --git a/lang/en/lang.php b/lang/en/lang.php index c02adcd..4659d70 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -15,35 +15,30 @@ $lang['menu'] = 'Page/Namespace Move/Rename...'; $lang['desc'] = 'Page/Namespace Move/Rename Plugin'; -$lang['pm_notexist'] = 'This topic does not exist yet'; -$lang['pm_notstart'] = 'The Start page cannot be moved or renamed'; -$lang['pm_notwrite'] = 'You do not have sufficient rights to modify this page'; +$lang['pm_notexist'] = 'This page does not exist'; +$lang['pm_notwrite'] = 'You do not have sufficient permissions to modify this page'; $lang['pm_badns'] = 'Invalid characters in namespace.'; $lang['pm_badname'] = 'Invalid characters in pagename.'; -$lang['pm_nochange'] = 'Document name and namespace are unchanged.'; -$lang['pm_existing'] = 'A document called %s already exists in %s'; +$lang['pm_nochange'] = 'Page name and namespace are unchanged.'; +$lang['pm_existing'] = 'A page called %s already exists in %s'; $lang['pm_root'] = '[Root namespace]'; $lang['pm_current'] = '(Current)'; -$lang['pm_movedfrom'] = 'Document moved from '; -$lang['pm_movedto'] = 'Document moved to '; $lang['pm_renamed'] = 'Page name changed from %s to %s'; $lang['pm_moved'] = 'Page moved from %s to %s'; $lang['pm_move_rename'] = 'Page moved and renamed from %s to %s'; -$lang['pm_fileslocked'] = 'These files are locked - '; $lang['pm_delete'] = 'Deleted by PageMove plugin'; $lang['pm_norights'] = 'You have insufficient permissions to edit %s.'; $lang['pm_notargetperms'] = 'You don\'t have the permission to create %s.'; $lang['pm_filelocked'] = 'The page %s is locked. Try again later.'; $lang['pm_linkchange'] = 'Links to %s changed to %s'; -$lang['pm_newname'] = 'New document name :'; -$lang['pm_newnsname'] = 'Use new Name for Namespace:'; -$lang['pm_targetns'] = 'Select new Namespace :'; -$lang['pm_newtargetns'] = 'Create a new Namespace'; +// Form labels +$lang['pm_newname'] = 'New page name:'; +$lang['pm_newnsname'] = 'New namespace name:'; +$lang['pm_targetns'] = 'Select new namespace:'; +$lang['pm_newtargetns'] = 'Create a new namespace:'; $lang['pm_movepage'] = 'Move page'; -$lang['pm_movens'] = 'Move Namespace'; -$lang['pm_previewpage'] = ' get moved to '; -$lang['pm_previewns'] = 'All pages and namespaces in the namespace %s: get moved in the namespace'; -$lang['pm_delete'] = 'Deleted by PageMove plugin'; -$lang['pm_preview'] = 'Preview'; +$lang['pm_movens'] = 'Move namespace'; $lang['pm_submit'] = 'Submit'; -?> \ No newline at end of file +// JavaScript preview +$lang['js']['pm_previewpage'] = 'OLDPAGE will be moved to NEWPAGE'; +$lang['js']['pm_previewns'] = 'All pages and namespaces in the namespace OLDNS will be moved in the namespace NEWNS'; diff --git a/lang/en/pagemove.txt b/lang/en/pagemove.txt index f801b3f..cfc7faa 100644 --- a/lang/en/pagemove.txt +++ b/lang/en/pagemove.txt @@ -1,13 +1,10 @@ ====== Pagemove ====== -This plugin allows you to move and/or rename the current document or move and/or rename the current namespace within the following restrictions. +This plugin allows you to move and/or rename the current page or move and/or rename the current namespace within the following restrictions: - * You cannot move the start page. - * You must have edit permission for the document and any documents that point to it (backlinks). - * The document and its' backlinks cannot be locked for editing. - * For moving a file you also need create permission in the target directory. - * You cannot move the document to a namespace where a document with the same name already exists. + * You must have edit permission for the current page/all pages in the current namespace + * The pages that are moved must not be locked for editing. + * For moving a page you also need create permission in the target namespace. + * You cannot move a page to a namespace where a page with the same name already exists. -All links to and from the page will be updated to reflect the new location and/or name. -\\ -\\ \ No newline at end of file +All links to and from the pages that are moved will be updated to reflect the new location and/or name. diff --git a/script.js b/script.js new file mode 100644 index 0000000..853d067 --- /dev/null +++ b/script.js @@ -0,0 +1,42 @@ +/** + * JavasScript code for the preview in the pagemove plugin + * + * @author Michael Hamann + */ + +jQuery(function() { + jQuery('form.pagemove__form').each(function() { + var $this = jQuery(this); + var $preview = jQuery('

'); + $this.find('input[type=submit]').before($preview); + var updatePreview = function() { + if ($this.find('input[name=move_type]').attr('value') == 'namespace') { + var targetns = $this.find('select[name=targetns]').attr('value'); + var newnsname = $this.find('input[name=newnsname]').attr('value'); + var previewns; + if (targetns == ':') { + previewns = newnsname; + } else { + previewns = targetns + ':' + newnsname; + } + $preview.text(LANG['plugins']['pagemove']['pm_previewns'].replace('OLDNS', JSINFO['namespace']).replace('NEWNS', previewns)); + } else { + var ns_for_page = $this.find('select[name=ns_for_page]').attr('value'); + var newns = $this.find('input[name=newns]').attr('value'); + var newname = $this.find('input[name=newname]').attr('value'); + var newid = ''; + if (newns.replace(/\s/g) != '') { + newid = newns + ':'; + } else if (ns_for_page != ':') { + newid = ns_for_page + ':'; + } + newid += newname; + $preview.text(LANG['plugins']['pagemove']['pm_previewpage'].replace('OLDPAGE', JSINFO['id']).replace('NEWPAGE', newid)); + + } + }; + updatePreview(); + $this.find('input,select').change(updatePreview); + $this.find('input').keyup(updatePreview); + }); +}); \ No newline at end of file