Skip to content

Commit

Permalink
New error handling for _pm_move_page() - return parameter shows success
Browse files Browse the repository at this point in the history
  • Loading branch information
michitux committed Dec 29, 2012
1 parent ab183b6 commit 7b5f66e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
52 changes: 22 additions & 30 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,35 +420,25 @@ function _pm_move_recursive($pathToSearch, $opts) {
* @author Gary Owen <[email protected]>, 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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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']));

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:';
Expand Down

0 comments on commit 7b5f66e

Please sign in to comment.