From 04e6adebb8fefe85cfd3c017d3e84e4f24b82f50 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 17 Nov 2003 12:55:24 +0000 Subject: [PATCH] Maintenance script fixes --- maintenance/checktrans.php | 2 +- maintenance/cleandb.php | 8 +++++-- maintenance/rebuildall.php | 6 +++++- maintenance/rebuildlinks.inc | 31 +++++++++++++++++++++++----- maintenance/rebuildlinks.php | 6 +++++- maintenance/rebuildrecentchanges.inc | 22 ++++++++++---------- maintenance/rebuildrecentchanges.php | 6 +++++- maintenance/rebuildtextindex.php | 8 +++++-- wiki.phtml | 5 ++--- 9 files changed, 67 insertions(+), 27 deletions(-) diff --git a/maintenance/checktrans.php b/maintenance/checktrans.php index f390a4faf0..ef0e9fcd39 100644 --- a/maintenance/checktrans.php +++ b/maintenance/checktrans.php @@ -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 ); diff --git a/maintenance/cleandb.php b/maintenance/cleandb.php index cf346a00e3..3dc75d34b7 100644 --- a/maintenance/cleandb.php +++ b/maintenance/cleandb.php @@ -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" ); diff --git a/maintenance/rebuildall.php b/maintenance/rebuildall.php index 9e64d193c3..7b556264aa 100644 --- a/maintenance/rebuildall.php +++ b/maintenance/rebuildall.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( "./rebuildlinks.inc" ); include_once( "./rebuildtextindex.inc" ); include_once( "./rebuildrecentchanges.inc" ); diff --git a/maintenance/rebuildlinks.inc b/maintenance/rebuildlinks.inc index 047476e91b..6a6bc26a8d 100644 --- a/maintenance/rebuildlinks.inc +++ b/maintenance/rebuildlinks.inc @@ -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 "; diff --git a/maintenance/rebuildlinks.php b/maintenance/rebuildlinks.php index de756c1911..9405a037c4 100644 --- a/maintenance/rebuildlinks.php +++ b/maintenance/rebuildlinks.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( "./rebuildlinks.inc" ); $wgTitle = Title::newFromText( "Rebuild links script" ); set_time_limit(0); diff --git a/maintenance/rebuildrecentchanges.inc b/maintenance/rebuildrecentchanges.inc index 2d9c00933a..92d2ab5d0d 100644 --- a/maintenance/rebuildrecentchanges.inc +++ b/maintenance/rebuildrecentchanges.inc @@ -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 ) ) { diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php index 894353f179..3803c1a85f 100644 --- a/maintenance/rebuildrecentchanges.php +++ b/maintenance/rebuildrecentchanges.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( "./rebuildrecentchanges.inc" ); $wgTitle = Title::newFromText( "Rebuild recent changes script" ); set_time_limit(0); diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index bbc5327d3b..2ca73567d4 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -1,6 +1,6 @@