X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMovePage.php;h=7d27a277b4770172a182aa396ba927e7fa9f3ee9;hb=8c18b95cbe8149544dbf284733ebd6edb4f2f031;hp=0fd697b5bd7c7b3f3d5998375f064debdbca9f4e;hpb=e1e44592aac39d8dfd7d7052fd9f75af9c5efb0d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MovePage.php b/includes/MovePage.php index 0fd697b5bd..7d27a277b4 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -20,6 +20,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Revision\SlotRecord; /** * Handles the backend logic of moving a page from one title @@ -137,7 +138,8 @@ class MovePage { $status->fatal( 'content-not-allowed-here', ContentHandler::getLocalizedName( $this->oldTitle->getContentModel() ), - $this->newTitle->getPrefixedText() + $this->newTitle->getPrefixedText(), + SlotRecord::MAIN ); } @@ -247,23 +249,7 @@ class MovePage { return $status; } - // If it is a file, move it first. - // It is done before all other moving stuff is done because it's hard to revert. $dbw = wfGetDB( DB_MASTER ); - if ( $this->oldTitle->getNamespace() == NS_FILE ) { - $file = wfLocalFile( $this->oldTitle ); - $file->load( File::READ_LATEST ); - if ( $file->exists() ) { - $status = $file->move( $this->newTitle ); - if ( !$status->isOK() ) { - return $status; - } - } - // Clear RepoGroup process cache - RepoGroup::singleton()->clearCache( $this->oldTitle ); - RepoGroup::singleton()->clearCache( $this->newTitle ); # clear false negative cache - } - $dbw->startAtomic( __METHOD__ ); Hooks::run( 'TitleMoveStarting', [ $this->oldTitle, $this->newTitle, $user ] ); @@ -392,6 +378,16 @@ class MovePage { $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle ); } + // If it is a file then move it last. + // This is done after all database changes so that file system errors cancel the transaction. + if ( $this->oldTitle->getNamespace() == NS_FILE ) { + $status = $this->moveFile( $this->oldTitle, $this->newTitle ); + if ( !$status->isOK() ) { + $dbw->cancelAtomic( __METHOD__ ); + return $status; + } + } + Hooks::run( 'TitleMoveCompleting', [ $this->oldTitle, $this->newTitle, @@ -425,6 +421,33 @@ class MovePage { return Status::newGood(); } + /** + * Move a file associated with a page to a new location. + * Can also be used to revert after a DB failure. + * + * @access private + * @param Title Old location to move the file from. + * @param Title New location to move the file to. + * @return Status + */ + private function moveFile( $oldTitle, $newTitle ) { + $status = Status::newFatal( + 'cannotdelete', + $oldTitle->getPrefixedText() + ); + + $file = wfLocalFile( $oldTitle ); + $file->load( File::READ_LATEST ); + if ( $file->exists() ) { + $status = $file->move( $newTitle ); + } + + // Clear RepoGroup process cache + RepoGroup::singleton()->clearCache( $oldTitle ); + RepoGroup::singleton()->clearCache( $newTitle ); # clear false negative cache + return $status; + } + /** * Move page to a title which is either a redirect to the * source page or nonexistent