Committed a bunch of live hacks from Wikimedia servers
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 2 Oct 2006 17:04:13 +0000 (17:04 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 2 Oct 2006 17:04:13 +0000 (17:04 +0000)
A few left, but these don't look too evil

24 files changed:
RELEASE-NOTES
includes/Database.php
includes/FileStore.php
includes/LoadBalancer.php
includes/MagicWord.php
includes/Parser.php
includes/ProfilerSimple.php
includes/ProfilerSimpleUDP.php
includes/Setup.php
includes/SiteStatsUpdate.php
includes/SpecialExport.php
includes/SpecialShortpages.php
includes/StreamFile.php
includes/Wiki.php
maintenance/addwiki.php
maintenance/deleteBatch.php
maintenance/dumpInterwiki.inc
maintenance/mctest.php
maintenance/ourusers.php
maintenance/runJobs.php
maintenance/storage/compressOld.inc
serialized/serialize-localisation.php
serialized/serialize.php
thumb.php

index 13096c9..22babed 100644 (file)
@@ -251,6 +251,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   "I can't import dumps from Wikipedia" complaints
 * (bug 7460) Revert broken patch for bug 7226 which slows down
   Special:Allmessages by a factor of 16
+* Committed a bunch of live hacks from Wikimedia servers
 
 
 == Languages updated ==
index eaecc1a..f620b28 100644 (file)
@@ -490,12 +490,26 @@ class Database {
 
                $success = false;
 
-               if ( $this->mFlags & DBO_PERSISTENT ) {
-                       @/**/$this->mConn = mysql_pconnect( $server, $user, $password );
-               } else {
-                       # Create a new connection...
-                       @/**/$this->mConn = mysql_connect( $server, $user, $password, true );
+                wfProfileIn("dbconnect-$server");
+               
+               # LIVE PATCH by Tim, ask Domas for why: retry loop
+               $this->mConn = false;
+               for ( $i = 0; $i < 3 && !$this->mConn; $i++ ) {
+                       if ( $i > 1 ) {
+                               usleep( 1000 );
+                       }
+                       if ( $this->mFlags & DBO_PERSISTENT ) {
+                               @/**/$this->mConn = mysql_pconnect( $server, $user, $password );
+                       } else {
+                               # Create a new connection...
+                               @/**/$this->mConn = mysql_connect( $server, $user, $password, true );
+                       }
+                        if ($this->mConn === false) {
+                            wfLogDBError("Connect loop error ($server): " . mysql_errno() . " - " . mysql_error()."\n"); 
+                        }
                }
+               
+                wfProfileOut("dbconnect-$server");
 
                if ( $dbName != '' ) {
                        if ( $this->mConn !== false ) {
@@ -503,6 +517,7 @@ class Database {
                                if ( !$success ) {
                                        $error = "Error selecting database $dbName on server {$this->mServer} " .
                                                "from client host {$wguname['nodename']}\n";
+                                        wfLogDBError(" Error selecting database $dbname on server {$this->mServer} \n");
                                        wfDebug( $error );
                                }
                        } else {
index 85aaedf..c81504a 100644 (file)
@@ -374,4 +374,4 @@ class FSTransaction {
 
 class FSException extends MWException { }
 
-?>
\ No newline at end of file
+?>
index cbee03e..33c23bb 100644 (file)
@@ -623,6 +623,9 @@ class LoadBalancer {
                                wfProfileOut( __METHOD__ );
                                return $times;
                        }
+                       wfIncrStats( 'lag_cache_miss_expired' );
+               } else {
+                       wfIncrStats( 'lag_cache_miss_absent' );
                }
 
                # Cache key missing or expired
@@ -642,7 +645,6 @@ class LoadBalancer {
 
                # But don't give the timestamp to the caller
                unset($times['timestamp']);
-               wfIncrStats( 'lag_cache_miss' );
                wfProfileOut( __METHOD__ );
                return $times;
        }
index 826a7e9..511efab 100644 (file)
@@ -155,6 +155,11 @@ class MagicWord {
                global $wgContLang;
                $this->mId = $id;
                $wgContLang->getMagic( $this );
+               if ( !$this->mSynonyms ) {
+                       $this->mSynonyms = array( 'dkjsagfjsgashfajsh' );
+                       #throw new MWException( "Error: invalid magic word '$id'" );
+                       wfDebugLog( 'exception', "Error: invalid magic word '$id'\n" );
+               }
        }
 
        /**
index 7332180..31ec709 100644 (file)
@@ -272,7 +272,7 @@ class Parser
                 */
 
                global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
-               $fname = 'Parser::parse';
+               $fname = 'Parser::parse-' . wfGetCaller();
                wfProfileIn( $fname );
 
                if ( $clearState ) {
@@ -3787,7 +3787,11 @@ class Parser
 
                wfProfileIn($fname);
 
-               $this->mTitle = $wgTitle;
+               if ( $wgTitle ) {
+                       $this->mTitle = $wgTitle;
+               } else {
+                       $this->mTitle = Title::newFromText('msg');
+               }
                $this->mOptions = $options;
                $this->setOutputType( OT_MSG );
                $this->clearState();
index 0f2b59a..d5bdaf9 100644 (file)
@@ -11,6 +11,8 @@
 require_once(dirname(__FILE__).'/Profiler.php');
 
 class ProfilerSimple extends Profiler {
+       var $mMinimumTime = 0;
+
        function ProfilerSimple() {
                global $wgRequestTime,$wgRUstart;
                if (!empty($wgRequestTime) && !empty($wgRUstart)) {
@@ -33,6 +35,10 @@ class ProfilerSimple extends Profiler {
                }
        }
 
+       function setMinimum( $min ) {
+               $this->mMinimumTime = $min;
+       }
+
        function profileIn($functionname) {
                global $wgDebugFunctionEntry;
                if ($wgDebugFunctionEntry) {
index 5c8da13..1eb2c5f 100644 (file)
@@ -12,6 +12,12 @@ class ProfilerSimpleUDP extends ProfilerSimple {
                global $wgUDPProfilerPort;
                global $wgDBname;
 
+               if ( $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
+                       # Less than minimum, ignore
+                       return;
+               }
+                       
+               
                $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
                $plength=0;
                $packet="";
index 2a8e6e5..d529fea 100644 (file)
@@ -184,7 +184,10 @@ wfProfileIn( $fname.'-extensions' );
 # of the extension file. This allows the extension to perform
 # any necessary initialisation in the fully initialised environment
 foreach ( $wgExtensionFunctions as $func ) {
+       $profName = $fname.'-extensions-'.strval( $func );
+       wfProfileIn( $profName );
        call_user_func( $func );
+       wfProfileOut( $profName );
 }
 
 // For compatibility
index 1b6d380..b91dcfe 100644 (file)
@@ -75,8 +75,18 @@ class SiteStatsUpdate {
                if ( $updates ) {
                        $site_stats = $dbw->tableName( 'site_stats' );
                        $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1);
+                       $dbw->begin();
                        $dbw->query( $sql, $fname );
+                       $dbw->commit();
                }
+
+               /*
+               global $wgDBname, $wgTitle;
+               if ( $this->mGood && $wgDBname == 'enwiki' ) {
+                       $good = $dbw->selectField( 'site_stats', 'ss_good_articles', '', $fname );
+                       error_log( $good . ' ' . $wgTitle->getPrefixedDBkey() . "\n", 3, '/home/wikipedia/logs/million.log' );
+               }
+               */
        }
 }
 ?>
index a402b65..3e56f2f 100644 (file)
@@ -31,13 +31,12 @@ require_once( 'Export.php' );
 function wfSpecialExport( $page = '' ) {
        global $wgOut, $wgRequest, $wgExportAllowListContributors;
        global $wgExportAllowHistory, $wgExportMaxHistory;
-       $maxLimit = 200;
 
        $curonly = true;
        $fullHistory = array(
                'dir' => 'asc',
                'offset' => false,
-               'limit' => $maxLimit,
+               'limit' => $wgExportMaxHistory,
        );
        if( $wgRequest->wasPosted() ) {
                $page = $wgRequest->getText( 'pages' );
@@ -53,13 +52,13 @@ function wfSpecialExport( $page = '' ) {
                $history = array(
                        'dir' => 'asc',
                        'offset' => false,
-                       'limit' => $maxLimit,
+                       'limit' => $wgExportMaxHistory,
                );
                $historyCheck = $wgRequest->getCheck( 'history' );
                if ( $curonly ) {
                        $history = MW_EXPORT_CURRENT;
                } elseif ( !$historyCheck ) {
-                       if ( $limit > 0 && $limit < $maxLimit ) {
+                       if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
                                $history['limit'] = $limit;
                        }
                        if ( !is_null( $offset ) ) {
@@ -107,6 +106,7 @@ function wfSpecialExport( $page = '' ) {
                $exporter->openStream();
                
                foreach( $pages as $page ) {
+                       /*
                        if( $wgExportMaxHistory && !$curonly ) {
                                $title = Title::newFromText( $page );
                                if( $title ) {
@@ -117,7 +117,7 @@ function wfSpecialExport( $page = '' ) {
                                                continue;
                                        }
                                }
-                       }
+                       }*/
                        $exporter->pageByName( $page );
                }
                
index d8e13c7..34b3505 100644 (file)
@@ -65,6 +65,9 @@ class ShortPagesPage extends QueryPage {
                $dm = $wgContLang->getDirMark();
                
                $title = Title::makeTitleSafe( $result->namespace, $result->title );
+               if ( !$title ) {
+                       return '<!-- Invalid title ' .  htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
+               }
                $hlink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
                $plink = $this->isCached()
                                        ? $skin->makeLinkObj( $title )
index 8341718..99cb4d7 100644 (file)
@@ -6,10 +6,12 @@ function wfStreamFile( $fname ) {
        $stat = @stat( $fname );
        if ( !$stat ) {
                header( 'HTTP/1.0 404 Not Found' );
+               $encFile = htmlspecialchars( $fname );
+               $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
                echo "<html><body>
 <h1>File not found</h1>
-<p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
-does not.</p>
+<p>Although this PHP script ($encScript) exists, the file requested for output 
+($encFile) does not.</p>
 </body></html>";
                return;
        }
index f613638..401756b 100644 (file)
@@ -264,8 +264,14 @@ class MediaWiki {
         */
        function doUpdates ( &$updates ) {
                wfProfileIn( 'MediaWiki::doUpdates' );
+               $dbw =& wfGetDB( DB_MASTER );
                foreach( $updates as $up ) {
                        $up->doUpdate();
+
+                       # Commit after every update to prevent lock contention
+                       if ( $dbw->trxLevel() ) {
+                               $dbw->commit();
+                       }
                }
                wfProfileOut( 'MediaWiki::doUpdates' );
        }
index 253033a..b784363 100644 (file)
@@ -33,26 +33,40 @@ function addWiki( $lang, $site, $dbName )
        print "Initialising tables\n";
        dbsource( "$maintenance/tables.sql", $dbw );
        dbsource( "$IP/extensions/OAI/update_table.sql", $dbw );
+       dbsource( "$IP/extensions/AntiSpoof/mysql/patch-antispoof.sql", $dbw );
        $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
 
        # Initialise external storage
-       if ( $wgDefaultExternalStore && preg_match( '!^DB://(.*)$!', $wgDefaultExternalStore, $m ) ) {
-               print "Initialising external storage...\n";
+       if ( is_array( $wgDefaultExternalStore ) ) {
+               $stores = $wgDefaultExternalStore;
+       } elseif ( $stores ) {
+               $stores = array( $wgDefaultExternalStore );
+       } else {
+               $stores = array();
+       }
+       if ( count( $stores ) ) {
                require_once( 'ExternalStoreDB.php' );
+               print "Initialising external storage $store...\n";
                global $wgDBuser, $wgDBpassword, $wgExternalServers;
-               $cluster = $m[1];
-               
-               # Hack
-               $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
-               $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
-               
-               $store = new ExternalStoreDB;
-               $extdb =& $store->getMaster( $cluster );
-               $extdb->query( "SET table_type=InnoDB" );
-               $extdb->query( "CREATE DATABASE $dbName" );
-               $extdb->selectDB( $dbName );
-               dbsource( "$maintenance/storage/blobs.sql", $extdb );
-               $extdb->immediateCommit();
+               foreach ( $stores as $storeURL ) {
+                       if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
+                               continue;
+                       }
+                       
+                       $cluster = $m[1];
+                       
+                       # Hack
+                       $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
+                       $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
+                       
+                       $store = new ExternalStoreDB;
+                       $extdb =& $store->getMaster( $cluster );
+                       $extdb->query( "SET table_type=InnoDB" );
+                       $extdb->query( "CREATE DATABASE $dbName" );
+                       $extdb->selectDB( $dbName );
+                       dbsource( "$maintenance/storage/blobs.sql", $extdb );
+                       $extdb->immediateCommit();
+               }
        }
 
        $wgTitle = Title::newMainPage();
@@ -203,7 +217,17 @@ See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedia
        fclose( $file );
        print "Sourcing interwiki SQL\n";
        dbsource( $tempname, $dbw );
-       unlink( $tempname );
+       #unlink( $tempname );
+       
+       # Create the upload dir
+       global $wgUploadDirectory;
+       if( file_exists( $wgUploadDirectory ) ) {
+               echo "$wgUploadDirectory already exists.\n";
+       } else {
+               echo "Creating $wgUploadDirectory...\n";
+               mkdir( $wgUploadDirectory, 0777 );
+               chmod( $wgUploadDirectory, 0777 );
+       }
 
        print "Script ended. You now want to run sync-common-all to publish *dblist files (check them for duplicates first)\n";
 }
index 697dffd..234744c 100644 (file)
@@ -71,9 +71,13 @@ for ( $linenum = 1; !feof( $file ); $linenum++ ) {
        } else {
                $art = new Article( $page );
        }
-       $art->doDelete( $reason );
+       $success = $art->doDeleteArticle( $reason );
        $dbw->immediateCommit();
-       print "\n";
+       if ( $success ) {
+               print "\n";
+       } else {
+               print " FAILED\n";
+       }
 
        if ( $interval ) {
                sleep( $interval );
index 3cca1e0..f7a56ee 100644 (file)
@@ -43,6 +43,7 @@ function getRebuildInterwikiDump() {
                'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ),
                'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ),
                'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ),
+               'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ),
        );
 
        # List of language prefixes likely to be found in multi-language sites
index 7deaa07..316620d 100644 (file)
@@ -5,6 +5,13 @@ $optionsWithArgs = array( 'i' );
 
 require_once('commandLine.inc');
 
+function microtime_float()
+{
+   list($usec, $sec) = explode(" ", microtime());
+   return ((float)$usec + (float)$sec);
+}
+
+
 #$wgDebugLogFile = '/dev/stdout';
 
 if ( isset( $args[0] ) ) {
@@ -49,11 +56,5 @@ foreach ( $wgMemCachedServers as $server ) {
        print "set: $set   incr: $incr   get: $get time: $exectime\n";
 }
 
-function microtime_float()
-{
-   list($usec, $sec) = explode(" ", microtime());
-   return ((float)$usec + (float)$sec);
-}
-
 
 ?>
index e244578..b50519d 100644 (file)
@@ -54,8 +54,7 @@ print "/*!40100 set global old_passwords=1 */;";
 foreach( $hosts as $host ) {
        print "--\n-- $host\n--\n\n-- wikiuser\n\n";
        print "GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n";
-       print "GRANT ALL PRIVILEGES ON `boardvote`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n";
-       print "GRANT ALL PRIVILEGES ON `boardvote2005`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n";
+       print "GRANT ALL PRIVILEGES ON `boardvote%`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n";
        foreach( $databases as $db ) {
                print "GRANT SELECT, INSERT, UPDATE, DELETE ON `$db`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n";
        }
@@ -84,8 +83,7 @@ EOS;
 
        print "\n-- wikiadmin\n\n";
        print "GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'wikiadmin'@'$host' IDENTIFIED BY '$wikiadmin_pass';\n";
-       print "GRANT ALL PRIVILEGES ON `boardvote`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n";
-       print "GRANT ALL PRIVILEGES ON `boardvote2005`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n";
+       print "GRANT ALL PRIVILEGES ON `boardvote%`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n";
        foreach ( $databases as $db ) {
                print "GRANT ALL PRIVILEGES ON `$db`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n";
        }
index d72addc..343cda8 100644 (file)
@@ -1,13 +1,22 @@
 <?php
 
+$optionsWithArgs = array( 'maxjobs' );
+$wgUseNormalUser = true;
 require_once( 'commandLine.inc' );
 require_once( "$IP/includes/JobQueue.php" );
 require_once( "$IP/includes/FakeTitle.php" );
 
+if ( isset( $options['maxjobs'] ) ) {
+       $maxJobs = $options['maxjobs'];
+} else {
+       $maxJobs = 10000;
+}
+
 // Trigger errors on inappropriate use of $wgTitle
 $wgTitle = new FakeTitle;
 
 $dbw =& wfGetDB( DB_MASTER );
+$n = 0;
 while ( $dbw->selectField( 'job', 'count(*)', '', 'runJobs.php' ) ) {
        while ( false != ($job = Job::pop()) ) {
                wfWaitForSlaves( 5 );
@@ -15,6 +24,9 @@ while ( $dbw->selectField( 'job', 'count(*)', '', 'runJobs.php' ) ) {
                if ( !$job->run() ) {
                        print "Error: {$job->error}\n";
                }
+               if ( $maxJobs && ++$n > $maxJobs ) {
+                       break 2;
+               }
        }
 }
 ?>
index b7d7094..3c42684 100644 (file)
@@ -155,6 +155,17 @@ function compressWithConcat( $startId, $maxChunkSize, $maxChunkFactor, $factorTh
                $titleObj = Title::makeTitle( $pageRow->page_namespace, $pageRow->page_title );
                print "$pageId\t" . $titleObj->getPrefixedDBkey() . " ";
 
+               print_r(
+                       array( 
+                               'rev_page' => $pageRow->page_id, 
+                               # Don't operate on the current revision
+                               # Use < instead of <> in case the current revision has changed 
+                               # since the page select, which wasn't locking
+                               'rev_id < ' . $pageRow->page_latest
+                       ) + $conds
+               );
+               exit;
+
                # Load revisions
                $revRes = $dbw->select( $tables, $fields,
                        array( 
index 10624ba..925806b 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+$wgNoDBParam = true;
 $optionsWithArgs = array( 'o' );
 require_once( dirname(__FILE__).'/../maintenance/commandLine.inc' );
 require_once( dirname(__FILE__).'/serialize.php' );
index 78b7789..0eaf0b1 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 if ( !defined( 'MEDIAWIKI' ) ) {
+       $wgNoDBParam = true;
        $optionsWithArgs = array( 'o' );
        require_once( dirname(__FILE__).'/../maintenance/commandLine.inc' );
 
index bc794eb..545f644 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -76,7 +76,12 @@ if ( $img ) {
        $thumb = false;
 }
 
-if ( $thumb && $thumb->path ) {
+if ( $img->lastError && $img->lastError !== true ) {
+       header( 'HTTP/1.0 500 Internal Server Error' );
+       echo "<html><body><h1>Thumbnail generation error</h1><p>" . 
+               htmlspecialchars( $img->lastError ) . "<br>" . wfHostname() .
+               "</p></body></html>";
+} elseif ( $thumb && $thumb->path ) {
        wfStreamFile( $thumb->path );
 } else {
        $badtitle = wfMsg( 'badtitle' );