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 ) {
60 call_user_func_array( [
$status,
'fatal' ], $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 ) ) {
211 $content =
$rev->getContent();
212 # Does the redirect point to the source?
213 # Or is it a broken self-redirect, usually caused by namespace collisions?
214 $redirTitle = $content ? $content->getRedirectTarget() :
null;
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 ],
283 if ( $this->newTitle->getNamespace() ==
NS_CATEGORY ) {
285 } elseif ( $this->newTitle->getNamespace() ==
NS_FILE ) {
290 foreach ( $prefixes
as $prefixRow ) {
291 $prefix = $prefixRow->cl_sortkey_prefix;
292 $catTo = $prefixRow->cl_to;
293 $dbw->update(
'categorylinks',
296 $this->newTitle->getCategorySortkey( $prefix ) ),
299 'cl_timestamp=cl_timestamp' ],
301 'cl_from' => $pageid,
307 $redirid = $this->oldTitle->getArticleID();
310 # Protect the redirect title as the title used to be...
314 [
'pr_page' => $pageid ],
319 foreach (
$res as $row ) {
321 'pr_page' => $redirid,
322 'pr_type' => $row->pr_type,
323 'pr_level' => $row->pr_level,
324 'pr_cascade' => $row->pr_cascade,
325 'pr_user' => $row->pr_user,
326 'pr_expiry' => $row->pr_expiry
329 $dbw->insert(
'page_restrictions', $rowsInsert, __METHOD__, [
'IGNORE' ] );
334 $this->oldTitle->getPrefixedText(),
335 $this->newTitle->getPrefixedText()
336 )->inContentLanguage()->text();
338 $comment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $reason;
342 $insertedPrIds = $dbw->select(
345 [
'pr_page' => $redirid ],
348 $logRelationsValues = [];
349 foreach ( $insertedPrIds
as $prid ) {
350 $logRelationsValues[] = $prid->pr_id;
355 $logEntry->setTarget( $this->newTitle );
356 $logEntry->setComment( $comment );
357 $logEntry->setPerformer(
$user );
358 $logEntry->setParameters( [
359 '4::oldtitle' => $this->oldTitle->getPrefixedText(),
361 $logEntry->setRelations( [
'pr_id' => $logRelationsValues ] );
362 $logEntry->setTags( $changeTags );
363 $logId = $logEntry->insert();
364 $logEntry->publish( $logId );
368 if ( $this->oldTitle->getNamespace() != $this->newTitle->getNamespace() ) {
369 $dbw->update(
'pagelinks',
370 [
'pl_from_namespace' => $this->newTitle->getNamespace() ],
371 [
'pl_from' => $pageid ],
374 $dbw->update(
'templatelinks',
375 [
'tl_from_namespace' => $this->newTitle->getNamespace() ],
376 [
'tl_from' => $pageid ],
379 $dbw->update(
'imagelinks',
380 [
'il_from_namespace' => $this->newTitle->getNamespace() ],
381 [
'il_from' => $pageid ],
387 $oldtitle = $this->oldTitle->getDBkey();
388 $newtitle = $this->newTitle->getDBkey();
391 if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) {
392 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
393 $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle );
397 'TitleMoveCompleting',
398 [ $this->oldTitle, $this->newTitle,
399 $user, $pageid, $redirid, $reason, $nullRevision ]
402 $dbw->endAtomic( __METHOD__ );
445 array $changeTags = []
447 if ( $nt->exists() ) {
448 $moveOverRedirect =
true;
449 $logType =
'move_redir';
451 $moveOverRedirect =
false;
455 if ( $moveOverRedirect ) {
457 'delete_and_move_reason',
458 $this->oldTitle->getPrefixedText()
459 )->inContentLanguage()->text();
462 $status = $newpage->doDeleteArticleReal(
477 $nt->resetArticleID(
false );
480 if ( $createRedirect ) {
481 if ( $this->oldTitle->getNamespace() ==
NS_CATEGORY
482 && !
wfMessage(
'category-move-redirect-override' )->inContentLanguage()->isDisabled()
485 wfMessage(
'category-move-redirect-override' )
486 ->params( $nt->getPrefixedText() )->inContentLanguage()->plain() );
489 $redirectContent = $contentHandler->makeRedirectContent( $nt,
490 wfMessage(
'move-redirect-text' )->inContentLanguage()->
plain() );
495 $redirectContent =
null;
500 $contentModel = $this->oldTitle->getContentModel();
502 $defaultContentModelChanging = ( $oldDefault !== $newDefault
503 && $oldDefault === $contentModel );
506 $oldid = $this->oldTitle->getArticleID();
510 $logEntry->setPerformer(
$user );
511 $logEntry->setTarget( $logTitle );
512 $logEntry->setComment( $reason );
513 $logEntry->setParameters( [
514 '4::target' => $nt->getPrefixedText(),
515 '5::noredir' => $redirectContent ?
'0' :
'1',
520 $comment = $formatter->getPlainActionText();
522 $comment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $reason;
528 $oldcountable = $oldpage->isCountable();
532 # Save a null revision in the page's history notifying of the move
534 if ( !is_object( $nullRevision ) ) {
535 throw new MWException(
'No valid null revision produced in ' . __METHOD__ );
538 $nullRevId = $nullRevision->insertOn( $dbw );
539 $logEntry->setAssociatedRevId( $nullRevId );
541 # Change the name of the target page:
542 $dbw->update(
'page',
544 'page_namespace' => $nt->getNamespace(),
545 'page_title' => $nt->getDBkey(),
547 [
'page_id' => $oldid ],
551 if ( !$redirectContent ) {
556 $this->oldTitle->resetArticleID( 0 );
557 $nt->resetArticleID( $oldid );
560 $newpage->updateRevisionOn( $dbw, $nullRevision );
563 [ $newpage, $nullRevision, $nullRevision->getParentId(),
$user ] );
565 $newpage->doEditUpdates( $nullRevision,
$user,
566 [
'changed' =>
false,
'moved' =>
true,
'oldcountable' => $oldcountable ] );
569 if ( $defaultContentModelChanging ) {
572 [
'rev_content_model' => $contentModel ],
573 [
'rev_page' => $nt->getArticleID(),
'rev_content_model IS NULL' ],
580 # Recreate the redirect, this time in the other direction.
581 if ( $redirectContent ) {
584 $newid = $redirectArticle->insertOn( $dbw );
586 $this->oldTitle->resetArticleID( $newid );
588 'title' => $this->oldTitle,
590 'user_text' =>
$user->getName(),
591 'user' =>
$user->getId(),
592 'comment' => $comment,
593 'content' => $redirectContent ] );
594 $redirectRevId = $redirectRevision->
insertOn( $dbw );
595 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
598 [ $redirectArticle, $redirectRevision,
false,
$user ] );
600 $redirectArticle->doEditUpdates( $redirectRevision,
$user, [
'created' =>
true ] );
607 $logid = $logEntry->insert();
609 $logEntry->setTags( $changeTags );
610 $logEntry->publish( $logid );
612 return $nullRevision;