Modification to moveCustomMessages.php to create redirects, related modifications...
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 23 Mar 2004 12:05:40 +0000 (12:05 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 23 Mar 2004 12:05:40 +0000 (12:05 +0000)
includes/Title.php
maintenance/archives/moveCustomMessages.php
maintenance/commandLine.inc

index 3de57d4..86a3f7d 100644 (file)
@@ -1043,5 +1043,49 @@ class Title {
                # 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;
+       }
 }
 ?>
index 02c2421..e87ae2c 100644 (file)
@@ -1,45 +1,82 @@
 <?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";
-}
 
 ?>
index 216ee9c..a103d11 100644 (file)
@@ -8,7 +8,7 @@ if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
 $wgCommandLineMode = true;
 
 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
-if ( @$argv[1] ) {
+if ( @$argv[1] && @$argv[1] != "-" ) {
        $lang = $argv[1];
        putenv( "wikilang=$lang");
        $settingsFile = "/apache/htdocs/{$argv[1]}/w/LocalSettings.php";