X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=blobdiff_plain;f=includes%2FMovePage.php;h=bc3305ab0482e727d6c630a4584d9add3b7ad3da;hb=71e336981b5db53c9db614c18ee798863c3ded9c;hp=321b7e3339b7a93eb1b7e1e6660ef0a0cf73ab84;hpb=c89de8fef4124a47646b537122db435863cb3e21;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MovePage.php b/includes/MovePage.php index 321b7e3339..bc3305ab04 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -19,6 +19,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * Handles the backend logic of moving a page from one title * to another. @@ -238,7 +240,7 @@ class MovePage { $file->load( File::READ_LATEST ); if ( $file->exists() ) { $status = $file->move( $this->newTitle ); - if ( !$status->isOk() ) { + if ( !$status->isOK() ) { return $status; } } @@ -254,7 +256,7 @@ class MovePage { $pageid = $this->oldTitle->getArticleID( Title::GAID_FOR_UPDATE ); $protected = $this->oldTitle->isProtected(); - // Do the actual move + // Do the actual move; if this fails, it will throw an MWException(!) $nullRevision = $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect ); // Refresh the sortkey for this row. Be careful to avoid resetting @@ -369,7 +371,7 @@ class MovePage { $oldsnamespace = MWNamespace::getSubject( $this->oldTitle->getNamespace() ); $newsnamespace = MWNamespace::getSubject( $this->newTitle->getNamespace() ); if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) { - $store = WatchedItemStore::getDefaultInstance(); + $store = MediaWikiServices::getInstance()->getWatchedItemStore(); $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle ); } @@ -390,11 +392,16 @@ class MovePage { $reason, $nullRevision ]; - $dbw->onTransactionIdle( function () use ( $params, $dbw ) { - // Keep each single hook handler atomic - $dbw->setFlag( DBO_TRX ); // flag is automatically reset by DB layer - Hooks::run( 'TitleMoveComplete', $params ); - } ); + // Keep each single hook handler atomic + DeferredUpdates::addUpdate( + new AtomicSectionUpdate( + $dbw, + __METHOD__, + function () use ( $params ) { + Hooks::run( 'TitleMoveComplete', $params ); + } + ) + ); return Status::newGood(); } @@ -405,7 +412,7 @@ class MovePage { * * @fixme This was basically directly moved from Title, it should be split into smaller functions * @param User $user the User doing the move - * @param Title $nt The page to move to, which should be a redirect or nonexistent + * @param Title $nt The page to move to, which should be a redirect or non-existent * @param string $reason The reason for the move * @param bool $createRedirect Whether to leave a redirect at the old title. Does not check * if the user has the suppressredirect right @@ -423,6 +430,29 @@ class MovePage { $logType = 'move'; } + if ( $moveOverRedirect ) { + $overwriteMessage = wfMessage( + 'delete_and_move_reason', + $this->oldTitle->getPrefixedText() + )->text(); + $newpage = WikiPage::factory( $nt ); + $errs = []; + $status = $newpage->doDeleteArticleReal( + $overwriteMessage, + /* $suppress */ false, + $nt->getArticleId(), + /* $commit */ false, + $errs, + $user + ); + + if ( !$status->isGood() ) { + throw new MWException( 'Failed to delete page-move revision: ' . $status ); + } + + $nt->resetArticleID( false ); + } + if ( $createRedirect ) { if ( $this->oldTitle->getNamespace() == NS_CATEGORY && !wfMessage( 'category-move-redirect-override' )->inContentLanguage()->isDisabled() @@ -477,19 +507,6 @@ class MovePage { $newpage = WikiPage::factory( $nt ); - if ( $moveOverRedirect ) { - $newid = $nt->getArticleID(); - $newcontent = $newpage->getContent(); - - # Delete the old redirect. We don't save it to history since - # by definition if we've got here it's rather uninteresting. - # We have to remove it so that the next step doesn't trigger - # a conflict on the unique namespace+title index... - $dbw->delete( 'page', [ 'page_id' => $newid ], __METHOD__ ); - - $newpage->doDeleteUpdates( $newid, $newcontent ); - } - # Save a null revision in the page's history notifying of the move $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $user ); if ( !is_object( $nullRevision ) ) { @@ -535,9 +552,7 @@ class MovePage { ); } - if ( !$moveOverRedirect ) { - WikiPage::onArticleCreate( $nt ); - } + WikiPage::onArticleCreate( $nt ); # Recreate the redirect, this time in the other direction. if ( $redirectContent ) {