* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Handles the backend logic of moving a page from one title
* to another.
$file->load( File::READ_LATEST );
if ( $file->exists() ) {
$status = $file->move( $this->newTitle );
- if ( !$status->isOk() ) {
+ if ( !$status->isOK() ) {
return $status;
}
}
$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
$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 );
}
$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();
}
*
* @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
$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()
$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 ) ) {
);
}
- if ( !$moveOverRedirect ) {
- WikiPage::onArticleCreate( $nt );
- }
+ WikiPage::onArticleCreate( $nt );
# Recreate the redirect, this time in the other direction.
if ( $redirectContent ) {