wiki.techinc.nl/maintenance/commandLine.inc

249 lines
6.2 KiB
PHP
Raw Normal View History

<?php
/**
* @todo document
* @addtogroup Maintenance
*/
$wgRequestTime = microtime(true);
/** */
# Abort if called from a web server
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
print "This script must be run from the command line\n";
exit();
}
if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
print "Sorry! This version of MediaWiki requires PHP 5; you are running " .
PHP_VERSION . ".\n\n" .
"If you are sure you already have PHP 5 installed, it may be " .
"installed\n" .
"in a different path from PHP 4. Check with your system administrator.\n";
die( -1 );
}
2005-12-03 19:25:39 +00:00
define('MEDIAWIKI',true);
# Process command line arguments
# $options becomes an array with keys set to the option names
# $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned
# in the values of $options.
# $args becomes a zero-based array containing the non-option arguments
if ( !isset( $optionsWithArgs ) ) {
$optionsWithArgs = array();
}
$optionsWithArgs[] = 'conf'; # For specifying the location of LocalSettings.php
$optionsWithArgs[] = 'aconf'; # As above for AdminSettings.php
$self = array_shift( $argv );
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$IP = realpath( dirname( __FILE__ ) . '/..' );
#chdir( $IP );
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
require_once( "$IP/StartProfiler.php" );
$options = array();
$args = array();
2005-12-03 19:25:39 +00:00
# Parse arguments
for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
if ( $arg == '--' ) {
# End of options, remainder should be considered arguments
$arg = next( $argv );
while( $arg !== false ) {
$args[] = $arg;
$arg = next( $argv );
}
break;
} elseif ( substr( $arg, 0, 2 ) == '--' ) {
# Long options
$option = substr( $arg, 2 );
if ( in_array( $option, $optionsWithArgs ) ) {
$param = next( $argv );
if ( $param === false ) {
echo "$arg needs an value after it\n";
die( -1 );
}
$options[$option] = $param;
} else {
$bits = explode( '=', $option, 2 );
if( count( $bits ) > 1 ) {
$option = $bits[0];
$param = $bits[1];
} else {
$param = 1;
}
$options[$option] = $param;
}
} elseif ( substr( $arg, 0, 1 ) == '-' ) {
# Short options
for ( $p=1; $p<strlen( $arg ); $p++ ) {
$option = $arg{$p};
if ( in_array( $option, $optionsWithArgs ) ) {
$param = next( $argv );
if ( $param === false ) {
echo "$arg needs an value after it\n";
die( -1 );
}
$options[$option] = $param;
} else {
$options[$option] = 1;
}
}
} else {
$args[] = $arg;
2004-06-12 12:56:00 +00:00
}
}
2005-12-03 19:25:39 +00:00
# General initialisation
$wgCommandLineMode = true;
# Turn off output buffering if it's on
@ob_end_flush();
$sep = PATH_SEPARATOR;
if (!isset( $wgUseNormalUser ) ) {
$wgUseNormalUser = false;
}
if ( file_exists( '/home/wikipedia/common/langlist' ) ) {
$wgWikiFarm = true;
$cluster = trim( file_get_contents( '/etc/cluster' ) );
require_once( "$IP/includes/SiteConfiguration.php" );
2004-08-14 06:10:56 +00:00
# Get $wgConf
require( "$IP/wgConf.php" );
2004-08-14 06:10:56 +00:00
2005-06-24 21:42:00 +00:00
if ( empty( $wgNoDBParam ) ) {
# Check if we were passed a db name
$db = array_shift( $args );
list( $site, $lang ) = $wgConf->siteFromDB( $db );
2004-08-14 06:10:56 +00:00
2005-06-24 21:42:00 +00:00
# If not, work out the language and site the old way
if ( is_null( $site ) || is_null( $lang ) ) {
2006-01-07 13:31:29 +00:00
if ( !$db ) {
2005-12-03 19:25:39 +00:00
$lang = 'aa';
2005-06-24 21:42:00 +00:00
} else {
$lang = $db;
}
if ( isset( $args[0] ) ) {
$site = array_shift( $args );
} else {
2005-12-03 19:25:39 +00:00
$site = 'wikipedia';
2005-06-24 21:42:00 +00:00
}
2004-08-14 06:10:56 +00:00
}
2005-06-24 21:42:00 +00:00
} else {
2005-12-03 19:25:39 +00:00
$lang = 'aa';
$site = 'wikipedia';
}
# This is for the IRC scripts, which now run as the apache user
# The apache user doesn't have access to the wikiadmin_pass command
2005-12-03 19:25:39 +00:00
if ( $_ENV['USER'] == 'apache' ) {
#if ( posix_geteuid() == 48 ) {
$wgUseNormalUser = true;
}
2005-12-03 19:25:39 +00:00
putenv( 'wikilang='.$lang);
$DP = $IP;
2005-12-03 19:25:39 +00:00
ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
#require_once( $IP.'/includes/ProfilerStub.php' );
2005-12-03 19:25:39 +00:00
require_once( $IP.'/includes/Defines.php' );
require_once( $IP.'/CommonSettings.php' );
2005-06-26 07:02:40 +00:00
$bin = '/home/wikipedia/bin';
if ( $wgUseRootUser ) {
2005-12-03 19:25:39 +00:00
$wgDBuser = $wgDBadminuser = 'root';
$wgDBpassword = $wgDBadminpassword = trim(`$bin/mysql_root_pass`);
} elseif ( !$wgUseNormalUser ) {
2005-12-03 19:25:39 +00:00
$wgDBuser = $wgDBadminuser = 'wikiadmin';
$wgDBpassword = $wgDBadminpassword = trim(`$bin/wikiadmin_pass`);
2005-06-26 07:02:40 +00:00
}
} else {
$wgWikiFarm = false;
if ( isset( $options['conf'] ) ) {
$settingsFile = $options['conf'];
} else {
2006-08-04 20:59:13 +00:00
$settingsFile = "$IP/LocalSettings.php";
}
2004-06-12 12:56:00 +00:00
if ( ! is_readable( $settingsFile ) ) {
print "A copy of your installation's LocalSettings.php\n" .
"must exist and be readable in the source directory.\n";
exit( 1 );
2004-06-12 12:56:00 +00:00
}
$wgCommandLineMode = true;
$DP = $IP;
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
#require_once( $IP.'/includes/ProfilerStub.php' );
2005-12-03 19:25:39 +00:00
require_once( $IP.'/includes/Defines.php' );
require_once( $settingsFile );
/* ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); */
2006-01-07 13:31:29 +00:00
$adminSettings = isset( $options['aconf'] )
? $options['aconf']
: "{$IP}/AdminSettings.php";
if( is_readable( $adminSettings ) )
require_once( $adminSettings );
2004-06-12 12:56:00 +00:00
}
# Turn off output buffering again, it might have been turned on in the settings files
Prevent the following strict-standards warnings - i.e. when running with error_logging(E_ALL | E_STRICT); - which seems to disable the yucky "@" operator, as well as maxing out the pedantry of warnings. Nothing major found, just nice to be as explicit and as forward-compatible as possible. * Strict Standards: Undefined index: switch in includes/Parser.php on line 3849 * Strict Standards: Undefined index: ref in includes/Parser.php on line 3818 * Strict Standards: Non-static method OutputPage::setEncodings() should not be called statically in index.php on line 11 * Strict Standards: Only variables should be assigned by reference in includes/Skin.php on line 888 * Strict Standards: Non-static method Title::newFromURL() should not be called statically in includes/SpecialContributions.php on line 178 * Strict Standards: Only variables should be assigned by reference in includes/GlobalFunctions.php on line 2054 * Strict Standards: Undefined index: contributions-summary in languages/Language.php on line 764 * Strict Standards: Undefined index: trackbackhtml in skins/MonoBook.php on line 86 * Strict Standards: Undefined index: blockip in skins/MonoBook.php on line 204 * Strict Standards: Undefined index: tagline in skins/MonoBook.php on line 261 * Strict Standards: Undefined index: uselang in includes/SkinTemplate.php on line 1159 * Strict Standards: Non-static method CoreParserFunctions::plural() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Undefined offset: 0 in includes/SkinTemplate.php on line 196 * Strict Standards: Undefined index: USE INDEX in includes/Database.php on line 1015 * Strict Standards: Undefined index: image_tests in includes/Parser.php on line 3488 * Strict Standards: Undefined offset: 0 in includes/Parser.php on line 3507 * Strict Standards: Non-static method ChangesList::newFromUser() should not be called statically in includes/SpecialWatchlist.php on line 361 * Strict Standards: Non-static method RecentChange::newFromCurRow() should not be called statically in includes/SpecialWatchlist.php on line 367 * Strict Standards: is_a(): Deprecated. Please use the instanceof operator in includes/Exception.php on line 168 * Strict Standards: Non-static method LogPage::logName() should not be called statically in includes/SpecialContributions.php on line 325 * Strict Standards: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in maintenance/commandLine.inc on line 191 * Strict Standards: Undefined index: meatball in languages/Language.php on line 234 * Strict Standards: rmdir(/tmp/mwParser-2108164586-images/thumb): Directory not empty in maintenance/parserTests.inc on line 605 * Cleaning out some new temp files left over by parserTests (there were one or two straggler dirs/files that would persist after the test run ended, due to new tests being added over time) * Strict Standards: Non-static method CoreParserFunctions::special() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Declaration of ListUsersPage::preprocessResults() should be compatible with that of QueryPage::preprocessResults() in includes/SpecialListusers.php on line 38 * Strict Standards: Only variables should be passed by reference in includes/SpecialBlockip.php on line 175 * Strict Standards: Skin::include_once(skins/Standard.deps.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in includes/Skin.php on line 121 * Strict Standards: Declaration of ApiMain::getResult() should be compatible with that of ApiBase::getResult() in includes/api/ApiMain.php on line 35 * Strict Standards: is_a(): Deprecated. Please use the instanceof operator in includes/WikiError.php on line 63 * Strict Standards: Non-static method WikiError::isError() should not be called statically in includes/SpecialImport.php on line 64 * Strict Standards: Non-static method ImportStreamSource::newFromInterwiki() should not be called statically in includes/SpecialImport.php on line 58<b * Strict Standards: Only variables should be assigned by reference in includes/SpecialUndelete.php on line 501 * Strict Standards: Non-static method Image::newFromName() should not be called statically in thumb.php on line 56 * Strict Standards: Non-static method CoreParserFunctions::numberoffiles() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Non-static method CoreParserFunctions::statisticsFunction() should not be called statically in includes/CoreParserFunctions.php on line 139 * Strict Standards: Non-static method CoreParserFunctions::isRaw() should not be called statically in includes/CoreParserFunctions.php on line 128 * Strict Standards: Non-static method CoreParserFunctions::grammar() cannot be called statically in includes/Parser.php on line 2902 * Strict Standards: Undefined offset: 1 in includes/SpecialMIMEsearch.php on line 130 * Strict Standards: Undefined index: recentchangeslinked in skins/MonoBook.php on line 184 * Strict Standards: Declaration of DumpNotalkFilter::pass() should be compatible with that of DumpFilter::pass() in includes/Export.php on line 612 * Strict Standards: Declaration of DumpNamespaceFilter::pass() should be compatible with that of DumpFilter::pass() in includes/Export.php on line 665 * Strict Standards: Non-static method ImportStreamSource::newFromUpload() should not be called statically in includes/SpecialImport.php on line 46 * Strict Standards: Undefined offset: 5 in includes/Sanitizer.php on line 396 * Strict Standards: Undefined index: wikidbUserName in includes/SpecialUserlogin.php on line 562 * Strict Standards: Only variables should be assigned by reference in includes/api/ApiQueryBase.php on line 95 * Strict Standards: Only variables should be assigned by reference in includes/api/ApiQueryBase.php on line 116 * Strict Standards: Only variables should be assigned by reference in includes/api/ApiQueryWatchlist.php on line 128 * Strict Standards: Undefined property: stdClass::$rc_id in includes/api/ApiQueryBase.php on line 131 * Strict Standards: Undefined property: stdClass::$rc_last_oldid in includes/api/ApiQueryBase.php on line 164 * Strict Standards: Undefined property: stdClass::$rc_moved_to_ns in includes/api/ApiQueryBase.php on line 285 * Strict Standards: Undefined property: stdClass::$rc_patrolled in includes/api/ApiQueryBase.php on line 176 * Strict Standards: Undefined index: comment in includes/api/ApiFeedWatchlist.php on line 85 * Strict Standards: Undefined offset: 0 in includes/Skin.php on line 302 * Strict Standards: Non-static method User::SetupSession() should not be called statically in includes/SpecialUserlogin.php on line 15 ... There are certain to be other things too, so this is not intended to be comprehensive, rather the above just stops most of the notifications I observed.
2006-11-29 05:45:03 +00:00
if( ob_get_level() ) {
ob_end_flush();
}
2004-06-26 07:08:31 +00:00
# Same with these
$wgCommandLineMode = true;
2004-06-26 07:08:31 +00:00
if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
$wgDBuser = $wgDBadminuser;
$wgDBpassword = $wgDBadminpassword;
if( $wgDBservers ) {
foreach ( $wgDBservers as $i => $server ) {
$wgDBservers[$i]['user'] = $wgDBuser;
$wgDBservers[$i]['password'] = $wgDBpassword;
}
}
}
if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
$fn = MW_CMDLINE_CALLBACK;
$fn();
}
ini_set( 'memory_limit', -1 );
$wgShowSQLErrors = true;
require_once( "$IP/includes/Setup.php" );
require_once( "$IP/install-utils.inc" );
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$wgTitle = null; # Much much faster startup than creating a title object
set_time_limit(0);
// --------------------------------------------------------------------
// Functions
// --------------------------------------------------------------------
function wfWaitForSlaves( $maxLag ) {
global $wgLoadBalancer;
if ( $maxLag ) {
list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
while ( $lag > $maxLag ) {
$name = @gethostbyaddr( $host );
if ( $name !== false ) {
$host = $name;
}
print "Waiting for $host (lagged $lag seconds)...\n";
sleep($maxLag);
list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
}
}
}
?>