Committed a bunch of live hacks from Wikimedia servers

A few left, but these don't look too evil
This commit is contained in:
Brion Vibber 2006-10-02 17:04:13 +00:00
parent 59e1c916bd
commit bf63ffaa2c
24 changed files with 166 additions and 45 deletions

View 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 ==

View 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 {

View file

@ -374,4 +374,4 @@ class FSTransaction {
class FSException extends MWException { }
?>
?>

View 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;
}

View 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" );
}
}
/**

View 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();

View 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) {

View 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="";

View 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

View 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' );
}
*/
}
}
?>

View 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 );
}

View 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 )

View 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;
}

View 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' );
}

View 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";
}

View 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 );

View 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

View 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);
}
?>

View 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";
}

View 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;
}
}
}
?>

View 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(

View file

@ -1,5 +1,6 @@
<?php
$wgNoDBParam = true;
$optionsWithArgs = array( 'o' );
require_once( dirname(__FILE__).'/../maintenance/commandLine.inc' );
require_once( dirname(__FILE__).'/serialize.php' );

View file

@ -1,6 +1,7 @@
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
$wgNoDBParam = true;
$optionsWithArgs = array( 'o' );
require_once( dirname(__FILE__).'/../maintenance/commandLine.inc' );

View file

@ -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' );