From 7b5f66e5ab9c4f1e43f2483eab83b394370c8936 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 29 Dec 2012 23:15:27 +0100 Subject: [PATCH] New error handling for _pm_move_page() - return parameter shows success --- admin.php | 52 ++++++++++++++++++++---------------------------- lang/en/lang.php | 7 ++++--- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/admin.php b/admin.php index 43befcc..4a277f4 100644 --- a/admin.php +++ b/admin.php @@ -420,35 +420,25 @@ function _pm_move_recursive($pathToSearch, $opts) { * @author Gary Owen , modified by Kay Roesler * * @param array $opts + * @return bool If the move was executed */ - function _pm_move_page($opts) { - - global $conf; - global $lang; + function _pm_move_page(&$opts) { global $ID; - global $INFO; - global $ACT; // Check we have rights to move this document - if ( !$INFO['exists']) { - $this->have_rights = false; - $this->errors[] = $this->lang['pm_notexist']; - return; - } - if ( $ID == $conf['start']) { - $this->have_rights = false; - $this->errors[] = $this->lang['pm_notstart']; - return; + if ( !page_exists($ID)) { + msg($this->getLang('pm_notexist'), -1); + return false; } if ( auth_quickaclcheck($ID) < AUTH_EDIT ) { - $this->have_rights = false; - $this->errors[] = $this->lang['pm_norights']; - return; + msg(sprintf($this->getLang('pm_norights'), hsc($ID)), -1); + return false; } // Check file is not locked - if (checklock($ID)) { - $this->locked_files[] = $ID; + if (checklock($ID) !== false) { + msg( sprintf($this->getLang('pm_filelocked'), hsc($ID)), -1); + return false; } // Assemble fill document name and path @@ -457,18 +447,20 @@ function _pm_move_page($opts) { // Has the document name and/or namespace changed? if ( $opts['newns'] == $opts['ns'] && $opts['newname'] == $opts['name'] ) { - $this->errors[] = $this->lang['pm_nochange']; - return; + msg($this->getLang('pm_nochange'), -1); + return false; } // Check the page does not already exist if ( @file_exists($opts['new_path']) ) { - $this->errors[] = sprintf($this->lang['pm_existing'], $opts['newname'], - ($opts['newns'] == '' ? $this->lang['pm_root'] : $opts['newns'])); - return; + msg(sprintf($this->getLang('pm_existing'), $opts['newname'], + ($opts['newns'] == '' ? $this->getLang('pm_root') : $opts['newns'])), -1); + return false; } - if ( count($this->errors) != 0 ) { - return; + // Check if the current user can create the new page + if (auth_quickaclcheck($opts['new_id']) < AUTH_CREATE) { + msg(sprintf($this->getLang('pm_notargetperms'), $opts['new_id']), -1); + return false; } /** @@ -496,7 +488,7 @@ function _pm_move_page($opts) { /** @var helper_plugin_pagemove $helper */ $helper = $this->loadHelper('pagemove', true); - if (is_null($helper)) return; + if (is_null($helper)) return false; $text = $helper->rewrite_content($text, $ID, array($ID => $opts['new_id'])); @@ -513,12 +505,12 @@ function _pm_move_page($opts) { else { $lang_key = 'pm_move_rename'; } - $summary = sprintf($this->lang[$lang_key], $ID, $opts['new_id']); + $summary = sprintf($this->getLang($lang_key), $ID, $opts['new_id']); saveWikiText($opts['new_id'], $text, $summary); // Delete the orginal file if (@file_exists(wikiFN($opts['new_id']))) { - saveWikiText($ID, '', $this->lang['pm_delete'] ); + saveWikiText($ID, '', $this->getLang('pm_delete') ); } // Move the old revisions diff --git a/lang/en/lang.php b/lang/en/lang.php index 1432f5b..c02adcd 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -29,10 +29,11 @@ $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_norights'] = 'You have insufficient permissions to edit one or more backlinks for this document.'; -$lang['pm_tryagain'] = 'Try again latter.'; -$lang['pm_filelocked'] = 'This file is locked - '; $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:';