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
37 $optionsWithArgs[] = 'aconf'; # As above for AdminSettings.php
39 $self = array_shift( $argv );
40 $IP = realpath( dirname( __FILE__ ) . '/..' );
42 require_once( "$IP/StartProfiler.php" );
49 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
51 # End of options, remainder should be considered arguments
53 while( $arg !== false ) {
58 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
60 $option = substr( $arg, 2 );
61 if ( in_array( $option, $optionsWithArgs ) ) {
62 $param = next( $argv );
63 if ( $param === false ) {
64 echo "$arg needs an value after it\n";
67 $options[$option] = $param;
69 $bits = explode( '=', $option, 2 );
70 if( count( $bits ) > 1 ) {
76 $options[$option] = $param;
78 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
80 for ( $p=1; $p<strlen( $arg ); $p++ ) {
82 if ( in_array( $option, $optionsWithArgs ) ) {
83 $param = next( $argv );
84 if ( $param === false ) {
85 echo "$arg needs an value after it\n";
88 $options[$option] = $param;
90 $options[$option] = 1;
99 # General initialisation
101 $wgCommandLineMode = true;
102 # Turn off output buffering if it's on
104 $sep = PATH_SEPARATOR;
106 if (!isset( $wgUseNormalUser ) ) {
107 $wgUseNormalUser = false;
110 if ( file_exists( '/home/wikipedia/common/langlist' ) ) {
112 $cluster = trim( file_get_contents( '/etc/cluster' ) );
113 require_once( "$IP/includes/SiteConfiguration.php" );
116 require( "$IP/wgConf.php" );
118 if ( empty( $wgNoDBParam ) ) {
119 # Check if we were passed a db name
120 $db = array_shift( $args );
121 list( $site, $lang ) = $wgConf->siteFromDB( $db );
123 # If not, work out the language and site the old way
124 if ( is_null( $site ) || is_null( $lang ) ) {
130 if ( isset( $args[0] ) ) {
131 $site = array_shift( $args );
141 # This is for the IRC scripts, which now run as the apache user
142 # The apache user doesn't have access to the wikiadmin_pass command
143 if ( $_ENV['USER'] == 'apache' ) {
144 #if ( posix_geteuid() == 48 ) {
145 $wgUseNormalUser = true;
148 putenv( 'wikilang='.$lang);
151 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
153 #require_once( $IP.'/includes/ProfilerStub.php' );
154 require_once( $IP.'/includes/Defines.php' );
155 require_once( $IP.'/CommonSettings.php' );
157 $bin = '/home/wikipedia/bin';
158 if ( $wgUseRootUser ) {
159 $wgDBuser = $wgDBadminuser = 'root';
160 $wgDBpassword = $wgDBadminpassword = trim(`$bin/mysql_root_pass`);
161 } elseif ( !$wgUseNormalUser ) {
162 $wgDBuser = $wgDBadminuser = 'wikiadmin';
163 $wgDBpassword = $wgDBadminpassword = trim(`$bin/wikiadmin_pass`);
167 if ( isset( $options['conf'] ) ) {
168 $settingsFile = $options['conf'];
170 $settingsFile = "$IP/LocalSettings.php";
173 if ( ! is_readable( $settingsFile ) ) {
174 print "A copy of your installation's LocalSettings.php\n" .
175 "must exist and be readable in the source directory.\n";
178 $wgCommandLineMode = true;
180 #require_once( $IP.'/includes/ProfilerStub.php' );
181 require_once( $IP.'/includes/Defines.php' );
182 require_once( $settingsFile );
183 /* ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); */
185 $adminSettings = isset( $options['aconf'] )
187 : "{$IP}/AdminSettings.php";
188 if( is_readable( $adminSettings ) )
189 require_once( $adminSettings );
193 # Turn off output buffering again, it might have been turned on in the settings files
194 if( ob_get_level() ) {
198 $wgCommandLineMode = true;
200 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
201 $wgDBuser = $wgDBadminuser;
202 $wgDBpassword = $wgDBadminpassword;
205 foreach ( $wgDBservers as $i => $server ) {
206 $wgDBservers[$i]['user'] = $wgDBuser;
207 $wgDBservers[$i]['password'] = $wgDBpassword;
212 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
213 $fn = MW_CMDLINE_CALLBACK;
217 ini_set( 'memory_limit', -1 );
219 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
220 // Send PHP warnings and errors to stderr instead of stdout.
221 // This aids in diagnosing problems, while keeping messages
222 // out of redirected output.
223 if( ini_get( 'display_errors' ) ) {
224 ini_set( 'display_errors', 'stderr' );
227 // Don't touch the setting on earlier versions of PHP,
228 // as setting it would disable output if you'd wanted it.
230 // Note that exceptions are also sent to stderr when
231 // command-line mode is on, regardless of PHP version.
233 $wgShowSQLErrors = true;
235 require_once( "$IP/includes/Setup.php" );
236 require_once( "$IP/install-utils.inc" );
237 $wgTitle = null; # Much much faster startup than creating a title object