Maintenance script fixes
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 17 Nov 2003 12:55:24 +0000 (12:55 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 17 Nov 2003 12:55:24 +0000 (12:55 +0000)
maintenance/checktrans.php
maintenance/cleandb.php
maintenance/rebuildall.php
maintenance/rebuildlinks.inc
maintenance/rebuildlinks.php
maintenance/rebuildrecentchanges.inc
maintenance/rebuildrecentchanges.php
maintenance/rebuildtextindex.php
wiki.phtml

index f390a4f..ef0e9fc 100644 (file)
@@ -12,6 +12,7 @@ if ( ! is_readable( "../LocalSettings.php" ) ) {
        exit();
 }
 
+$wgCommandLineMode = true;
 $DP = "../includes";
 include_once( "../LocalSettings.php" );
 
@@ -31,7 +32,6 @@ set_time_limit( 0 );
 
 include_once( "{$IP}/Setup.php" );
 $wgTitle = Title::newFromText( "Translation checking script" );
-$wgCommandLineMode = true;
 
 $count = $total = 0;
 $msgarray = "wgAllMessages" . ucfirst( $wgLanguageCode );
index cf346a0..3dc75d3 100644 (file)
@@ -3,9 +3,13 @@
 # Creating a new empty database; either this or the conversion
 # script from the old format needs to be run, but not both.
 
-global $IP;
+$wgCommandLineMode = true;
 include_once( "../LocalSettings.php" );
-include_once( "$IP/Setup.php" );
+
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
+
+include_once( "Setup.php" );
 
 $wgTitle = Title::newFromText( "Database creation script" );
 include_once( "./buildTables.inc" );
index 9e64d19..7b55626 100644 (file)
@@ -9,11 +9,15 @@ if ( ! is_readable( "../LocalSettings.php" ) ) {
        exit();
 }
 
+$wgCommandLineMode = true;
 $DP = "../includes";
 include_once( "../LocalSettings.php" );
 include_once( "../AdminSettings.php" );
 
-include_once( "{$IP}/Setup.php" );
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
+
+include_once( "Setup.php" );
 include_once( "./rebuildlinks.inc" );
 include_once( "./rebuildtextindex.inc" );
 include_once( "./rebuildrecentchanges.inc" );
index 047476e..6a6bc26 100644 (file)
@@ -5,9 +5,12 @@
 # See rebuildlinks.php, for example.
 #
 
+# Turn this on if you've got memory to burn
+$wgUseMemoryTables = false;
+
 function rebuildLinkTablesPass1()
 {
-       global $wgLang;
+       global $wgLang, $wgUseMemoryTables;
        $count = 0;
        print "Rebuilding link tables (pass 1).\n";
 
@@ -18,10 +21,11 @@ function rebuildLinkTablesPass1()
   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";
+  INDEX rl_to (rl_to) )";
+       if( $wgUseMemoryTables ) $sql .= " TYPE=heap";
        wfQuery( $sql, DB_WRITE );
 
-       $sql = "LOCK TABLES cur READ, rebuildlinks WRITE, interwiki READ";
+       $sql = "LOCK TABLES cur READ, rebuildlinks WRITE, interwiki READ, user_newtalk READ";
        wfQuery( $sql, DB_WRITE );
 
        $sql = "DELETE FROM rebuildlinks";
@@ -48,6 +52,11 @@ function rebuildLinkTablesPass1()
                        $first = true;
                        $sql = "INSERT INTO rebuildlinks (rl_f_id,rl_f_title,rl_to) VALUES ";
                        for ( $i = 0; $i < $numlinks; ++$i ) {
+                               if( preg_match( '/^(http|https|ftp|mailto|news):/', $m[1][$i] ) ) {
+                                       # an URL link; not for us!
+                                       continue;
+                               }
+                               # FIXME: Handle subpage links
                                $nt = Title::newFromText( $m[1][$i] );
                                if (! $nt)
                                {
@@ -55,6 +64,18 @@ function rebuildLinkTablesPass1()
                                        print "error in '$ns:{$row->cur_title}' :\t'$txt'\n";
                                        continue;
                                }
+                               if( $nt->getInterwiki() != "" ) {
+                                       # Interwiki links are not stored in the link tables
+                                       continue;
+                               }
+                               if( $nt->getNamespace() == Namespace::getSpecial() ) {
+                                       # Special links not stored in link tables
+                                       continue;
+                               }
+                               if( $nt->getNamespace() == Namespace::getMedia() ) {
+                                       # treat media: links as image: links
+                                       $nt = Title::makeTitle( Namespace::getImage(), $nt->getDBkey() );
+                               }
 
                                if (!$first)
                                        $sql .= ",";
@@ -138,7 +159,7 @@ function rebuildLinkTablesPass2()
                $to = addslashes( $row->rl_to );
 
                if ( 0 == $id ) {
-                       $sql = "SELECT rl_f_id FROM rebuildlinks WHERE rl_to='{$to}'";
+                       $sql = "SELECT DISTINCT rl_f_id FROM rebuildlinks WHERE rl_to='{$to}'";
                        $res2 = wfQuery( $sql, DB_WRITE );
 
                        $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
@@ -156,7 +177,7 @@ function rebuildLinkTablesPass2()
                        wfFreeResult( $res2 );
                        if ( ! $first ) { wfQuery( $sql, DB_WRITE ); }
                } else {
-                       $sql = "SELECT rl_f_title FROM rebuildlinks WHERE rl_to='{$to}'";
+                       $sql = "SELECT DISTINCT rl_f_title FROM rebuildlinks WHERE rl_to='{$to}'";
                        $res2 = wfQuery( $sql, DB_WRITE );
 
                        $sql = "INSERT INTO links (l_from,l_to) VALUES ";
index de756c1..9405a03 100644 (file)
@@ -9,11 +9,15 @@ if ( ! is_readable( "../LocalSettings.php" ) ) {
        exit();
 }
 
+$wgCommandLineMode = true;
 $DP = "../includes";
 include_once( "../LocalSettings.php" );
 include_once( "../AdminSettings.php" );
 
-include_once( "{$IP}/Setup.php" );
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
+
+include_once( "Setup.php" );
 include_once( "./rebuildlinks.inc" );
 $wgTitle = Title::newFromText( "Rebuild links script" );
 set_time_limit(0);
index 2d9c009..92d2ab5 100644 (file)
@@ -6,7 +6,7 @@
 function rebuildRecentChangesTablePass1()
 {
        $sql = "DROP TABLE IF EXISTS recentchanges";
-       wfQuery( $sql );
+       wfQuery( $sql, DB_WRITE );
 
        $sql = "CREATE TABLE recentchanges (
   rc_timestamp varchar(14) binary NOT NULL default '',
@@ -28,7 +28,7 @@ function rebuildRecentChangesTablePass1()
   INDEX rc_namespace (rc_namespace),
   INDEX rc_title (rc_title)
 ) TYPE=MyISAM PACK_KEYS=1;";
-       wfQuery( $sql );
+       wfQuery( $sql, DB_WRITE );
 
        print( "Loading from CUR table...\n" );
 
@@ -38,7 +38,7 @@ function rebuildRecentChangesTablePass1()
          "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 );
+       wfQuery( $sql, DB_WRITE );
 
        print( "Loading from OLD table...\n" );
 
@@ -48,16 +48,16 @@ function rebuildRecentChangesTablePass1()
          "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 );
+       wfQuery( $sql, DB_WRITE );
 
        $sql = "SELECT rc_timestamp FROM recentchanges " .
          "ORDER BY rc_timestamp DESC LIMIT 5000,1";
-       $res = wfQuery( $sql );
+       $res = wfQuery( $sql, DB_WRITE );
        $obj = wfFetchObject( $res );
        $ts = $obj->rc_timestamp;
 
        $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$ts}'";
-       wfQuery( $sql );
+       wfQuery( $sql, DB_WRITE );
 }
 
 function rebuildRecentChangesTablePass2()
@@ -69,7 +69,7 @@ function rebuildRecentChangesTablePass2()
 
        $sql = "SELECT rc_namespace,rc_title,rc_timestamp FROM recentchanges " .
          "ORDER BY rc_namespace,rc_title,rc_timestamp DESC";
-       $res = wfQuery( $sql );
+       $res = wfQuery( $sql, DB_WRITE );
 
        while ( $obj = wfFetchObject( $res ) ) {
                if ( ! ( $ns == $obj->rc_namespace &&
@@ -80,7 +80,7 @@ function rebuildRecentChangesTablePass2()
 
                        $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE " .
                          "cur_namespace={$ns} AND cur_title='{$title}'";
-                       $res2 = wfQuery( $sql );
+                       $res2 = wfQuery( $sql, DB_WRITE );
                        $obj2 = wfFetchObject( $res2 );
 
                        $id = $obj2->cur_id;
@@ -89,7 +89,7 @@ function rebuildRecentChangesTablePass2()
                $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 );
+               $res2 = wfQuery( $sql, DB_WRITE );
 
                if ( 0 != wfNumRows( $res2 ) ) {
                        $obj2 = wfFetchObject( $res2 );
@@ -98,12 +98,12 @@ function rebuildRecentChangesTablePass2()
                          "'{$ct}',rc_last_oldid={$obj2->old_id} WHERE " .
                          "rc_namespace={$ns} AND rc_title='{$title}' AND " .
                          "rc_timestamp='{$obj->rc_timestamp}'";
-                       wfQuery( $sql );
+                       wfQuery( $sql, DB_WRITE );
                } 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 );
+                       wfQuery( $sql, DB_WRITE );
                }
 
                if ( 0 == ( ++$count % 500 ) ) {
index 894353f..3803c1a 100644 (file)
@@ -9,11 +9,15 @@ if ( ! is_readable( "../LocalSettings.php" ) ) {
        exit();
 }
 
+$wgCommandLineMode = true;
 $DP = "../includes";
 include_once( "../LocalSettings.php" );
 include_once( "../AdminSettings.php" );
 
-include_once( "{$IP}/Setup.php" );
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
+
+include_once( "Setup.php" );
 include_once( "./rebuildrecentchanges.inc" );
 $wgTitle = Title::newFromText( "Rebuild recent changes script" );
 set_time_limit(0);
index bbc5327..2ca7356 100644 (file)
@@ -1,6 +1,6 @@
 <?
 
-# Rebuild link tracking tables from scratch.  This takes several
+# Rebuild search index table from scratch.  This takes several
 # hours, depending on the database size and server configuration.
 
 if ( ! is_readable( "../LocalSettings.php" ) ) {
@@ -9,11 +9,15 @@ if ( ! is_readable( "../LocalSettings.php" ) ) {
        exit();
 }
 
+$wgCommandLineMode = true;
 $DP = "../includes";
 include_once( "../LocalSettings.php" );
 include_once( "../AdminSettings.php" );
 
-include_once( "{$IP}/Setup.php" );
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
+
+include_once( "Setup.php" );
 include_once( "./rebuildtextindex.inc" );
 $wgTitle = Title::newFromText( "Rebuild text index script" );
 set_time_limit(0);
index 2ab801a..c286b06 100644 (file)
@@ -14,10 +14,9 @@ unset( $IP );
 ini_set( "allow_url_fopen", 0 ); # For security...
 include_once( "./LocalSettings.php" );
 
-$include_path = ini_get( "include_path" );
 # Windows requires ';' as separator, ':' for Unix
-if( strchr( $include_path, ";" ) ) $sep = ";"; else $sep = ":";
-ini_set( "include_path", $IP . $sep . ini_get( "include_path" ) );
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+ini_set( "include_path", "$IP$sep$include_path" );
 
 include_once( "Setup.php" );