# Return true if there was no history
return $row === false;
}
+
+ # Create a redirect, fails if the title already exists, does not notify RC
+ # Returns success
+ function createRedirect( $dest, $comment ) {
+ global $wgUser;
+ if ( $this->getArticleID() ) {
+ return false;
+ }
+
+ $now = wfTimestampNow();
+ $won = wfInvertTimestamp( $now );
+
+ 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 [[" . $dest->getPrefixedText() . "]]\n"
+ ));
+ $newid = wfInsertId();
+ $this->resetArticleID( $newid );
+
+ # Link table
+ if ( $dest->getArticleID() ) {
+ wfInsertArray( 'links', array(
+ 'l_to' => $dest->getArticleID(),
+ 'l_from' => $newid
+ ));
+ } else {
+ wfInsertArray( 'brokenlinks', array(
+ 'bl_to' => $dest->getPrefixedDBkey(),
+ 'bl_from' => $newid
+ ));
+ }
+
+ Article::onArticleCreate( $this );
+ return true;
+ }
}
?>
<?php
# Move "custom messages" from the MediaWiki namespace to the Template namespace
+# Usage: php moveCustomMessages.php [<lang>] [skipredir]
+
chdir( ".." );
include_once( "commandLine.inc" );
+if ( @$argv[2] == "1" ) {
+ $doRedirects = true;
+ $doMove = false;
+} elseif ( @$argv[2] == "2" ) {
+ $doRedirects = false;
+ $doMove = true;
+} else {
+ $doRedirects = true;
+ $doMove = true;
+}
+
+$wgUser = User::newFromName( "Template namespace initialisation script" );
+
# Compose DB key array
global $wgAllMessagesEn;
$dbkeys = array();
-foreach ( $wgAllMessagesEn as $key => $enValue )
-{
+foreach ( $wgAllMessagesEn as $key => $enValue ) {
$title = Title::newFromText( $key );
$dbkeys[$title->getDBkey()] = 1;
}
$sql = "SELECT cur_id, cur_title FROM cur WHERE cur_namespace= " . NS_MEDIAWIKI;
$res = wfQuery( $sql, DB_READ );
-$first = true;
+
+# Compile target array
+$targets = array();
while ( $row = wfFetchObject( $res ) ) {
- $partial = $row->cur_title;
- print "$partial...";
- if ( !array_key_exists( $partial, $dbkeys ) ) {
+ if ( !array_key_exists( $row->cur_title, $dbkeys ) ) {
+ $targets[] = $row->cur_title;
+ }
+}
+wfFreeResult( $res );
+
+# Create redirects from destination to source
+if ( $doRedirects ) {
+ foreach ( $targets as $partial ) {
+ print "$partial...";
+ $nt = Title::makeTitle( NS_TEMPLATE, $partial );
+ $ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
+
+ if ( $nt->createRedirect( $ot, "" ) ) {
+ print "redirected\n";
+ } else {
+ print "not redirected\n";
+ }
+ }
+ if ( $doMove ) {
+ print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n";
+ readconsole();
+ }
+}
+
+# Move pages
+if ( $doMove ) {
+ foreach ( $targets as $partial ) {
$ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
$nt = Title::makeTitle( NS_TEMPLATE, $partial );
+ print "$partial...";
+
if ( $ot->moveNoAuth( $nt ) === true ) {
print "moved\n";
} else {
print "not moved\n";
}
- # Clear deferred updates
+ # Do deferred updates
while ( count( $wgDeferredUpdateList ) ) {
$up = array_pop( $wgDeferredUpdateList );
$up->doUpdate();
}
- $first = false;
- } else {
- print "internal\n";
}
}
-if ( $first ) {
- print "Nothing to move\n";
-}
?>