Completed several maintenance scripts for index rebuilding.
authorLee Daniel Crocker <lcrocker@users.mediawiki.org>
Fri, 2 May 2003 22:55:37 +0000 (22:55 +0000)
committerLee Daniel Crocker <lcrocker@users.mediawiki.org>
Fri, 2 May 2003 22:55:37 +0000 (22:55 +0000)
maintenance/rebuildIndex.php [deleted file]
maintenance/rebuildLinks.inc [deleted file]
maintenance/rebuildLinks.php [deleted file]
maintenance/rebuildall.php [new file with mode: 0644]
maintenance/rebuildlinks.inc [new file with mode: 0644]
maintenance/rebuildlinks.php [new file with mode: 0644]
maintenance/rebuildrecentchanges.inc [new file with mode: 0644]
maintenance/rebuildrecentchanges.php [new file with mode: 0644]
maintenance/rebuildtextindex.inc [new file with mode: 0644]
maintenance/rebuildtextindex.php [new file with mode: 0644]
maintenance/tables.sql

diff --git a/maintenance/rebuildIndex.php b/maintenance/rebuildIndex.php
deleted file mode 100644 (file)
index 1bd085c..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?
-
-# Rebuild the fulltext search indexes. This may take a while
-# depending on the database size and server configuration.
-
-global $IP;
-include_once( "../LocalSettings.php" );
-include_once( "$IP/Setup.php" );
-include_once( "$IP/SearchUpdate.php" );
-set_time_limit(0);
-
-$wgDBuser                      = "wikiadmin";
-$wgDBpassword          = $wgDBadminpassword;
-
-# May run faster if you drop the index; but will break attempts to search
-# while it's running if you're online.
-#echo "Dropping index...\n";
-##$sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
-#$res = wfQuery($sql);
-
-$sql = "SELECT COUNT(*) AS count FROM cur";
-$res = wfQuery($sql);
-$s = wfFetchObject($res);
-echo "Rebuilding index fields for {$s->count} pages...\n";
-$n = 0;
-
-$sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur";
-$res = wfQuery($sql);
-while( $s = wfFetchObject($res)) {
-       $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
-       $u->doUpdate();
-       if ( ( (++$n) % 500) == 0) {
-               echo "$n\n";
-       }
-}
-wfFreeResult( $res );
-
-#echo "Rebuild the index...\n";
-##$sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title),
-##  ADD FULLTEXT si_text (si_text)";
-#$res = wfQuery($sql);
-
-print "Done.\n";
-exit();
-
-?>
diff --git a/maintenance/rebuildLinks.inc b/maintenance/rebuildLinks.inc
deleted file mode 100644 (file)
index e98d6d7..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-<?
-
-# Functions for rebuilding the link tracking tables; must
-# be included within a script that also includes the Setup.
-# See convertdb.php, for example.
-#
-
-function rebuildLinkTablesPass1()
-{
-       global $wgLang;
-       $count = 0;
-       print "Rebuilding link tables (pass 1).\n";
-
-       $sql = "DROP TABLE IF EXISTS rebuildlinks";
-       wfQuery( $sql );
-
-       $sql = "CREATE TABLE rebuildlinks (
-  rl_f_id int(8) unsigned NOT NULL default 0,
-  rl_f_title varchar(255) binary NOT NULL default '',
-  rl_to varchar(255) binary NOT NULL default '',
-  INDEX rl_to (rl_to) ) TYPE=MyISAM";
-       wfQuery( $sql );
-
-       $sql = "LOCK TABLES cur READ, rebuildlinks WRITE";
-       wfQuery( $sql );
-
-       $sql = "DELETE FROM rebuildlinks";
-       wfQuery( $sql );
-
-       $sql = "SELECT cur_id,cur_namespace,cur_title,cur_text FROM cur";
-       $res = wfQuery( $sql );
-       $total = wfNumRows( $res );
-
-       $tc = Title::legalChars();
-       while ( $row = wfFetchObject( $res ) ) {
-               $id = $row->cur_id;
-               $ns = $wgLang->getNsText( $row->cur_namespace );
-               if ( "" == $ns ) {
-                       $title = addslashes( $row->cur_title );
-               } else {
-                       $title = addslashes( "$ns:{$row->cur_title}" );
-               }
-               $text = $row->cur_text;
-               $numlinks = preg_match_all( "/\\[\\[([{$tc}]+)(]|\\|)/", $text,
-                 $m, PREG_PATTERN_ORDER );
-
-               if ( 0 != $numlinks ) {
-                       $sql = "INSERT INTO rebuildlinks (rl_f_id,rl_f_title,rl_to) VALUES ";
-                       for ( $i = 0; $i < $numlinks; ++$i ) {
-                               $nt = Title::newFromText( $m[1][$i] );
-                               $dest = addslashes( $nt->getPrefixedDBkey() );
-
-                               if ( 0 != $i ) { $sql .= ","; }
-                               $sql .= "({$id},'{$title}','{$dest}')";
-                       }
-                       wfQuery( $sql );
-               }
-               if ( ( ++$count % 1000 ) == 0 ) {
-                       print "$count of $total articles scanned.\n";
-               }
-       }
-       print "$count articles scanned.\n";
-       mysql_free_result( $res );
-
-       $sql = "UNLOCK TABLES";
-       wfQuery( $sql );
-}
-
-function rebuildLinkTablesPass2()
-{
-       global $wgLang;
-       $count = 0;
-       print "Rebuilding link tables (pass 2).\n";
-
-       $sql = "LOCK TABLES cur READ, rebuildlinks READ, " .
-         "links WRITE, brokenlinks WRITE, imagelinks WRITE";
-       wfQuery( $sql );
-
-       $sql = "DELETE FROM links";
-       wfQuery( $sql );
-
-       $sql = "DELETE FROM brokenlinks";
-       wfQuery( $sql );
-
-       $sql = "DELETE FROM links";
-       wfQuery( $sql );
-
-       $ins = $wgLang->getNsText( Namespace::getImage() );
-       $inslen = strlen($ins)+1;
-       $sql = "SELECT rl_f_title,rl_to FROM rebuildlinks " .
-         "WHERE rl_to LIKE '$ins:%'";
-       $res = wfQuery( $sql );
-
-       $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
-       $sqlX = "";
-       $first = true;
-       while ( $row = wfFetchObject( $res ) ) {
-               $iname = addslashes( substr( $row->rl_to, $inslen ) );
-               $pname = addslashes( $row->rl_f_title );
-
-               if ( ! $first ) { $sqlX .= ","; }
-               $first = false;
-
-               $sqlX .= "('{$pname}','{$iname}')";
-       }
-       if ($sqlX != "") {
-         $sql .= $sqlX;
-         wfFreeResult( $res );
-         wfQuery( $sql );
-       }
-
-       $sql = "SELECT DISTINCT rl_to FROM rebuildlinks " .
-         "ORDER BY rl_to";
-       $res = wfQuery( $sql );
-       $count = 0;
-       $total = wfNumRows( $res );
-
-       while ( $row = wfFetchObject( $res ) ) {
-               if ( 0 == strncmp( "$ins:", $row->rl_to, $inslen ) ) { continue; }
-
-               $nt = Title::newFromDBkey( $row->rl_to );
-               $id = $nt->getArticleID();
-               $to = addslashes( $row->rl_to );
-
-               if ( 0 == $id ) {
-                       $sql = "SELECT rl_f_id FROM rebuildlinks WHERE rl_to='{$to}'";
-                       $res2 = wfQuery( $sql );
-
-                       $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
-                       $first = true;
-                       while ( $row2 = wfFetchObject( $res2 ) ) {
-                               $from = $row2->rl_f_id;
-                               if ( ! $first ) { $sql .= ","; }
-                               $first = false;
-                               $sql .= "({$from},'{$to}')";
-                       }
-                       wfFreeResult( $res2 );
-                       if ( ! $first ) { wfQuery( $sql ); }
-               } else {
-                       $sql = "SELECT rl_f_title FROM rebuildlinks WHERE rl_to='{$to}'";
-                       $res2 = wfQuery( $sql );
-
-                       $sql = "INSERT INTO links (l_from,l_to) VALUES ";
-                       $first = true;
-                       while ( $row2 = wfFetchObject( $res2 ) ) {
-                               $from = addslashes( $row2->rl_f_title );
-                               if ( ! $first ) { $sql .= ","; }
-                               $first = false;
-                               $sql .= "('{$from}',{$id})";
-                       }
-                       wfFreeResult( $res2 );
-                       if ( ! $first ) { wfQuery( $sql ); }
-               }
-               if ( ( ++$count % 1000 ) == 0 ) {
-                       print "$count of $total titles processed.\n";
-               }
-       }
-       wfFreeResult( $res );
-
-       $sql = "UNLOCK TABLES";
-       wfQuery( $sql );
-
-       $sql = "DROP TABLE rebuildlinks";
-       wfQuery( $sql );
-}
-?>
diff --git a/maintenance/rebuildLinks.php b/maintenance/rebuildLinks.php
deleted file mode 100644 (file)
index 2890507..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?
-
-# Rebuild link tracking tables from scratch.  This takes several
-# hours, depending on the database size and server configuration.
-
-global $IP;
-include_once( "../LocalSettings.php" );
-include_once( "$IP/Setup.php" );
-include_once( "./rebuildLinks.inc" );
-include_once( "./rebuildRecentChanges.inc" );
-$wgTitle = Title::newFromText( "Rebuild links script" );
-set_time_limit(0);
-
-$wgDBuser                      = "wikiadmin";
-$wgDBpassword          = $wgDBadminpassword;
-
-rebuildLinkTablesPass1();
-rebuildLinkTablesPass2();
-
-rebuildRecentChangesTable();
-
-print "Done.\n";
-exit();
-
-?>
diff --git a/maintenance/rebuildall.php b/maintenance/rebuildall.php
new file mode 100644 (file)
index 0000000..9e64d19
--- /dev/null
@@ -0,0 +1,39 @@
+<?
+
+# Rebuild link tracking tables from scratch.  This takes several
+# hours, depending on the database size and server configuration.
+
+if ( ! is_readable( "../LocalSettings.php" ) ) {
+       print "A copy of your installation's LocalSettings.php\n" .
+         "must exist in the source directory.\n";
+       exit();
+}
+
+$DP = "../includes";
+include_once( "../LocalSettings.php" );
+include_once( "../AdminSettings.php" );
+
+include_once( "{$IP}/Setup.php" );
+include_once( "./rebuildlinks.inc" );
+include_once( "./rebuildtextindex.inc" );
+include_once( "./rebuildrecentchanges.inc" );
+$wgTitle = Title::newFromText( "Rebuild links script" );
+set_time_limit(0);
+
+$wgDBuser                      = $wgDBadminuser;
+$wgDBpassword          = $wgDBadminpassword;
+
+rebuildLinkTablesPass1();
+rebuildLinkTablesPass2();
+
+dropTextIndex();
+rebuildTextIndex();
+createTextIndex();
+
+rebuildRecentChangesTablePass1();
+rebuildRecentChangesTablePass2();
+
+print "Done.\n";
+exit();
+
+?>
diff --git a/maintenance/rebuildlinks.inc b/maintenance/rebuildlinks.inc
new file mode 100644 (file)
index 0000000..7dd3dde
--- /dev/null
@@ -0,0 +1,166 @@
+<?
+
+# Functions for rebuilding the link tracking tables; must
+# be included within a script that also includes the Setup.
+# See rebuildlinks.php, for example.
+#
+
+function rebuildLinkTablesPass1()
+{
+       global $wgLang;
+       $count = 0;
+       print "Rebuilding link tables (pass 1).\n";
+
+       $sql = "DROP TABLE IF EXISTS rebuildlinks";
+       wfQuery( $sql );
+
+       $sql = "CREATE TABLE rebuildlinks (
+  rl_f_id int(8) unsigned NOT NULL default 0,
+  rl_f_title varchar(255) binary NOT NULL default '',
+  rl_to varchar(255) binary NOT NULL default '',
+  INDEX rl_to (rl_to) ) TYPE=MyISAM";
+       wfQuery( $sql );
+
+       $sql = "LOCK TABLES cur READ, rebuildlinks WRITE";
+       wfQuery( $sql );
+
+       $sql = "DELETE FROM rebuildlinks";
+       wfQuery( $sql );
+
+       $sql = "SELECT cur_id,cur_namespace,cur_title,cur_text FROM cur";
+       $res = wfQuery( $sql );
+       $total = wfNumRows( $res );
+
+       $tc = Title::legalChars();
+       while ( $row = wfFetchObject( $res ) ) {
+               $id = $row->cur_id;
+               $ns = $wgLang->getNsText( $row->cur_namespace );
+               if ( "" == $ns ) {
+                       $title = addslashes( $row->cur_title );
+               } else {
+                       $title = addslashes( "$ns:{$row->cur_title}" );
+               }
+               $text = $row->cur_text;
+               $numlinks = preg_match_all( "/\\[\\[([{$tc}]+)(]|\\|)/", $text,
+                 $m, PREG_PATTERN_ORDER );
+
+               if ( 0 != $numlinks ) {
+                       $sql = "INSERT INTO rebuildlinks (rl_f_id,rl_f_title,rl_to) VALUES ";
+                       for ( $i = 0; $i < $numlinks; ++$i ) {
+                               $nt = Title::newFromText( $m[1][$i] );
+                               $dest = addslashes( $nt->getPrefixedDBkey() );
+
+                               if ( 0 != $i ) { $sql .= ","; }
+                               $sql .= "({$id},'{$title}','{$dest}')";
+                       }
+                       wfQuery( $sql );
+               }
+               if ( ( ++$count % 1000 ) == 0 ) {
+                       print "$count of $total articles scanned.\n";
+               }
+       }
+       print "$count articles scanned.\n";
+       mysql_free_result( $res );
+
+       $sql = "UNLOCK TABLES";
+       wfQuery( $sql );
+}
+
+function rebuildLinkTablesPass2()
+{
+       global $wgLang;
+       $count = 0;
+       print "Rebuilding link tables (pass 2).\n";
+
+       $sql = "LOCK TABLES cur READ, rebuildlinks READ, " .
+         "links WRITE, brokenlinks WRITE, imagelinks WRITE";
+       wfQuery( $sql );
+
+       $sql = "DELETE FROM links";
+       wfQuery( $sql );
+
+       $sql = "DELETE FROM brokenlinks";
+       wfQuery( $sql );
+
+       $sql = "DELETE FROM links";
+       wfQuery( $sql );
+
+       $ins = $wgLang->getNsText( Namespace::getImage() );
+       $inslen = strlen($ins)+1;
+       $sql = "SELECT rl_f_title,rl_to FROM rebuildlinks " .
+         "WHERE rl_to LIKE '$ins:%'";
+       $res = wfQuery( $sql );
+
+       $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES ";
+       $sqlX = "";
+       $first = true;
+       while ( $row = wfFetchObject( $res ) ) {
+               $iname = addslashes( substr( $row->rl_to, $inslen ) );
+               $pname = addslashes( $row->rl_f_title );
+
+               if ( ! $first ) { $sqlX .= ","; }
+               $first = false;
+
+               $sqlX .= "('{$pname}','{$iname}')";
+       }
+       if ($sqlX != "") {
+         $sql .= $sqlX;
+         wfFreeResult( $res );
+         wfQuery( $sql );
+       }
+
+       $sql = "SELECT DISTINCT rl_to FROM rebuildlinks " .
+         "ORDER BY rl_to";
+       $res = wfQuery( $sql );
+       $count = 0;
+       $total = wfNumRows( $res );
+
+       while ( $row = wfFetchObject( $res ) ) {
+               if ( 0 == strncmp( "$ins:", $row->rl_to, $inslen ) ) { continue; }
+
+               $nt = Title::newFromDBkey( $row->rl_to );
+               $id = $nt->getArticleID();
+               $to = addslashes( $row->rl_to );
+
+               if ( 0 == $id ) {
+                       $sql = "SELECT rl_f_id FROM rebuildlinks WHERE rl_to='{$to}'";
+                       $res2 = wfQuery( $sql );
+
+                       $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
+                       $first = true;
+                       while ( $row2 = wfFetchObject( $res2 ) ) {
+                               $from = $row2->rl_f_id;
+                               if ( ! $first ) { $sql .= ","; }
+                               $first = false;
+                               $sql .= "({$from},'{$to}')";
+                       }
+                       wfFreeResult( $res2 );
+                       if ( ! $first ) { wfQuery( $sql ); }
+               } else {
+                       $sql = "SELECT rl_f_title FROM rebuildlinks WHERE rl_to='{$to}'";
+                       $res2 = wfQuery( $sql );
+
+                       $sql = "INSERT INTO links (l_from,l_to) VALUES ";
+                       $first = true;
+                       while ( $row2 = wfFetchObject( $res2 ) ) {
+                               $from = addslashes( $row2->rl_f_title );
+                               if ( ! $first ) { $sql .= ","; }
+                               $first = false;
+                               $sql .= "('{$from}',{$id})";
+                       }
+                       wfFreeResult( $res2 );
+                       if ( ! $first ) { wfQuery( $sql ); }
+               }
+               if ( ( ++$count % 1000 ) == 0 ) {
+                       print "$count of $total titles processed.\n";
+               }
+       }
+       wfFreeResult( $res );
+
+       $sql = "UNLOCK TABLES";
+       wfQuery( $sql );
+
+       $sql = "DROP TABLE rebuildlinks";
+       wfQuery( $sql );
+}
+?>
diff --git a/maintenance/rebuildlinks.php b/maintenance/rebuildlinks.php
new file mode 100644 (file)
index 0000000..de756c1
--- /dev/null
@@ -0,0 +1,30 @@
+<?
+
+# Rebuild link tracking tables from scratch.  This takes several
+# hours, depending on the database size and server configuration.
+
+if ( ! is_readable( "../LocalSettings.php" ) ) {
+       print "A copy of your installation's LocalSettings.php\n" .
+         "must exist in the source directory.\n";
+       exit();
+}
+
+$DP = "../includes";
+include_once( "../LocalSettings.php" );
+include_once( "../AdminSettings.php" );
+
+include_once( "{$IP}/Setup.php" );
+include_once( "./rebuildlinks.inc" );
+$wgTitle = Title::newFromText( "Rebuild links script" );
+set_time_limit(0);
+
+$wgDBuser                      = $wgDBadminuser;
+$wgDBpassword          = $wgDBadminpassword;
+
+rebuildLinkTablesPass1();
+rebuildLinkTablesPass2();
+
+print "Done.\n";
+exit();
+
+?>
diff --git a/maintenance/rebuildrecentchanges.inc b/maintenance/rebuildrecentchanges.inc
new file mode 100644 (file)
index 0000000..2d9c009
--- /dev/null
@@ -0,0 +1,115 @@
+<?
+
+# Rebuild recent changes table.
+#
+
+function rebuildRecentChangesTablePass1()
+{
+       $sql = "DROP TABLE IF EXISTS recentchanges";
+       wfQuery( $sql );
+
+       $sql = "CREATE TABLE recentchanges (
+  rc_timestamp varchar(14) binary NOT NULL default '',
+  rc_cur_time varchar(14) binary NOT NULL default '',
+  rc_user int(10) unsigned NOT NULL default '0',
+  rc_user_text varchar(255) binary NOT NULL default '',
+  rc_namespace tinyint(3) unsigned NOT NULL default '0',
+  rc_title varchar(255) binary NOT NULL default '',
+  rc_comment varchar(255) binary NOT NULL default '',
+  rc_minor tinyint(3) unsigned NOT NULL default '0',
+  rc_bot tinyint(3) unsigned NOT NULL default '0',
+  rc_new tinyint(3) unsigned NOT NULL default '0',
+  rc_cur_id int(10) unsigned NOT NULL default '0',
+  rc_this_oldid int(10) unsigned NOT NULL default '0',
+  rc_last_oldid int(10) unsigned NOT NULL default '0',
+  INDEX rc_cur_id (rc_cur_id),
+  INDEX rc_cur_time (rc_cur_time),
+  INDEX rc_timestamp (rc_timestamp),
+  INDEX rc_namespace (rc_namespace),
+  INDEX rc_title (rc_title)
+) TYPE=MyISAM PACK_KEYS=1;";
+       wfQuery( $sql );
+
+       print( "Loading from CUR table...\n" );
+
+       $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," .
+         "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," .
+         "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT cur_timestamp," .
+         "cur_timestamp,cur_user,cur_user_text,cur_namespace,cur_title," .
+         "cur_comment,cur_minor_edit,0,cur_is_new,cur_id,0,0 FROM cur " .
+         "ORDER BY cur_timestamp DESC LIMIT 5000";
+       wfQuery( $sql );
+
+       print( "Loading from OLD table...\n" );
+
+       $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," .
+      "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," .
+      "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT old_timestamp,''," .
+         "old_user,old_user_text,old_namespace,old_title,old_comment," .
+         "old_minor_edit,0,0,0,old_id,0 FROM old ORDER BY old_timestamp " .
+         "DESC LIMIT 5000";
+       wfQuery( $sql );
+
+       $sql = "SELECT rc_timestamp FROM recentchanges " .
+         "ORDER BY rc_timestamp DESC LIMIT 5000,1";
+       $res = wfQuery( $sql );
+       $obj = wfFetchObject( $res );
+       $ts = $obj->rc_timestamp;
+
+       $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$ts}'";
+       wfQuery( $sql );
+}
+
+function rebuildRecentChangesTablePass2()
+{
+       $ns = $id = $count = 0;
+       $title = $ct =  "";
+
+       print( "Updating links...\n" );
+
+       $sql = "SELECT rc_namespace,rc_title,rc_timestamp FROM recentchanges " .
+         "ORDER BY rc_namespace,rc_title,rc_timestamp DESC";
+       $res = wfQuery( $sql );
+
+       while ( $obj = wfFetchObject( $res ) ) {
+               if ( ! ( $ns == $obj->rc_namespace &&
+                          0 == strcmp( $title, wfStrencode( $obj->rc_title ) ) ) ) {
+
+                       $ns = $obj->rc_namespace;
+                       $title = wfStrencode( $obj->rc_title );
+
+                       $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE " .
+                         "cur_namespace={$ns} AND cur_title='{$title}'";
+                       $res2 = wfQuery( $sql );
+                       $obj2 = wfFetchObject( $res2 );
+
+                       $id = $obj2->cur_id;
+                       $ct = $obj2->cur_timestamp;
+               }
+               $sql = "SELECT old_id FROM old WHERE old_namespace={$ns} " .
+                 "AND old_title='{$title}' AND old_timestamp < '" .
+                 "{$obj->rc_timestamp}' ORDER BY old_timestamp DESC LIMIT 1";
+               $res2 = wfQuery( $sql );
+
+               if ( 0 != wfNumRows( $res2 ) ) {
+                       $obj2 = wfFetchObject( $res2 );
+
+                       $sql = "UPDATE recentchanges SET rc_cur_id={$id},rc_cur_time=" .
+                         "'{$ct}',rc_last_oldid={$obj2->old_id} WHERE " .
+                         "rc_namespace={$ns} AND rc_title='{$title}' AND " .
+                         "rc_timestamp='{$obj->rc_timestamp}'";
+                       wfQuery( $sql );
+               } else {
+                       $sql = "UPDATE recentchanges SET rc_cur_id={$id},rc_cur_time=" .
+                         "'{$ct}' WHERE rc_namespace={$ns} AND rc_title='{$title}' " .
+                         "AND rc_timestamp='{$obj->rc_timestamp}'";
+                       wfQuery( $sql );
+               }
+
+               if ( 0 == ( ++$count % 500 ) ) {
+                       printf( "%d records processed.\n", $count );
+               }
+       }
+}
+
+?>
diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php
new file mode 100644 (file)
index 0000000..894353f
--- /dev/null
@@ -0,0 +1,30 @@
+<?
+
+# Rebuild link tracking tables from scratch.  This takes several
+# hours, depending on the database size and server configuration.
+
+if ( ! is_readable( "../LocalSettings.php" ) ) {
+       print "A copy of your installation's LocalSettings.php\n" .
+         "must exist in the source directory.\n";
+       exit();
+}
+
+$DP = "../includes";
+include_once( "../LocalSettings.php" );
+include_once( "../AdminSettings.php" );
+
+include_once( "{$IP}/Setup.php" );
+include_once( "./rebuildrecentchanges.inc" );
+$wgTitle = Title::newFromText( "Rebuild recent changes script" );
+set_time_limit(0);
+
+$wgDBuser                      = $wgDBadminuser;
+$wgDBpassword          = $wgDBadminpassword;
+
+rebuildRecentChangesTablePass1();
+rebuildRecentChangesTablePass2();
+
+print "Done.\n";
+exit();
+
+?>
diff --git a/maintenance/rebuildtextindex.inc b/maintenance/rebuildtextindex.inc
new file mode 100644 (file)
index 0000000..8d681c8
--- /dev/null
@@ -0,0 +1,43 @@
+<?
+
+# Rebuild the fulltext search indexes. This may take a while
+# depending on the database size and server configuration.
+
+# Rebuilding is faster if you drop the index and recreate it,
+# but that will prevent searches from working while it runs.
+
+function dropTextIndex()
+{
+       echo "Dropping index...\n";
+       $sql = "ALTER TABLE searchindex DROP INDEX si_title, DROP INDEX si_text";
+       $res = wfQuery($sql);
+}
+
+function createTextIndex()
+{
+       echo "Rebuild the index...\n";
+       $sql = "ALTER TABLE searchindex ADD FULLTEXT si_title (si_title), " .
+         "ADD FULLTEXT si_text (si_text)";
+       $res = wfQuery($sql);
+}
+
+function rebuildTextIndex()
+{
+       $sql = "SELECT COUNT(*) AS count FROM cur";
+       $res = wfQuery($sql);
+       $s = wfFetchObject($res);
+       echo "Rebuilding index fields for {$s->count} pages...\n";
+       $n = 0;
+
+       $sql = "SELECT cur_id, cur_namespace, cur_title, cur_text FROM cur";
+       $res = wfQuery($sql);
+
+       while( $s = wfFetchObject($res) ) {
+               $u = new SearchUpdate( $s->cur_id, $s->cur_title, $s->cur_text );
+               $u->doUpdate();
+               if ( ( (++$n) % 500) == 0) { echo "$n\n"; }
+       }
+       wfFreeResult( $res );
+}
+
+?>
diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php
new file mode 100644 (file)
index 0000000..bbc5327
--- /dev/null
@@ -0,0 +1,31 @@
+<?
+
+# Rebuild link tracking tables from scratch.  This takes several
+# hours, depending on the database size and server configuration.
+
+if ( ! is_readable( "../LocalSettings.php" ) ) {
+       print "A copy of your installation's LocalSettings.php\n" .
+         "must exist in the source directory.\n";
+       exit();
+}
+
+$DP = "../includes";
+include_once( "../LocalSettings.php" );
+include_once( "../AdminSettings.php" );
+
+include_once( "{$IP}/Setup.php" );
+include_once( "./rebuildtextindex.inc" );
+$wgTitle = Title::newFromText( "Rebuild text index script" );
+set_time_limit(0);
+
+$wgDBuser                      = $wgDBadminuser;
+$wgDBpassword          = $wgDBadminpassword;
+
+dropTextIndex();
+rebuildTextIndex();
+createTextIndex();
+
+print "Done.\n";
+exit();
+
+?>
index 09556af..9ca9f5e 100644 (file)
@@ -165,12 +165,12 @@ CREATE TABLE watchlist (
 
 DROP TABLE IF EXISTS math;
 CREATE TABLE math (
-    math_inputhash varchar(16) NOT NULL,
-    math_outputhash varchar(16) NOT NULL,
-    math_html_conservativeness tinyint(1) NOT NULL,
-    math_html text,
-    math_mathml text,
-    UNIQUE KEY math_inputhash (math_inputhash)
+  math_inputhash varchar(16) NOT NULL,
+  math_outputhash varchar(16) NOT NULL,
+  math_html_conservativeness tinyint(1) NOT NULL,
+  math_html text,
+  math_mathml text,
+  UNIQUE KEY math_inputhash (math_inputhash)
 ) TYPE=MyISAM;
 
 -- Table searchindex must be MyISAM for fulltext support