links schema conversion script, alterations to config/index.php and commandLine.inc...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 12 Apr 2004 07:16:43 +0000 (07:16 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 12 Apr 2004 07:16:43 +0000 (07:16 +0000)
config/index.php
maintenance/commandLine.inc
maintenance/convertLinks.php [new file with mode: 0644]

index 8509393..bd8e629 100644 (file)
@@ -633,8 +633,10 @@ function writeLocalSettings( $conf ) {
 ini_set( \"include_path\", \"\$IP/includes$sep\$IP/languages$sep\" . ini_get(\"include_path\") );
 include_once( \"DefaultSettings.php\" );
 
-if( \$wgCommandLineMode ) {
-       die( \"Can't use command-line utils with in-place install yet, sorry.\" );
+if ( \$wgCommandLineMode ) {
+       if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
+               die( \"This script must be run from the command line\\n\" );
+       }
 } else {
        ## Compress output if the browser supports it
        {$zlib}if( !ini_get( 'zlib.output_compression' ) ) ob_start( 'ob_gzhandler' );
index a103d11..d43bc0d 100644 (file)
@@ -30,6 +30,7 @@ $DP = "../includes";
 include_once( $settingsFile );
 ini_set( "include_path", "../includes$sep../languages$sep$newpath$IP$sep$include_path" );
 
+$wgUsePHPTal = false;
 include_once( "Setup.php" );
 include_once( "./InitialiseMessages.inc" );
 include_once( "../install-utils.inc" );
diff --git a/maintenance/convertLinks.php b/maintenance/convertLinks.php
new file mode 100644 (file)
index 0000000..5f55541
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+
+# Convert from the old links schema (string->ID) to the new schema (ID->ID)
+# This hasn't been tested yet, so expect bugs
+
+# The wiki should be put into read-only mode while this script executes
+
+include_once( "commandLine.inc" );
+
+# Check if it's already done
+
+$res = wfQuery( "SELECT * FROM links LIMIT 1", DB_WRITE );
+if ( !wfNumRows( $res ) ) {
+       print "No rows to convert. Updating schema...\n";
+       createTable();
+} else {
+       $row = wfFetchObject( $res );
+       if ( is_numeric( $row->l_from ) ) {
+               print "Schema already converted\n";
+               exit;
+       }
+       
+       # Create a title -> cur_id map
+
+       print "Loading IDs...";
+
+       wfBufferSQLResults( false );
+       $res = wfQuery( "SELECT cur_namespace,cur_title,cur_id FROM cur", DB_WRITE );
+       $ids = array();
+
+       while ( $row = wfFetchObject( $res ) ) {
+               $title = $row->cur_title;
+               if ( $row->cur_namespace ) {
+                       $title = $wgLang->getNsText( $row->cur_namespace ) . ":$title";
+               }
+               $ids[$title] = $row->cur_id;
+       }
+       wfFreeResult( $res );
+
+       print "done\n";
+
+       # Now, load in all the links and create a links table in RAM
+       print "Processing links...\n";
+       $res = wfQuery( "SELECT * FROM links", DB_WRITE );
+       $links = array();
+       $numBad = 0;
+
+       while ( $row = wfFetchObject( $res ) ) {
+               if ( array_key_exists( $row->l_from, $ids ) ) {
+                       $links[$ids[$row->l_from]] = $row->l_to;
+               } else {
+                       $numBad ++;
+               }
+       }
+
+       print "Done, $numBad invalid titles\n";
+
+       # Save it to a new table
+       createTable();
+       $sql = "INSERT INTO links_temp(l_from,l_to) VALUES ";
+
+       $first = true;
+       foreach( $links as $from => $to ) {
+               if ( $first ) {
+                       $first = false;
+               } else {
+                       $sql .= ",";
+               }
+               $sql .= "($from,$to)";
+       }
+
+       wfQuery( $sql, DB_WRITE );
+}
+
+# Swap in the new table
+wfQuery( "RENAME TABLE links TO links_backup, links_temp TO links" );
+
+print "Conversion complete. The old table remains at links_backup, delete at your leisure.\n";
+
+function createTable() {
+       wfQuery( "CREATE TABLE links_temp (
+         l_from int(8) unsigned NOT NULL default '0',
+         l_to int(8) unsigned NOT NULL default '0',
+         UNIQUE KEY l_from(l_from,l_to),
+         KEY (l_to))", DB_WRITE);
+}
+
+?>