class MovePageForm {
var $oldTitle, $newTitle; # Text input
-
- var $ot, $nt; # Old, new Title objects
- var $ons, $nns; # Namespaces
- var $odt, $ndt; # Pagenames (dbkey form)
- var $oft, $nft; # Full page titles (DBkey form)
- var $ofx, $nfx; # Full page titles (Text form)
- var $oldid, $newid; # "cur_id" field (yes, both from "cur")
- var $talkmoved = 0;
-
+
function MovePageForm() {
global $wgRequest;
$this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
global $wgUseSquid;
$fname = "MovePageForm::doSubmit";
- $this->ot = Title::newFromText( $this->oldTitle );
- $this->nt = Title::newFromText( $this->newTitle );
- if( !$this->ot or !$this->nt ) {
- $this->showForm( wfMsg( "badtitletext" ) );
- return;
- }
- $this->ons = $this->ot->getNamespace();
- $this->nns = $this->nt->getNamespace();
- $this->odt = wfStrencode( $this->ot->getDBkey() );
- $this->ndt = wfStrencode( $this->nt->getDBkey() );
- $this->oft = wfStrencode( $this->ot->getPrefixedDBkey() );
- $this->nft = wfStrencode( $this->nt->getPrefixedDBkey() );
- $this->ofx = $this->ot->getPrefixedText();
- $this->nfx = $this->nt->getPrefixedText();
+ $ot = Title::newFromText( $this->oldTitle );
+ $nt = Title::newFromText( $this->newTitle );
- $this->oldid = $this->ot->getArticleID();
- $this->newid = $this->nt->getArticleID();
-
- if ( strlen( trim( $this->ndt ) ) < 1 ) {
- $this->showForm( wfMsg( "articleexists" ) );
- return;
- }
- if ( ( ! Namespace::isMovable( $this->ons ) ) ||
- ( "" == $this->odt ) ||
- ( "" != $this->ot->getInterwiki() ) ||
- ( !$this->ot->userCanEdit() ) ||
- ( !$this->oldid ) ||
- ( ! Namespace::isMovable( $this->nns ) ) ||
- ( "" == $this->ndt ) ||
- ( "" != $this->nt->getInterwiki() ) ||
- ( !$this->nt->userCanEdit() ) ) {
- $this->showForm( wfMsg( "badarticleerror" ) );
+ $error = $ot->moveTo( $nt );
+ if ( $error !== true ) {
+ $this->showForm( wfMsg( $error ) );
return;
}
- # The move is allowed only if (1) the target doesn't exist, or
- # (2) the target is a redirect to the source, and has no history
- # (so we can undo bad moves right after they're done).
-
- if ( 0 != $this->newid ) { # Target exists; check for validity
- if ( ! $this->isValidTarget() ) {
- $this->showForm( wfMsg( "articleexists" ) );
- return;
- }
- $this->moveOverExistingRedirect();
- } else { # Target didn't exist, do normal move.
- $this->moveToNewTitle();
- }
-
- $this->updateWatchlists();
-
- $u = new SearchUpdate( $this->oldid, $this->nt->getPrefixedDBkey() );
- $u->doUpdate();
- $u = new SearchUpdate( $this->newid, $this->ot->getPrefixedDBkey(), "" );
- $u->doUpdate();
# Move talk page if
# (1) the checkbox says to,
# (2) the namespaces are not themselves talk namespaces, and of course
# (3) it exists.
+ $ons = $ot->getNamespace();
+ $nns = $nt->getNamespace();
+
if ( ( 1 == $_REQUEST['wpMovetalk'] ) &&
- ( ! Namespace::isTalk( $this->ons ) ) &&
- ( ! Namespace::isTalk( $this->nns ) ) ) {
+ ( ! Namespace::isTalk( $ons ) ) &&
+ ( ! Namespace::isTalk( $nns ) ) ) {
# get old talk page namespace
- $this->ons = Namespace::getTalk( $this->ons );
+ $ons = Namespace::getTalk( $ons );
# get new talk page namespace
- $this->nns = Namespace::getTalk( $this->nns );
-
+ $nns = Namespace::getTalk( $nns );
- # grab the newer title objects
- $this->ot = Title::makeTitle( $this->ons, $this->ot->getDBkey() );
- $this->nt = Title::makeTitle( $this->nns, $this->nt->getDBkey() );
-
- # odt, ndt, ofx, nfx remain the same
-
- $this->oft = wfStrencode( $this->ot->getPrefixedDBkey() );
- $this->nft = wfStrencode( $this->nt->getPrefixedDBkey() );
-
- $this->oldid = $this->ot->getArticleID();
- $this->newid = $this->nt->getArticleID();
-
- if ( 0 != $this->oldid ) {
- if ( 0 != $this->newid ) {
- if ( $this->isValidTarget() ) {
- $this->moveOverExistingRedirect();
- $this->talkmoved = 1;
- } else {
- $this->talkmoved = 'invalid';
- }
- } else {
- $this->moveToNewTitle();
- $this->talkmoved = 1;
- }
- $u = new SearchUpdate( $this->oldid, $this->nt->getPrefixedDBkey() );
- $u->doUpdate();
- $u = new SearchUpdate( $this->newid, $this->ot->getPrefixedDBkey(), "" );
- $u->doUpdate();
+ # make talk page title objects
+ $ott = Title::makeTitle( $ons, $ot->getDBkey() );
+ $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
+
+ # Attempt the move
+ $error = $ott->moveTo( $ntt );
+ if ( $error === true ) {
+ $talkmoved = 1;
+ } else {
+ $talkmoved = $error;
}
}
+
$titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" );
$success = $titleObj->getFullURL(
- "action=success&oldtitle=" . wfUrlencode( $this->ofx ) .
- "&newtitle=" . wfUrlencode( $this->nfx ) .
- "&talkmoved={$this->talkmoved}" );
+ "action=success&oldtitle=" . wfUrlencode( $ot->getPrefixedText() ) .
+ "&newtitle=" . wfUrlencode( $nt->getPrefixedText() ) .
+ "&talkmoved={$talkmoved}" );
$wgOut->redirect( $success );
}
$text = wfMsg( "pagemovedtext", $_REQUEST['oldtitle'], $_REQUEST['newtitle'] );
$wgOut->addWikiText( $text );
- if ( 1 == $_REQUEST['talkmoved'] ) {
+ $talkmoved = $_REQUEST['talkmoved'];
+ if ( 1 == $talkmoved ) {
$wgOut->addHTML( "\n<p>" . wfMsg( "talkpagemoved" ) );
- } elseif( 'invalid' == $_REQUEST['talkmoved'] ) {
+ } elseif( 'articleexists' == $talkmoved ) {
$wgOut->addHTML( "\n<p><strong>" . wfMsg( "talkexists" ) . "</strong>" );
} else {
$ot = Title::newFromURL( $_REQUEST['oldtitle'] );
if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
- $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagenotmoved" ) );
+ $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagenotmoved", wfMsg( $talkmoved ) ) );
}
}
}
-
- # Is the the existing target title valid?
-
- function isValidTarget()
- {
- $fname = "MovePageForm::isValidTarget";
-
- $sql = "SELECT cur_is_redirect,cur_text FROM cur " .
- "WHERE cur_id={$this->newid}";
- $res = wfQuery( $sql, DB_READ, $fname );
- $obj = wfFetchObject( $res );
-
- if ( 0 == $obj->cur_is_redirect ) { return false; }
-
- if ( preg_match( "/\\[\\[\\s*([^\\]]*)]]/", $obj->cur_text, $m ) ) {
- $rt = Title::newFromText( $m[1] );
- if ( 0 != strcmp( wfStrencode( $rt->getPrefixedDBkey() ),
- $this->oft ) ) {
- return false;
- }
- }
- $sql = "SELECT old_id FROM old WHERE old_namespace={$this->nns} " .
- "AND old_title='{$this->ndt}'";
- $res = wfQuery( $sql, DB_READ, $fname );
- if ( 0 != wfNumRows( $res ) ) { return false; }
-
- return true;
- }
-
- # Move page to title which is presently a redirect to the source
- # page. Handling link tables here is tricky.
-
- function moveOverExistingRedirect()
- {
- global $wgUser, $wgLinkCache, $wgUseSquid;
- $fname = "MovePageForm::moveOverExistingRedirect";
- $mt = wfMsg( "movedto" );
-
- # Change the name of the target page:
- $now = wfTimestampNow();
- $won = wfInvertTimestamp( $now );
- $sql = "UPDATE cur SET cur_touched='{$now}'," .
- "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
- "WHERE cur_id={$this->oldid}";
- wfQuery( $sql, DB_WRITE, $fname );
- $wgLinkCache->clearLink( $this->nft );
-
- # Repurpose the old redirect. We don't save it to history since
- # by definition if we've got here it's rather uninteresting.
- $sql = "UPDATE cur SET cur_touched='{$now}',cur_timestamp='{$now}',inverse_timestamp='${won}'," .
- "cur_namespace={$this->ons},cur_title='{$this->odt}'," .
- "cur_text='#REDIRECT [[{$this->nft}]]\n',cur_comment='" .
- "{$mt} \\\"{$this->nft}\\\"',cur_user='" . $wgUser->getID() .
- "',cur_minor_edit=0,cur_counter=0,cur_restrictions=''," .
- "cur_user_text='" . wfStrencode( $wgUser->getName() ) . "'," .
- "cur_is_redirect=1,cur_is_new=0 WHERE cur_id={$this->newid}";
- wfQuery( $sql, DB_WRITE, $fname );
- $wgLinkCache->clearLink( $this->oft );
-
- # Fix the redundant names for the past revisions of the target page.
- # The redirect should have no old revisions.
- $sql = "UPDATE old SET " .
- "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
- "old_namespace={$this->ons} AND old_title='{$this->odt}'";
- wfQuery( $sql, DB_WRITE, $fname );
-
- RecentChange::notifyMove( $now, $this->ot, $this->nt, $wgUser, $mt );
-
- # Swap links. Using MAXINT as a temp; if there's ever an article
- # with id 4294967295, this will fail, but I think that's pretty safe
-
- # FIXME: LOCK TABLE
- # Reassign links to the old title to LIMBO
- $sql = "UPDATE links SET l_to=4294967295 WHERE l_to={$this->oldid}";
- wfQuery( $sql, DB_WRITE, $fname );
-
- # Reassign links to the new title to the old title
- $sql = "UPDATE links SET l_to={$this->oldid} WHERE l_to={$this->newid}";
- wfQuery( $sql, DB_WRITE, $fname );
-
- # Reassign links from LIMBO to the new title. Ah, clear as mud!
- $sql = "UPDATE links SET l_to={$this->newid} WHERE l_to=4294967295";
- wfQuery( $sql, DB_WRITE, $fname );
-
- # Note: the insert below must be after the updates above!
-
- # Now, we record the link from the redirect to the new title.
- # It should have no other outgoing links...
- $sql = "DELETE FROM links WHERE l_from={$this->newid}";
- wfQuery( $sql, DB_WRITE, $fname );
- $sql = "INSERT INTO links (l_from,l_to) VALUES ({$this->newid},{$this->oldid})";
- wfQuery( $sql, DB_WRITE, $fname );
-
- # Purge squid
- if ( $wgUseSquid ) {
- $urls = array_merge( $this->nt->getSquidURLs(), $this->ot->getSquidURLs() );
- $u = new SquidUpdate( $urls );
- $u->doUpdate();
- }
- }
-
- # Move page to non-existing title.
-
- function moveToNewTitle()
- {
- global $wgUser, $wgLinkCache, $wgUseSquid;
- $fname = "MovePageForm::moveToNewTitle";
- $mt = wfMsg( "movedto" );
-
- $now = wfTimestampNow();
- $won = wfInvertTimestamp( $now );
- $sql = "UPDATE cur SET cur_touched='{$now}'," .
- "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
- "WHERE cur_id={$this->oldid}";
- wfQuery( $sql, DB_WRITE, $fname );
- $wgLinkCache->clearLink( $this->nft );
-
- $comment = "{$mt} \"{$this->nft}\"";
- $encComment = wfStrencode( $comment );
- $common = "{$this->ons},'{$this->odt}'," .
- "'$encComment','" .$wgUser->getID() . "','" .
- wfStrencode( $wgUser->getName() ) ."','{$now}'";
- $sql = "INSERT INTO cur (cur_namespace,cur_title," .
- "cur_comment,cur_user,cur_user_text,cur_timestamp,inverse_timestamp," .
- "cur_touched,cur_text,cur_is_redirect,cur_is_new) " .
- "VALUES ({$common},'{$won}','{$now}','#REDIRECT [[{$this->nft}]]\n',1,1)";
- wfQuery( $sql, DB_WRITE, $fname );
- $this->newid = wfInsertId();
- $wgLinkCache->clearLink( $this->oft );
-
- $sql = "UPDATE old SET " .
- "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
- "old_namespace={$this->ons} AND old_title='{$this->odt}'";
- wfQuery( $sql, DB_WRITE, $fname );
-
- RecentChange::notifyMove( $now, $this->ot, $this->nt, $wgUser, $comment );
- Article::onArticleCreate( $this->nt );
-
- # Any text links to the old title must be reassigned to the redirect
- $sql = "UPDATE links SET l_to={$this->newid} WHERE l_to={$this->oldid}";
- wfQuery( $sql, DB_WRITE, $fname );
-
- # Record the just-created redirect's linking to the page
- $sql = "INSERT INTO links (l_from,l_to) VALUES ({$this->newid},{$this->oldid})";
- wfQuery( $sql, DB_WRITE, $fname );
-
- # Non-existent target may have had broken links to it; these must
- # now be removed and made into good links.
- $update = new LinksUpdate( $this->oldid, $this->nft );
- $update->fixBrokenLinks();
-
- # Purge old title from squid
- # The new title, and links to the new title, are purged in Article::onArticleCreate()
- $titles = $this->nt->getLinksTo();
- if ( $wgUseSquid ) {
- $urls = $this->ot->getSquidURLs();
- foreach ( $titles as $linkTitle ) {
- $urls[] = $linkTitle->getInternalURL();
- }
- $u = new SquidUpdate( $urls );
- $u->doUpdate();
- }
- }
-
- function updateWatchlists()
- {
- $oldnamespace = $this->ons & ~1;
- $newnamespace = $this->nns & ~1;
- $oldtitle = $this->odt;
- $newtitle = $this->ndt;
-
- if( $oldnamespace == $newnamespace and $oldtitle == $newtitle )
- return;
-
- WatchedItem::duplicateEntries( $this->ot, $this->nt );
- }
-
}
?>
# Clean up whitespace
#
$t = preg_replace( "/[\\s_]+/", "_", $this->mDbkeyform );
- if ( "_" == $t{0} ) {
+ if ( "_" == @$t{0} ) {
$t = substr( $t, 1 );
}
$l = strlen( $t );
$this->getInternalURL( "action=history" )
);
}
+
+ function moveNoAuth( &$nt ) {
+ return $this->moveTo( $nt, false );
+ }
+
+ # Move a title to a new location
+ # Returns true on success, message name on failure
+ # auth indicates whether wgUser's permissions should be checked
+ function moveTo( &$nt, $auth = true ) {
+ $fname = "Title::move";
+ $oldid = $this->getArticleID();
+ $newid = $nt->getArticleID();
+
+ if( !$this or !$nt ) {
+ return "badtitletext";
+ }
+
+ if ( strlen( $nt->getDBkey() ) < 1 ) {
+ return "articleexists";
+ }
+ if ( ( ! Namespace::isMovable( $this->getNamespace() ) ) ||
+ ( "" == $this->getDBkey() ) ||
+ ( "" != $this->getInterwiki() ) ||
+ ( !$oldid ) ||
+ ( ! Namespace::isMovable( $nt->getNamespace() ) ) ||
+ ( "" == $nt->getDBkey() ) ||
+ ( "" != $nt->getInterwiki() ) ) {
+ return "badarticleerror";
+ }
+
+ if ( $auth && ( !$this->userCanEdit() || !$nt->userCanEdit() ) ) {
+ return "protectedpage";
+ }
+
+ # The move is allowed only if (1) the target doesn't exist, or
+ # (2) the target is a redirect to the source, and has no history
+ # (so we can undo bad moves right after they're done).
+
+ if ( 0 != $newid ) { # Target exists; check for validity
+ if ( ! $this->isValidMoveTarget( $nt ) ) {
+ return "articleexists";
+ }
+ $this->moveOverExistingRedirect( $nt );
+ } else { # Target didn't exist, do normal move.
+ $this->moveToNewTitle( $nt, $newid );
+ }
+
+ # Update watchlists
+
+ $oldnamespace = $this->getNamespace() & ~1;
+ $newnamespace = $nt->getNamespace() & ~1;
+ $oldtitle = $this->getDBkey();
+ $newtitle = $nt->getDBkey();
+
+ if( $oldnamespace != $newnamespace && $oldtitle != $newtitle ) {
+ WatchedItem::duplicateEntries( $this, $nt );
+ }
+
+ # Update search engine
+ $u = new SearchUpdate( $oldid, $nt->getPrefixedDBkey() );
+ $u->doUpdate();
+ $u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), "" );
+ $u->doUpdate();
+
+ return true;
+ }
+
+ # Move page to title which is presently a redirect to the source page
+
+ /* private */ function moveOverExistingRedirect( &$nt )
+ {
+ global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
+ $fname = "Title::moveOverExistingRedirect";
+ $comment = wfMsg( "1movedto2", $this->getPrefixedText(), $nt->getPrefixedText() );
+
+ $now = wfTimestampNow();
+ $won = wfInvertTimestamp( $now );
+ $newid = $nt->getArticleID();
+ $oldid = $this->getArticleID();
+
+ # Change the name of the target page:
+ wfUpdateArray(
+ /* table */ 'cur',
+ /* SET */ array(
+ 'cur_touched' => $now,
+ 'cur_namespace' => $nt->getNamespace(),
+ 'cur_title' => $nt->getDBkey()
+ ),
+ /* WHERE */ array( 'cur_id' => $oldid ),
+ $fname
+ );
+ $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
+
+ # Repurpose the old redirect. We don't save it to history since
+ # by definition if we've got here it's rather uninteresting.
+
+ $redirectText = $wgMwRedir->getSynonym( 0 ) . " [[" . $nt->getPrefixedText() . "]]\n";
+ wfUpdateArray(
+ /* table */ 'cur',
+ /* SET */ array(
+ 'cur_touched' => $now,
+ 'cur_timestamp' => $now,
+ 'inverse_timestamp' => $won,
+ 'cur_namespace' => $this->getNamespace(),
+ 'cur_title' => $this->getDBkey(),
+ 'cur_text' => $wgMwRedir->getSynonym( 0 ) . " [[" . $nt->getPrefixedText() . "]]\n",
+ 'cur_comment' => $comment,
+ 'cur_user' => $wgUser->getID(),
+ 'cur_minor_edit' => 0,
+ 'cur_counter' => 0,
+ 'cur_restrictions' => '',
+ 'cur_user_text' => $wgUser->getName(),
+ 'cur_is_redirect' => 1,
+ 'cur_is_new' => 1
+ ),
+ /* WHERE */ array( 'cur_id' => $newid ),
+ $fname
+ );
+
+ $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
+
+ # Fix the redundant names for the past revisions of the target page.
+ # The redirect should have no old revisions.
+ wfUpdateArray(
+ /* table */ 'old',
+ /* SET */ array(
+ 'old_namespace' => $nt->getNamespace(),
+ 'old_title' => $nt->getDBkey(),
+ ),
+ /* WHERE */ array(
+ 'old_namespace' => $this->getNamespace(),
+ 'old_title' => $this->getDBkey(),
+ ),
+ $fname
+ );
+
+ RecentChange::notifyMove( $now, $this, $nt, $wgUser, $comment );
+
+ # Swap links
+
+ # Load titles and IDs
+ $linksToOld = $this->getLinksTo();
+ $linksToNew = $nt->getLinksTo();
+
+ # Make function to convert Titles to IDs
+ $titleToID = create_function('$t', 'return $t->getArticleID();');
+
+ # Reassign links to old title
+ if ( count( $linksToOld ) ) {
+ $sql = "UPDATE links SET l_to=$newid WHERE l_from IN (";
+ $sql .= implode( ",", array_map( $titleToID, $linksToOld ) );
+ $sql .= ")";
+ wfQuery( $sql, DB_WRITE, $fname );
+ }
+
+ # Reassign links to new title
+ if ( count( $linksToNew ) ) {
+ $sql = "UPDATE links SET l_to=$oldid WHERE l_from IN (";
+ $sql .= implode( ",", array_map( $titleToID, $linksToNew ) );
+ $sql .= ")";
+ wfQuery( $sql, DB_WRITE, $fname );
+ }
+
+ # Note: the insert below must be after the updates above!
+
+ # Now, we record the link from the redirect to the new title.
+ # It should have no other outgoing links...
+ $sql = "DELETE FROM links WHERE l_from={$newid}";
+ wfQuery( $sql, DB_WRITE, $fname );
+ $sql = "INSERT INTO links (l_from,l_to) VALUES ({$newid},{$oldid})";
+ wfQuery( $sql, DB_WRITE, $fname );
+
+ # Purge squid
+ if ( $wgUseSquid ) {
+ $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
+ $u = new SquidUpdate( $urls );
+ $u->doUpdate();
+ }
+ }
+
+ # Move page to non-existing title.
+ # Sets $newid to be the new article ID
+
+ /* private */ function moveToNewTitle( &$nt, &$newid )
+ {
+ global $wgUser, $wgLinkCache, $wgUseSquid;
+ $fname = "MovePageForm::moveToNewTitle";
+ $comment = wfMsg( "1movedto2", $this->getPrefixedText(), $nt->getPrefixedText() );
+
+ $now = wfTimestampNow();
+ $won = wfInvertTimestamp( $now );
+ $newid = $nt->getArticleID();
+ $oldid = $this->getArticleID();
+
+ # Rename cur entry
+ wfUpdateArray(
+ /* table */ 'cur',
+ /* SET */ array(
+ 'cur_touched' => $now,
+ 'cur_namespace' => $nt->getNamespace(),
+ 'cur_title' => $nt->getDBkey()
+ ),
+ /* WHERE */ array( 'cur_id' => $oldid ),
+ $fname
+ );
+
+ $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
+
+ # Insert redirct
+ wfInsertArray( 'cur', array(
+ 'cur_namespace' => $this->getNamespace(),
+ 'cur_title' => $this->getDBkey(),
+ 'cur_comment' => $comment,
+ 'cur_user' => $wgUser->getID(),
+ 'cur_user_text' => $wgUser->getName(),
+ 'cur_timestamp' => $now,
+ 'inverse_timestamp' => $won,
+ 'cur_touched' => $now,
+ 'cur_is_redirect' => 1,
+ 'cur_is_new' => 1,
+ 'cur_text' => "#REDIRECT [[" . $nt->getPrefixedText() . "]]\n" )
+ );
+ $newid = wfInsertId();
+ $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
+
+ # Rename old entries
+ wfUpdateArray(
+ /* table */ 'old',
+ /* SET */ array(
+ 'old_namespace' => $nt->getNamespace(),
+ 'old_title' => $nt->getDBkey()
+ ),
+ /* WHERE */ array(
+ 'old_namespace' => $this->getNamespace(),
+ 'old_title' => $this->getDBkey()
+ ), $fname
+ );
+
+ # Miscellaneous updates
+
+ RecentChange::notifyMove( $now, $this, $nt, $wgUser, $comment );
+ Article::onArticleCreate( $nt );
+
+ # Any text links to the old title must be reassigned to the redirect
+ $sql = "UPDATE links SET l_to={$newid} WHERE l_to={$oldid}";
+ wfQuery( $sql, DB_WRITE, $fname );
+
+ # Record the just-created redirect's linking to the page
+ $sql = "INSERT INTO links (l_from,l_to) VALUES ({$newid},{$oldid})";
+ wfQuery( $sql, DB_WRITE, $fname );
+
+ # Non-existent target may have had broken links to it; these must
+ # now be removed and made into good links.
+ $update = new LinksUpdate( $oldid, $nt->getPrefixedDBkey() );
+ $update->fixBrokenLinks();
+
+ # Purge old title from squid
+ # The new title, and links to the new title, are purged in Article::onArticleCreate()
+ $titles = $nt->getLinksTo();
+ if ( $wgUseSquid ) {
+ $urls = $this->getSquidURLs();
+ foreach ( $titles as $linkTitle ) {
+ $urls[] = $linkTitle->getInternalURL();
+ }
+ $u = new SquidUpdate( $urls );
+ $u->doUpdate();
+ }
+ }
+
+ # Checks if $this can be moved to $nt
+ # Both titles must exist in the database, otherwise it will blow up
+ function isValidMoveTarget( $nt )
+ {
+ $fname = "Title::isValidMoveTarget";
+
+ # Is it a redirect?
+ $id = $nt->getArticleID();
+ $sql = "SELECT cur_is_redirect,cur_text FROM cur " .
+ "WHERE cur_id={$id}";
+ $res = wfQuery( $sql, DB_READ, $fname );
+ $obj = wfFetchObject( $res );
+
+ if ( 0 == $obj->cur_is_redirect ) {
+ # Not a redirect
+ return false;
+ }
+
+ # Does the redirect point to the source?
+ if ( preg_match( "/\\[\\[\\s*([^\\]]*)]]/", $obj->cur_text, $m ) ) {
+ $redirTitle = Title::newFromText( $m[1] );
+ if ( 0 != strcmp( $redirTitle->getPrefixedDBkey(), $this->getPrefixedDBkey() ) ) {
+ return false;
+ }
+ }
+
+ # Does the article have a history?
+ $row = wfGetArray( 'old', array( 'old_id' ), array(
+ 'old_namespace' => $nt->getNamespace(),
+ 'old_title' => $nt->getDBkey() )
+ );
+
+ # Return true if there was no history
+ return $row === false;
+ }
}
?>