- /**
- * Move page to non-existing title.
- *
- * @param $nt \type{Title} the new Title
- * @param $reason \type{\string} The reason for the move
- * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title
- * Ignored if the user doesn't have the suppressredirect right
- */
- private function moveToNewTitle( &$nt, $reason = '', $createRedirect = true ) {
- global $wgUser, $wgContLang;
-
- $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
- if ( $reason ) {
- $comment .= wfMsgExt( 'colon-separator',
- array( 'escapenoentities', 'content' ) );
- $comment .= $reason;
- }
- # Truncate for whole multibyte characters. +5 bytes for ellipsis
- $comment = $wgContLang->truncate( $comment, 250 );
-
- $newid = $nt->getArticleID();
- $oldid = $this->getArticleID();
- $latest = $this->getLatestRevId();
-
- $dbw = wfGetDB( DB_MASTER );
- $now = $dbw->timestamp();
-
- # Save a null revision in the page's history notifying of the move
- $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
- if ( !is_object( $nullRevision ) ) {
- throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
- }
- $nullRevId = $nullRevision->insertOn( $dbw );
-
- $article = new Article( $this );
- wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
-
- # Rename page entry
- $dbw->update( 'page',
- /* SET */ array(
- 'page_touched' => $now,
- 'page_namespace' => $nt->getNamespace(),
- 'page_title' => $nt->getDBkey(),
- 'page_latest' => $nullRevId,
- ),
- /* WHERE */ array( 'page_id' => $oldid ),
- __METHOD__
- );
- $nt->resetArticleID( $oldid );
-
- if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
- # Insert redirect
- $mwRedir = MagicWord::get( 'redirect' );
- $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
- $redirectArticle = new Article( $this );
- $newid = $redirectArticle->insertOn( $dbw );
- $redirectRevision = new Revision( array(
- 'page' => $newid,
- 'comment' => $comment,
- 'text' => $redirectText ) );
- $redirectRevision->insertOn( $dbw );
- $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
-
- wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) );
-
- # Record the just-created redirect's linking to the page
- $dbw->insert( 'pagelinks',
- array(
- 'pl_from' => $newid,
- 'pl_namespace' => $nt->getNamespace(),
- 'pl_title' => $nt->getDBkey() ),
- __METHOD__ );
- $redirectSuppressed = false;