various changes aimed at making a bare-bones 1.3 command line installer, for wikimedia
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 22 May 2004 02:47:30 +0000 (02:47 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 22 May 2004 02:47:30 +0000 (02:47 +0000)
maintenance/archives/moveCustomMessages.inc [new file with mode: 0644]
maintenance/archives/moveCustomMessages.php
maintenance/convertLinks.inc [new file with mode: 0644]
maintenance/convertLinks.php
maintenance/trivialCmdLine.php [new file with mode: 0644]
maintenance/update2.php [new file with mode: 0644]

diff --git a/maintenance/archives/moveCustomMessages.inc b/maintenance/archives/moveCustomMessages.inc
new file mode 100644 (file)
index 0000000..8ad118d
--- /dev/null
@@ -0,0 +1,127 @@
+<?
+
+function moveCustomMessages( $phase ) {
+       global $wgUser, $wgAllMessagesEn, $wgDeferredUpdateList, $wgLang ;
+       $wgUser = new User;
+       $wgUser->setLoaded( true ); # Don't load from DB
+       $wgUser->setName( "Template namespace initialisation script" );
+       $wgUser->addRight( "bot" );
+
+       # Compose DB key array
+       $dbkeys = array();
+
+       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 );
+
+       # Compile target array
+       $targets = array();
+       while ( $row = wfFetchObject( $res ) ) {
+               if ( !array_key_exists( $row->cur_title, $dbkeys ) ) {
+                       $targets[$row->cur_title] = 1;
+               }
+       }
+       wfFreeResult( $res );
+
+       # Create redirects from destination to source
+       if ( $phase == 0 || $phase == 1 ) {
+               foreach ( $targets as $partial => $dummy ) {
+                       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 ( $phase == 0 ) {
+                       print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n";
+                       readconsole();
+               }
+       }
+
+       # Move pages
+       if ( $phase == 0 || $phase == 2 ) {
+               print "\n";
+               foreach ( $targets as $partial => $dummy ) {
+                       $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";
+                       }
+                       # Do deferred updates
+                       while ( count( $wgDeferredUpdateList ) ) {
+                               $up = array_pop( $wgDeferredUpdateList );
+                               $up->doUpdate();
+                       }
+               }
+       }
+
+       # Convert text
+       if ( $phase == 0 || $phase == 3 ) {
+               print "\n";
+               
+               $parser = new Parser;
+               $options = ParserOptions::newFromUser( $wgUser );
+               $completedTitles = array();
+               $titleChars = Title::legalChars();
+               $mediaWiki = $wgLang->getNsText( NS_MEDIAWIKI );
+               $template = $wgLang->getNsText( NS_TEMPLATE );
+               $linkRegex = "/\[\[$mediaWiki:([$titleChars]*?)\]\]/";
+               $msgRegex = "/{{msg:([$titleChars]*?)}}/";
+
+               foreach ( $targets as $partial => $dummy ) {
+                       $dest = Title::makeTitle( NS_TEMPLATE, $partial );
+                       $linksTo = $dest->getLinksTo();
+                       foreach( $linksTo as $source ) {
+                               $pdbk = $source->getPrefixedDBkey();
+                               print "$pdbk...";
+                               if ( !array_key_exists( $pdbk, $completedTitles ) ) {   
+                                       $completedTitles[$pdbk] = 1;
+                                       $id = $source->getArticleID();
+                                       $row = wfGetArray( 'cur', array( 'cur_text' ), 
+                                               array( 'cur_id' => $source->getArticleID() ) );
+                                       $parser->startExternalParse( $source, $options, OT_WIKI );
+                                       $text = $parser->strip( $row->cur_text, $stripState, false );
+                                       # {{msg}} -> {{}}
+                                       $text = preg_replace( $msgRegex, "{{\$1}}", $text );
+                                       # [[MediaWiki:]] -> [[Template:]]
+                                       $text = preg_replace_callback( $linkRegex, "wfReplaceMediaWiki", $text );
+                                       $text = $parser->unstrip( $text, $stripState );
+                                       if ( $text != $row->cur_text ) {
+                                               wfUpdateArray( 'cur', array( 'cur_text' => $text ), array( 'cur_id' => $id ) );
+                                               print "modified\n";
+                                       } else {
+                                               print "not modified\n";
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+
+#--------------------------------------------------------------------------------------------------------------
+function wfReplaceMediaWiki( $m ) {
+       global $targets, $template, $replaceCount;
+       $title = Title::newFromText( $m[1] );
+       $partial = $title->getDBkey();
+
+       if ( array_key_exists( $partial, $targets ) ) {
+               $text = "[[$template:{$m[1]}]]";
+       } else {
+               $text = $m[0];
+       }
+       return $text;
+}
+
index bcd4974..bfb7613 100644 (file)
 
 chdir( ".." );
 require_once( "commandLine.inc" );
+require_once( "moveCustomMessages.inc" );
 
 $phase = 0;
 if ( is_numeric( @$argv[2] ) && $argv[2] > 0) {
        $phase = intval($argv[2]);
 }
 
-$wgUser = new User;
-$wgUser->setLoaded( true ); # Don't load from DB
-$wgUser->setName( "Template namespace initialisation script" );
-$wgUser->addRight( "bot" );
+moveCustomMessages( $phase );
 
-# Compose DB key array
-global $wgAllMessagesEn;
-$dbkeys = array();
-
-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 );
-
-# Compile target array
-$targets = array();
-while ( $row = wfFetchObject( $res ) ) {
-       if ( !array_key_exists( $row->cur_title, $dbkeys ) ) {
-               $targets[$row->cur_title] = 1;
-       }
-}
-wfFreeResult( $res );
-
-# Create redirects from destination to source
-if ( $phase == 0 || $phase == 1 ) {
-       foreach ( $targets as $partial => $dummy ) {
-               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 ( $phase == 0 ) {
-               print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n";
-               readconsole();
-       }
-}
-
-# Move pages
-if ( $phase == 0 || $phase == 2 ) {
-       print "\n";
-       foreach ( $targets as $partial => $dummy ) {
-               $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";
-               }
-               # Do deferred updates
-               while ( count( $wgDeferredUpdateList ) ) {
-                       $up = array_pop( $wgDeferredUpdateList );
-                       $up->doUpdate();
-               }
-       }
-}
-
-# Convert text
-if ( $phase == 0 || $phase == 3 ) {
-       print "\n";
-       
-       $parser = new Parser;
-       $options = ParserOptions::newFromUser( $wgUser );
-       $completedTitles = array();
-       $titleChars = Title::legalChars();
-       $mediaWiki = $wgLang->getNsText( NS_MEDIAWIKI );
-       $template = $wgLang->getNsText( NS_TEMPLATE );
-       $linkRegex = "/\[\[$mediaWiki:([$titleChars]*?)\]\]/";
-       $msgRegex = "/{{msg:([$titleChars]*?)}}/";
-
-       foreach ( $targets as $partial => $dummy ) {
-               $dest = Title::makeTitle( NS_TEMPLATE, $partial );
-               $linksTo = $dest->getLinksTo();
-               foreach( $linksTo as $source ) {
-                       $pdbk = $source->getPrefixedDBkey();
-                       print "$pdbk...";
-                       if ( !array_key_exists( $pdbk, $completedTitles ) ) {   
-                               $completedTitles[$pdbk] = 1;
-                               $id = $source->getArticleID();
-                               $row = wfGetArray( 'cur', array( 'cur_text' ), 
-                                       array( 'cur_id' => $source->getArticleID() ) );
-                               $parser->startExternalParse( $source, $options, OT_WIKI );
-                               $text = $parser->strip( $row->cur_text, $stripState, false );
-                               # {{msg}} -> {{}}
-                               $text = preg_replace( $msgRegex, "{{\$1}}", $text );
-                               # [[MediaWiki:]] -> [[Template:]]
-                               $text = preg_replace_callback( $linkRegex, "wfReplaceMediaWiki", $text );
-                               $text = $parser->unstrip( $text, $stripState );
-                               if ( $text != $row->cur_text ) {
-                                       wfUpdateArray( 'cur', array( 'cur_text' => $text ), array( 'cur_id' => $id ) );
-                                       print "modified\n";
-                               } else {
-                                       print "not modified\n";
-                               }
-                       }
-               }
-       }
-}
-
-#--------------------------------------------------------------------------------------------------------------
-function wfReplaceMediaWiki( $m ) {
-       global $targets, $template, $replaceCount;
-       $title = Title::newFromText( $m[1] );
-       $partial = $title->getDBkey();
-
-       if ( array_key_exists( $partial, $targets ) ) {
-               $text = "[[$template:{$m[1]}]]";
-       } else {
-               $text = $m[0];
-       }
-       return $text;
-}
 ?>
diff --git a/maintenance/convertLinks.inc b/maintenance/convertLinks.inc
new file mode 100644 (file)
index 0000000..a2acf67
--- /dev/null
@@ -0,0 +1,198 @@
+<?php
+
+function convertLinks() {
+       global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+       
+       $numRows = $tuplesAdded = $numBadLinks = $curRowsRead = 0; #counters etc
+       $totalTuplesInserted = 0; # total tuples INSERTed into links_temp
+
+       $reportCurReadProgress = true; #whether or not to give progress reports while reading IDs from cur table
+       $curReadReportInterval = 1000; #number of rows between progress reports
+
+       $reportLinksConvProgress = true; #whether or not to give progress reports during conversion
+       $linksConvInsertInterval = 1000; #number of rows per INSERT
+
+       $initialRowOffset = 0;
+       #$finalRowOffset = 0; # not used yet; highest row number from links table to process
+
+       # Overwrite the old links table with the new one.  If this is set to false,
+       # the new table will be left at links_temp.
+       $overwriteLinksTable = true;
+
+       # Don't create keys, and so allow duplicates in the new links table.
+       # This gives a huge speed improvement for very large links tables which are MyISAM. (What about InnoDB?)
+       $noKeys = false;
+
+
+       $logPerformance = false; # output performance data to a file
+       $perfLogFilename = "convLinksPerf.txt";
+       #--------------------------------------------------------------------
+
+       $res = wfQuery( "SELECT COUNT(*) AS count FROM links", DB_WRITE );
+       $row = wfFetchObject($res);
+       $numRows = $row->count;
+       wfFreeResult( $res );
+
+       if ( $numRows == 0 ) {
+               print "No rows to convert. Updating schema...\n";
+               createTempTable();
+       } else {
+               $row = wfFetchObject( $res );
+               if ( is_numeric( $row->l_from ) ) {
+                       print "Schema already converted\n";
+                       exit;
+               }
+               
+               if ( $logPerformance ) { $fh = fopen ( $perfLogFilename, "w" ); }
+               $baseTime = $startTime = getMicroTime();
+               # Create a title -> cur_id map
+               print "Loading IDs from cur table...\n";
+               performanceLog ( "Reading $numRows rows from cur table...\n" );
+               performanceLog ( "rows read vs seconds elapsed:\n" );
+               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;
+                       $curRowsRead++;
+                       if ($reportCurReadProgress) {
+                               if (($curRowsRead % $curReadReportInterval) == 0) {
+                                       performanceLog( $curRowsRead . " " . (getMicroTime() - $baseTime) . "\n" );
+                                       print "\t$curRowsRead rows of cur table read.\n";       
+                               }
+                       }
+               }
+               wfFreeResult( $res );
+               wfBufferSQLResults( true );
+               print "Finished loading IDs.\n\n";
+               performanceLog( "Took " . (getMicroTime() - $baseTime) . " seconds to load IDs.\n\n" );
+       #--------------------------------------------------------------------
+
+               # Now, step through the links table (in chunks of $linksConvInsertInterval rows),
+               # convert, and write to the new table.
+               createTempTable();
+               performanceLog( "Resetting timer.\n\n" );
+               $baseTime = getMicroTime();
+               print "Processing $numRows rows from links table...\n";
+               performanceLog( "Processing $numRows rows from links table...\n" );
+               performanceLog( "rows inserted vs seconds elapsed:\n" );
+               
+               for ($rowOffset = $initialRowOffset; $rowOffset < $numRows; $rowOffset += $linksConvInsertInterval) {
+                       $sqlRead = "SELECT * FROM links LIMIT $linksConvInsertInterval OFFSET $rowOffset";
+                       $res = wfQuery($sqlRead, DB_READ);
+                       if ( $noKeys ) {
+                               $sqlWrite = array("INSERT INTO links_temp(l_from,l_to) VALUES ");
+                       } else {
+                               $sqlWrite = array("INSERT IGNORE INTO links_temp(l_from,l_to) VALUES ");
+                       }
+                       
+                       $tuplesAdded = 0; # no tuples added to INSERT yet
+                       while ( $row = wfFetchObject($res) ) {
+                               $fromTitle = $row->l_from; 
+                               if ( array_key_exists( $fromTitle, $ids ) ) { # valid title
+                                       $from = $ids[$fromTitle];
+                                       $to = $row->l_to;
+                                       if ( $tuplesAdded != 0 ) {
+                                               $sqlWrite[] = ",";
+                                       }
+                                       $sqlWrite[] = "($from,$to)";
+                                       $tuplesAdded++;                         
+                               } else { # invalid title
+                                       $numBadLinks++;
+                               }
+                       }
+                       wfFreeResult($res);
+                       #print "rowOffset: $rowOffset\ttuplesAdded: $tuplesAdded\tnumBadLinks: $numBadLinks\n";
+                       if ( $tuplesAdded != 0  ) {
+                               if ($reportLinksConvProgress) {
+                                       print "Inserting $tuplesAdded tuples into links_temp...";
+                               }
+                               wfQuery( implode("",$sqlWrite) , DB_WRITE );
+                               $totalTuplesInserted += $tuplesAdded;
+                               if ($reportLinksConvProgress)
+                                       print " done. Total $totalTuplesInserted tuples inserted.\n";
+                                       performanceLog( $totalTuplesInserted . " " . (getMicroTime() - $baseTime) . "\n"  );
+                       }
+               }
+               print "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n\n";
+               performanceLog( "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n" );
+               performanceLog( "Total execution time: " . (getMicroTime() - $startTime) . " seconds.\n" );
+               if ( $logPerformance ) { fclose ( $fh ); }
+       }
+       #--------------------------------------------------------------------
+
+       if ( $overwriteLinksTable ) {
+               $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+               if (!($dbConn->isOpen())) {
+                       print "Opening connection to database failed.\n";
+                       exit;
+               }
+               # Check for existing links_backup, and delete it if it exists.
+               print "Dropping backup links table if it exists...";
+               $dbConn->query( "DROP TABLE IF EXISTS links_backup", DB_WRITE);
+               print " done.\n";
+               
+               # Swap in the new table, and move old links table to links_backup
+               print "Swapping tables 'links' to 'links_backup'; 'links_temp' to 'links'...";
+               $dbConn->query( "RENAME TABLE links TO links_backup, links_temp TO links", DB_WRITE );
+               print " done.\n\n";
+               
+               $dbConn->close();
+               print "Conversion complete. The old table remains at links_backup;\n";
+               print "delete at your leisure.\n";
+       } else {
+               print "Conversion complete.  The converted table is at links_temp;\n";
+               print "the original links table is unchanged.\n";
+       }
+
+#--------------------------------------------------------------------
+
+function createTempTable() {
+       global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+       global $noKeys;
+       $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+       
+       if (!($dbConn->isOpen())) {
+               print "Opening connection to database failed.\n";
+               exit;
+       }
+       
+       print "Dropping temporary links table if it exists...";
+       $dbConn->query( "DROP TABLE IF EXISTS links_temp", DB_WRITE);
+       print " done.\n";
+       
+       print "Creating temporary links table...";
+       if ( $noKeys ) {
+               $dbConn->query( "CREATE TABLE links_temp ( " .
+               "l_from int(8) unsigned NOT NULL default '0', " .
+               "l_to int(8) unsigned NOT NULL default '0')", DB_WRITE);
+       } else {
+               $dbConn->query( "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);
+       }
+       print " done.\n\n";
+}
+
+function performanceLog( $text ) {
+       global $logPerformance, $fh;
+       if ( $logPerformance ) {
+               fwrite( $fh, $text );
+       }
+}
+
+function getMicroTime() { # return time in seconds, with microsecond accuracy
+       list($usec, $sec) = explode(" ", microtime());
+       return ((float)$usec + (float)$sec);
+}
+
+
+
+?>
index 8e3bb51..62b41eb 100644 (file)
@@ -5,194 +5,8 @@
 require_once( "commandLine.inc" );
 # the below should probably be moved into commandLine.inc at some point
 require_once( "../AdminSettings.php" );
+require_once( "convertLinks.inc" );
 
-$numRows = $tuplesAdded = $numBadLinks = $curRowsRead = 0; #counters etc
-$totalTuplesInserted = 0; # total tuples INSERTed into links_temp
+convertLinks();
 
-$reportCurReadProgress = true; #whether or not to give progress reports while reading IDs from cur table
-$curReadReportInterval = 1000; #number of rows between progress reports
-
-$reportLinksConvProgress = true; #whether or not to give progress reports during conversion
-$linksConvInsertInterval = 1000; #number of rows per INSERT
-
-$initialRowOffset = 0;
-#$finalRowOffset = 0; # not used yet; highest row number from links table to process
-
-# Overwrite the old links table with the new one.  If this is set to false,
-# the new table will be left at links_temp.
-$overwriteLinksTable = true;
-
-# Don't create keys, and so allow duplicates in the new links table.
-# This gives a huge speed improvement for very large links tables which are MyISAM. (What about InnoDB?)
-$noKeys = false;
-
-
-$logPerformance = false; # output performance data to a file
-$perfLogFilename = "convLinksPerf.txt";
-#--------------------------------------------------------------------
-
-$res = wfQuery( "SELECT COUNT(*) AS count FROM links", DB_WRITE );
-$row = wfFetchObject($res);
-$numRows = $row->count;
-wfFreeResult( $res );
-
-if ( $numRows == 0 ) {
-       print "No rows to convert. Updating schema...\n";
-       createTempTable();
-} else {
-       $row = wfFetchObject( $res );
-       if ( is_numeric( $row->l_from ) ) {
-               print "Schema already converted\n";
-               exit;
-       }
-       
-       if ( $logPerformance ) { $fh = fopen ( $perfLogFilename, "w" ); }
-       $baseTime = $startTime = getMicroTime();
-       # Create a title -> cur_id map
-       print "Loading IDs from cur table...\n";
-       performanceLog ( "Reading $numRows rows from cur table...\n" );
-       performanceLog ( "rows read vs seconds elapsed:\n" );
-       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;
-               $curRowsRead++;
-               if ($reportCurReadProgress) {
-                       if (($curRowsRead % $curReadReportInterval) == 0) {
-                               performanceLog( $curRowsRead . " " . (getMicroTime() - $baseTime) . "\n" );
-                               print "\t$curRowsRead rows of cur table read.\n";       
-                       }
-               }
-       }
-       wfFreeResult( $res );
-       wfBufferSQLResults( true );
-       print "Finished loading IDs.\n\n";
-       performanceLog( "Took " . (getMicroTime() - $baseTime) . " seconds to load IDs.\n\n" );
-#--------------------------------------------------------------------
-
-       # Now, step through the links table (in chunks of $linksConvInsertInterval rows),
-       # convert, and write to the new table.
-       createTempTable();
-       performanceLog( "Resetting timer.\n\n" );
-       $baseTime = getMicroTime();
-       print "Processing $numRows rows from links table...\n";
-       performanceLog( "Processing $numRows rows from links table...\n" );
-       performanceLog( "rows inserted vs seconds elapsed:\n" );
-       
-       for ($rowOffset = $initialRowOffset; $rowOffset < $numRows; $rowOffset += $linksConvInsertInterval) {
-               $sqlRead = "SELECT * FROM links LIMIT $linksConvInsertInterval OFFSET $rowOffset";
-               $res = wfQuery($sqlRead, DB_READ);
-               if ( $noKeys ) {
-                       $sqlWrite = array("INSERT INTO links_temp(l_from,l_to) VALUES ");
-               } else {
-                       $sqlWrite = array("INSERT IGNORE INTO links_temp(l_from,l_to) VALUES ");
-               }
-               
-               $tuplesAdded = 0; # no tuples added to INSERT yet
-               while ( $row = wfFetchObject($res) ) {
-                       $fromTitle = $row->l_from; 
-                       if ( array_key_exists( $fromTitle, $ids ) ) { # valid title
-                               $from = $ids[$fromTitle];
-                               $to = $row->l_to;
-                               if ( $tuplesAdded != 0 ) {
-                                       $sqlWrite[] = ",";
-                               }
-                               $sqlWrite[] = "($from,$to)";
-                               $tuplesAdded++;                         
-                       } else { # invalid title
-                               $numBadLinks++;
-                       }
-               }
-               wfFreeResult($res);
-               #print "rowOffset: $rowOffset\ttuplesAdded: $tuplesAdded\tnumBadLinks: $numBadLinks\n";
-               if ( $tuplesAdded != 0  ) {
-                       if ($reportLinksConvProgress) {
-                               print "Inserting $tuplesAdded tuples into links_temp...";
-                       }
-                       wfQuery( implode("",$sqlWrite) , DB_WRITE );
-                       $totalTuplesInserted += $tuplesAdded;
-                       if ($reportLinksConvProgress)
-                               print " done. Total $totalTuplesInserted tuples inserted.\n";
-                               performanceLog( $totalTuplesInserted . " " . (getMicroTime() - $baseTime) . "\n"  );
-               }
-       }
-       print "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n\n";
-       performanceLog( "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n" );
-       performanceLog( "Total execution time: " . (getMicroTime() - $startTime) . " seconds.\n" );
-       if ( $logPerformance ) { fclose ( $fh ); }
-}
-#--------------------------------------------------------------------
-
-if ( $overwriteLinksTable ) {
-       $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
-       if (!($dbConn->isOpen())) {
-               print "Opening connection to database failed.\n";
-               exit;
-       }
-       # Check for existing links_backup, and delete it if it exists.
-       print "Dropping backup links table if it exists...";
-       $dbConn->query( "DROP TABLE IF EXISTS links_backup", DB_WRITE);
-       print " done.\n";
-       
-       # Swap in the new table, and move old links table to links_backup
-       print "Swapping tables 'links' to 'links_backup'; 'links_temp' to 'links'...";
-       $dbConn->query( "RENAME TABLE links TO links_backup, links_temp TO links", DB_WRITE );
-       print " done.\n\n";
-       
-       $dbConn->close();
-       print "Conversion complete. The old table remains at links_backup;\n";
-       print "delete at your leisure.\n";
-} else {
-       print "Conversion complete.  The converted table is at links_temp;\n";
-       print "the original links table is unchanged.\n";
-}
-
-#--------------------------------------------------------------------
-
-function createTempTable() {
-       global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
-       global $noKeys;
-       $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
-       
-       if (!($dbConn->isOpen())) {
-               print "Opening connection to database failed.\n";
-               exit;
-       }
-       
-       print "Dropping temporary links table if it exists...";
-       $dbConn->query( "DROP TABLE IF EXISTS links_temp", DB_WRITE);
-       print " done.\n";
-       
-       print "Creating temporary links table...";
-       if ( $noKeys ) {
-               $dbConn->query( "CREATE TABLE links_temp ( " .
-               "l_from int(8) unsigned NOT NULL default '0', " .
-               "l_to int(8) unsigned NOT NULL default '0')", DB_WRITE);
-       } else {
-               $dbConn->query( "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);
-       }
-       print " done.\n\n";
-}
-
-function performanceLog( $text ) {
-       global $logPerformance, $fh;
-       if ( $logPerformance ) {
-               fwrite( $fh, $text );
-       }
-}
-
-function getMicroTime() { # return time in seconds, with microsecond accuracy
-       list($usec, $sec) = explode(" ", microtime());
-       return ((float)$usec + (float)$sec);
-}
 ?>
diff --git a/maintenance/trivialCmdLine.php b/maintenance/trivialCmdLine.php
new file mode 100644 (file)
index 0000000..51628bc
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+require_once( "liveCmdLine.inc" );
+print "DB name: $wgDBname\n";
+print "DB user: $wgDBuser\n";
+print "DB password: $wgDBpassword\n";
+
+$res = wfQuery( "SELECT MAX(cur_id) as m FROM cur", DB_READ );
+$row = wfFetchObject( $res );
+print "Max cur_id: {$row->m}\n";
+
+?>
diff --git a/maintenance/update2.php b/maintenance/update2.php
new file mode 100644 (file)
index 0000000..afd07e0
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+$maintenance = "/home/wikipedia/common/php-new/maintenance";
+require_once( "$maintenance/liveCmdLine.inc" );
+require_once( "$maintenance/InitialiseMessages.inc" );
+require_once( "$maintenance/updaters.inc" );
+require_once( "$maintenance/archives/moveCustomMessages.inc" );
+require_once( "$maintenance/convertLinks.inc" );
+require_once( "$maintenance/../install-utils.inc" );
+
+$wgDatabase = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+do_ipblocks_update(); flush();
+do_interwiki_update(); flush();
+do_index_update(); flush();
+do_linkscc_update(); flush();
+do_hitcounter_update(); flush();
+do_recentchanges_update(); flush();
+do_user_real_name_update(); flush();
+do_querycache_update(); flush();
+do_objectcache_update(); flush();
+do_categorylinks_update(); flush();
+initialiseMessages(); flush();
+moveCustomMessages( 1 );
+
+if ( file_exists( $wgReadOnlyFile ) ) {
+       $alreadyExists = true;
+} else {
+       $file = fopen( $wgReadOnlyFile, "w" );
+       fwrite( $file, "The database is temporarily locked for a software upgrade\n" );
+       fclose( $file );
+       $alreadyExists = false;
+}
+
+convertLinks();
+
+if ( !$alreadyExists ) {
+       unlink( $wgReadOnlyFile );
+}
+
+?>