51 $this->oldTitle->getUserPermissionsErrors(
'move',
$user ),
52 $this->oldTitle->getUserPermissionsErrors(
'edit',
$user ),
53 $this->newTitle->getUserPermissionsErrors(
'move-target',
$user ),
54 $this->newTitle->getUserPermissionsErrors(
'edit',
$user )
59 foreach ( $errors
as $error ) {
66 $status->fatal(
'spamprotectiontext' );
69 $tp = $this->newTitle->getTitleProtection();
70 if ( $tp !==
false && !
$user->isAllowed( $tp[
'permission'] ) ) {
71 $status->fatal(
'cantmove-titleprotected' );
75 [ $this->oldTitle, $this->newTitle,
$user, $reason,
$status ]
92 if ( $this->oldTitle->equals( $this->newTitle ) ) {
95 if ( !$this->oldTitle->isMovable() ) {
96 $status->fatal(
'immobile-source-namespace', $this->oldTitle->getNsText() );
98 if ( $this->newTitle->isExternal() ) {
99 $status->fatal(
'immobile-target-namespace-iw' );
101 if ( !$this->newTitle->isMovable() ) {
102 $status->fatal(
'immobile-target-namespace', $this->newTitle->getNsText() );
105 $oldid = $this->oldTitle->getArticleID();
107 if ( strlen( $this->newTitle->getDBkey() ) < 1 ) {
108 $status->fatal(
'articleexists' );
111 ( $this->oldTitle->getDBkey() ==
'' ) ||
113 ( $this->newTitle->getDBkey() ==
'' )
115 $status->fatal(
'badarticleerror' );
118 # The move is allowed only if (1) the target doesn't exist, or
119 # (2) the target is a redirect to the source, and has no history
120 # (so we can undo bad moves right after they're done).
122 $status->fatal(
'articleexists' );
127 $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel() ) {
138 'content-not-allowed-here',
140 $this->newTitle->getPrefixedText()
145 if ( $this->oldTitle->inNamespace(
NS_FILE ) ) {
149 if ( $this->newTitle->inNamespace(
NS_FILE ) && !$this->oldTitle->inNamespace(
NS_FILE ) ) {
150 $status->fatal(
'nonfile-cannot-move-to-file' );
154 Hooks::run(
'MovePageIsValidMove', [ $this->oldTitle, $this->newTitle,
$status ] );
167 $file->load( File::READ_LATEST );
168 if ( $file->exists() ) {
170 $status->fatal(
'imageinvalidfilename' );
173 $status->fatal(
'imagetypemismatch' );
177 if ( !$this->newTitle->inNamespace(
NS_FILE ) ) {
178 $status->fatal(
'imagenocrossnamespace' );
192 # Is it an existing file?
193 if ( $this->newTitle->inNamespace(
NS_FILE ) ) {
195 $file->load( File::READ_LATEST );
196 if ( $file->exists() ) {
197 wfDebug( __METHOD__ .
": file exists\n" );
201 # Is it a redirect with no history?
202 if ( !$this->newTitle->isSingleRevRedirect() ) {
203 wfDebug( __METHOD__ .
": not a one-rev redirect\n" );
206 # Get the article text
208 if ( !is_object(
$rev ) ) {
212 # Does the redirect point to the source?
213 # Or is it a broken self-redirect, usually caused by namespace collisions?
217 if ( $redirTitle->getPrefixedDBkey() !== $this->oldTitle->getPrefixedDBkey() &&
218 $redirTitle->getPrefixedDBkey() !== $this->newTitle->getPrefixedDBkey() ) {
219 wfDebug( __METHOD__ .
": redirect points to other page\n" );
225 # Fail safe (not a redirect after all. strange.)
226 wfDebug( __METHOD__ .
": failsafe: database says " . $this->newTitle->getPrefixedDBkey() .
227 " is a redirect, but it doesn't contain a valid redirect.\n" );
243 Hooks::run(
'TitleMove', [ $this->oldTitle, $this->newTitle,
$user ] );
248 if ( $this->oldTitle->getNamespace() ==
NS_FILE ) {
250 $file->load( File::READ_LATEST );
251 if ( $file->exists() ) {
252 $status = $file->move( $this->newTitle );
262 $dbw->startAtomic( __METHOD__ );
264 Hooks::run(
'TitleMoveStarting', [ $this->oldTitle, $this->newTitle,
$user ] );
267 $protected = $this->oldTitle->isProtected();
270 $nullRevision = $this->
moveToInternal( $user, $this->newTitle, $reason, $createRedirect,
277 $prefixes = $dbw->select(
279 [
'cl_sortkey_prefix',
'cl_to' ],
280 [
'cl_from' => $pageid ],
284 foreach ( $prefixes
as $prefixRow ) {
285 $prefix = $prefixRow->cl_sortkey_prefix;
286 $catTo = $prefixRow->cl_to;
287 $dbw->update(
'categorylinks',
290 $this->newTitle->getCategorySortkey( $prefix ) ),
293 'cl_timestamp=cl_timestamp' ],
295 'cl_from' => $pageid,
301 $redirid = $this->oldTitle->getArticleID();
304 # Protect the redirect title as the title used to be...
307 [
'pr_type',
'pr_level',
'pr_cascade',
'pr_user',
'pr_expiry' ],
308 [
'pr_page' => $pageid ],
313 foreach (
$res as $row ) {
315 'pr_page' => $redirid,
316 'pr_type' => $row->pr_type,
317 'pr_level' => $row->pr_level,
318 'pr_cascade' => $row->pr_cascade,
319 'pr_user' => $row->pr_user,
320 'pr_expiry' => $row->pr_expiry
323 $dbw->insert(
'page_restrictions', $rowsInsert, __METHOD__, [
'IGNORE' ] );
328 $this->oldTitle->getPrefixedText(),
329 $this->newTitle->getPrefixedText()
330 )->inContentLanguage()->text();
332 $comment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $reason;
336 $insertedPrIds = $dbw->select(
339 [
'pr_page' => $redirid ],
342 $logRelationsValues = [];
343 foreach ( $insertedPrIds
as $prid ) {
344 $logRelationsValues[] = $prid->pr_id;
349 $logEntry->setTarget( $this->newTitle );
350 $logEntry->setComment( $comment );
351 $logEntry->setPerformer(
$user );
352 $logEntry->setParameters( [
353 '4::oldtitle' => $this->oldTitle->getPrefixedText(),
355 $logEntry->setRelations( [
'pr_id' => $logRelationsValues ] );
356 $logEntry->setTags( $changeTags );
357 $logId = $logEntry->insert();
358 $logEntry->publish( $logId );
362 if ( $this->oldTitle->getNamespace() != $this->newTitle->getNamespace() ) {
363 $dbw->update(
'pagelinks',
364 [
'pl_from_namespace' => $this->newTitle->getNamespace() ],
365 [
'pl_from' => $pageid ],
368 $dbw->update(
'templatelinks',
369 [
'tl_from_namespace' => $this->newTitle->getNamespace() ],
370 [
'tl_from' => $pageid ],
373 $dbw->update(
'imagelinks',
374 [
'il_from_namespace' => $this->newTitle->getNamespace() ],
375 [
'il_from' => $pageid ],
381 $oldtitle = $this->oldTitle->getDBkey();
382 $newtitle = $this->newTitle->getDBkey();
385 if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) {
386 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
387 $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle );
391 'TitleMoveCompleting',
392 [ $this->oldTitle, $this->newTitle,
393 $user, $pageid, $redirid, $reason, $nullRevision ]
396 $dbw->endAtomic( __METHOD__ );
439 array $changeTags = []
441 if ( $nt->exists() ) {
442 $moveOverRedirect =
true;
443 $logType =
'move_redir';
445 $moveOverRedirect =
false;
449 if ( $moveOverRedirect ) {
451 'delete_and_move_reason',
452 $this->oldTitle->getPrefixedText()
453 )->inContentLanguage()->text();
456 $status = $newpage->doDeleteArticleReal(
471 $nt->resetArticleID(
false );
474 if ( $createRedirect ) {
475 if ( $this->oldTitle->getNamespace() ==
NS_CATEGORY
476 && !
wfMessage(
'category-move-redirect-override' )->inContentLanguage()->isDisabled()
479 wfMessage(
'category-move-redirect-override' )
480 ->params( $nt->getPrefixedText() )->inContentLanguage()->plain() );
483 $redirectContent = $contentHandler->makeRedirectContent( $nt,
484 wfMessage(
'move-redirect-text' )->inContentLanguage()->
plain() );
489 $redirectContent =
null;
494 $contentModel = $this->oldTitle->getContentModel();
496 $defaultContentModelChanging = ( $oldDefault !== $newDefault
497 && $oldDefault === $contentModel );
500 $oldid = $this->oldTitle->getArticleID();
504 $logEntry->setPerformer(
$user );
505 $logEntry->setTarget( $logTitle );
506 $logEntry->setComment( $reason );
507 $logEntry->setParameters( [
508 '4::target' => $nt->getPrefixedText(),
509 '5::noredir' => $redirectContent ?
'0' :
'1',
514 $comment = $formatter->getPlainActionText();
516 $comment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $reason;
522 $oldcountable = $oldpage->isCountable();
526 # Change the name of the target page:
527 $dbw->update(
'page',
529 'page_namespace' => $nt->getNamespace(),
530 'page_title' => $nt->getDBkey(),
532 [
'page_id' => $oldid ],
536 # Save a null revision in the page's history notifying of the move
538 if ( !is_object( $nullRevision ) ) {
539 throw new MWException(
'Failed to create null revision while moving page ID '
540 . $oldid .
' to ' . $nt->getPrefixedDBkey() );
543 $nullRevId = $nullRevision->insertOn( $dbw );
544 $logEntry->setAssociatedRevId( $nullRevId );
546 if ( !$redirectContent ) {
551 $this->oldTitle->resetArticleID( 0 );
552 $nt->resetArticleID( $oldid );
555 $newpage->updateRevisionOn( $dbw, $nullRevision );
558 [ $newpage, $nullRevision, $nullRevision->getParentId(),
$user ] );
560 $newpage->doEditUpdates( $nullRevision,
$user,
561 [
'changed' =>
false,
'moved' =>
true,
'oldcountable' => $oldcountable ] );
564 if ( $defaultContentModelChanging ) {
567 [
'rev_content_model' => $contentModel ],
568 [
'rev_page' => $nt->getArticleID(),
'rev_content_model IS NULL' ],
575 # Recreate the redirect, this time in the other direction.
576 if ( $redirectContent ) {
579 $newid = $redirectArticle->insertOn( $dbw );
581 $this->oldTitle->resetArticleID( $newid );
583 'title' => $this->oldTitle,
585 'user_text' =>
$user->getName(),
586 'user' =>
$user->getId(),
587 'comment' => $comment,
588 'content' => $redirectContent ] );
589 $redirectRevId = $redirectRevision->
insertOn( $dbw );
590 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
593 [ $redirectArticle, $redirectRevision,
false,
$user ] );
595 $redirectArticle->doEditUpdates( $redirectRevision,
$user, [
'created' =>
true ] );
598 $redirectTags = $changeTags;
600 $redirectTags[] =
'mw-new-redirect';
607 $logid = $logEntry->insert();
609 $logEntry->setTags( $changeTags );
610 $logEntry->publish( $logid );
612 return $nullRevision;