From cf13bdb44db87016f92721ebc8e32f499e2ee300 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 25 May 2008 05:06:50 +0000 Subject: [PATCH] * Wrap file into one nice move transaction with the rest * Fix undefined variable error --- includes/SpecialMovepage.php | 4 +-- includes/Title.php | 58 ++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 94ab79bdbe..3e14a20f8f 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -342,9 +342,9 @@ class MovePageForm { $conds = null; } + $extrapages = array(); if( !is_null( $conds ) ) { - $extrapages = $dbr->select( - 'page', + $extrapages = $dbr->select( 'page', array( 'page_id', 'page_namespace', 'page_title' ), $conds, __METHOD__ diff --git a/includes/Title.php b/includes/Title.php index 93e6564009..fc98a0e82a 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2584,18 +2584,9 @@ class Title { $now = wfTimestampNow(); $newid = $nt->getArticleID(); $oldid = $this->getArticleID(); - $dbw = wfGetDB( DB_MASTER ); - # Move an image if it is - if( $this->getNamespace() == NS_IMAGE ) { - $file = wfLocalFile( $this ); - if( $file->exists() ) { - $status = $file->move( $nt ); - if( !$status->isOk() ) { - return $status->getWikiText(); - } - } - } + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin(); # Delete the old redirect. We don't save it to history since # by definition if we've got here it's rather uninteresting. @@ -2638,8 +2629,7 @@ class Title { wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) ); # Recreate the redirect, this time in the other direction. - if($createRedirect || !$wgUser->isAllowed('suppressredirect')) - { + if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) { $mwRedir = MagicWord::get( 'redirect' ); $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; $redirectArticle = new Article( $this ); @@ -2665,6 +2655,19 @@ class Title { } else { $this->resetArticleID( 0 ); } + + # Move an image if this is a file + if( $this->getNamespace() == NS_IMAGE ) { + $file = wfLocalFile( $this ); + if( $file->exists() ) { + $status = $file->move( $nt ); + if( !$status->isOk() ) { + $dbw->rollback(); + return $status->getWikiText(); + } + } + } + $dbw->commit(); # Log the move $log = new LogPage( 'move' ); @@ -2695,20 +2698,11 @@ class Title { $newid = $nt->getArticleID(); $oldid = $this->getArticleID(); + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin(); $now = $dbw->timestamp(); - # Move an image if it is - if( $this->getNamespace() == NS_IMAGE ) { - $file = wfLocalFile( $this ); - if( $file->exists() ) { - $status = $file->move( $nt ); - if( !$status->isOk() ) { - return $status->getWikiText(); - } - } - } - # Save a null revision in the page's history notifying of the move $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true ); $nullRevId = $nullRevision->insertOn( $dbw ); @@ -2730,8 +2724,7 @@ class Title { wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) ); - if($createRedirect || !$wgUser->isAllowed('suppressredirect')) - { + if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) { # Insert redirect $mwRedir = MagicWord::get( 'redirect' ); $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; @@ -2756,6 +2749,19 @@ class Title { } else { $this->resetArticleID( 0 ); } + + # Move an image if this is a file + if( $this->getNamespace() == NS_IMAGE ) { + $file = wfLocalFile( $this ); + if( $file->exists() ) { + $status = $file->move( $nt ); + if( !$status->isOk() ) { + $dbw->rollback(); + return $status->getWikiText(); + } + } + } + $dbw->commit(); # Log the move $log = new LogPage( 'move' ); -- 2.20.1