4 * @addtogroup Maintenance
7 $wgRequestTime = microtime(true);
10 # Abort if called from a web server
11 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
12 print "This script must be run from the command line\n";
16 if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
17 print "Sorry! This version of MediaWiki requires PHP 5; you are running " .
18 PHP_VERSION . ".\n\n" .
19 "If you are sure you already have PHP 5 installed, it may be " .
21 "in a different path from PHP 4. Check with your system administrator.\n";
25 define('MEDIAWIKI',true);
27 # Process command line arguments
28 # $options becomes an array with keys set to the option names
29 # $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned
30 # in the values of $options.
31 # $args becomes a zero-based array containing the non-option arguments
33 if ( !isset( $optionsWithArgs ) ) {
34 $optionsWithArgs = array();
36 $optionsWithArgs[] = 'conf'; # For specifying the location of LocalSettings.php
38 $self = array_shift( $argv );
39 $IP = realpath( dirname( __FILE__ ) . '/..' );
41 require_once( "$IP/StartProfiler.php" );
48 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
50 # End of options, remainder should be considered arguments
52 while( $arg !== false ) {
57 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
59 $option = substr( $arg, 2 );
60 if ( in_array( $option, $optionsWithArgs ) ) {
61 $param = next( $argv );
62 if ( $param === false ) {
63 echo "$arg needs an value after it\n";
66 $options[$option] = $param;
68 $bits = explode( '=', $option, 2 );
69 if( count( $bits ) > 1 ) {
75 $options[$option] = $param;
77 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
79 for ( $p=1; $p<strlen( $arg ); $p++ ) {
81 if ( in_array( $option, $optionsWithArgs ) ) {
82 $param = next( $argv );
83 if ( $param === false ) {
84 echo "$arg needs an value after it\n";
87 $options[$option] = $param;
89 $options[$option] = 1;
98 # General initialisation
100 $wgCommandLineMode = true;
101 # Turn off output buffering if it's on
103 $sep = PATH_SEPARATOR;
105 if (!isset( $wgUseNormalUser ) ) {
106 $wgUseNormalUser = false;
109 if ( file_exists( '/home/wikipedia/common/langlist' ) ) {
111 $cluster = trim( file_get_contents( '/etc/cluster' ) );
112 require_once( "$IP/includes/SiteConfiguration.php" );
115 require( "$IP/wgConf.php" );
117 if ( empty( $wgNoDBParam ) ) {
118 # Check if we were passed a db name
119 $db = array_shift( $args );
120 list( $site, $lang ) = $wgConf->siteFromDB( $db );
122 # If not, work out the language and site the old way
123 if ( is_null( $site ) || is_null( $lang ) ) {
129 if ( isset( $args[0] ) ) {
130 $site = array_shift( $args );
140 # This is for the IRC scripts, which now run as the apache user
141 # The apache user doesn't have access to the wikiadmin_pass command
142 if ( $_ENV['USER'] == 'apache' ) {
143 #if ( posix_geteuid() == 48 ) {
144 $wgUseNormalUser = true;
147 putenv( 'wikilang='.$lang);
150 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
152 #require_once( $IP.'/includes/ProfilerStub.php' );
153 require_once( $IP.'/includes/Defines.php' );
154 require_once( $IP.'/CommonSettings.php' );
156 $bin = '/home/wikipedia/bin';
157 if ( $wgUseRootUser ) {
158 $wgDBuser = $wgDBadminuser = 'root';
159 $wgDBpassword = $wgDBadminpassword = trim(`$bin/mysql_root_pass`);
160 } elseif ( !$wgUseNormalUser ) {
161 $wgDBuser = $wgDBadminuser = 'wikiadmin';
162 $wgDBpassword = $wgDBadminpassword = trim(`$bin/wikiadmin_pass`);
166 if ( isset( $options['conf'] ) ) {
167 $settingsFile = $options['conf'];
169 $settingsFile = "$IP/LocalSettings.php";
172 if ( ! is_readable( $settingsFile ) ) {
173 print "A copy of your installation's LocalSettings.php\n" .
174 "must exist and be readable in the source directory.\n";
177 $wgCommandLineMode = true;
179 #require_once( $IP.'/includes/ProfilerStub.php' );
180 require_once( $IP.'/includes/Defines.php' );
181 require_once( $settingsFile );
182 ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" );
184 if ( is_readable( $IP.'/AdminSettings.php' ) ) {
185 require_once( $IP.'/AdminSettings.php' );
189 # Turn off output buffering again, it might have been turned on in the settings files
190 if( ob_get_level() ) {
194 $wgCommandLineMode = true;
196 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
197 $wgDBuser = $wgDBadminuser;
198 $wgDBpassword = $wgDBadminpassword;
201 foreach ( $wgDBservers as $i => $server ) {
202 $wgDBservers[$i]['user'] = $wgDBuser;
203 $wgDBservers[$i]['password'] = $wgDBpassword;
208 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
209 $fn = MW_CMDLINE_CALLBACK;
213 ini_set( 'memory_limit', -1 );
215 $wgShowSQLErrors = true;
217 require_once( 'Setup.php' );
218 require_once( 'install-utils.inc' );
219 $wgTitle = null; # Much much faster startup than creating a title object
222 // --------------------------------------------------------------------
224 // --------------------------------------------------------------------
226 function wfWaitForSlaves( $maxLag ) {
227 global $wgLoadBalancer;
229 list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
230 while ( $lag > $maxLag ) {
231 $name = @gethostbyaddr( $host );
232 if ( $name !== false ) {
235 print "Waiting for $host (lagged $lag seconds)...\n";
237 list( $host, $lag ) = $wgLoadBalancer->getMaxLag();