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 = ( getenv('MW_INSTALL_PATH') !== false
41 ? getenv('MW_INSTALL_PATH')
42 : realpath( dirname( __FILE__ ) . '/..' ) );
44 require_once( "$IP/StartProfiler.php" );
51 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
53 # End of options, remainder should be considered arguments
55 while( $arg !== false ) {
60 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
62 $option = substr( $arg, 2 );
63 if ( in_array( $option, $optionsWithArgs ) ) {
64 $param = next( $argv );
65 if ( $param === false ) {
66 echo "$arg needs an value after it\n";
69 $options[$option] = $param;
71 $bits = explode( '=', $option, 2 );
72 if( count( $bits ) > 1 ) {
78 $options[$option] = $param;
80 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
82 for ( $p=1; $p<strlen( $arg ); $p++ ) {
84 if ( in_array( $option, $optionsWithArgs ) ) {
85 $param = next( $argv );
86 if ( $param === false ) {
87 echo "$arg needs an value after it\n";
90 $options[$option] = $param;
92 $options[$option] = 1;
101 # General initialisation
103 $wgCommandLineMode = true;
104 # Turn off output buffering if it's on
106 $sep = PATH_SEPARATOR;
108 if (!isset( $wgUseNormalUser ) ) {
109 $wgUseNormalUser = false;
112 if ( file_exists( '/home/wikipedia/common/langlist' ) ) {
114 $cluster = trim( file_get_contents( '/etc/cluster' ) );
115 require_once( "$IP/includes/SiteConfiguration.php" );
118 require( "$IP/wgConf.php" );
120 if ( empty( $wgNoDBParam ) ) {
121 # Check if we were passed a db name
122 $db = array_shift( $args );
123 list( $site, $lang ) = $wgConf->siteFromDB( $db );
125 # If not, work out the language and site the old way
126 if ( is_null( $site ) || is_null( $lang ) ) {
132 if ( isset( $args[0] ) ) {
133 $site = array_shift( $args );
143 # This is for the IRC scripts, which now run as the apache user
144 # The apache user doesn't have access to the wikiadmin_pass command
145 if ( $_ENV['USER'] == 'apache' ) {
146 #if ( posix_geteuid() == 48 ) {
147 $wgUseNormalUser = true;
150 putenv( 'wikilang='.$lang);
153 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
155 #require_once( $IP.'/includes/ProfilerStub.php' );
156 require_once( $IP.'/includes/Defines.php' );
157 require_once( $IP.'/CommonSettings.php' );
159 $bin = '/home/wikipedia/bin';
160 if ( $wgUseRootUser ) {
161 $wgDBuser = $wgDBadminuser = 'root';
162 $wgDBpassword = $wgDBadminpassword = trim(`$bin/mysql_root_pass`);
163 } elseif ( !$wgUseNormalUser ) {
164 $wgDBuser = $wgDBadminuser = 'wikiadmin';
165 $wgDBpassword = $wgDBadminpassword = trim(`$bin/wikiadmin_pass`);
169 if ( isset( $options['conf'] ) ) {
170 $settingsFile = $options['conf'];
172 $settingsFile = "$IP/LocalSettings.php";
175 if ( ! is_readable( $settingsFile ) ) {
176 print "A copy of your installation's LocalSettings.php\n" .
177 "must exist and be readable in the source directory.\n";
180 $wgCommandLineMode = true;
182 #require_once( $IP.'/includes/ProfilerStub.php' );
183 require_once( $IP.'/includes/Defines.php' );
184 require_once( $settingsFile );
185 /* ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); */
187 $adminSettings = isset( $options['aconf'] )
189 : "{$IP}/AdminSettings.php";
190 if( is_readable( $adminSettings ) )
191 require_once( $adminSettings );
195 # Turn off output buffering again, it might have been turned on in the settings files
196 if( ob_get_level() ) {
200 $wgCommandLineMode = true;
202 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
203 $wgDBuser = $wgDBadminuser;
204 $wgDBpassword = $wgDBadminpassword;
207 foreach ( $wgDBservers as $i => $server ) {
208 $wgDBservers[$i]['user'] = $wgDBuser;
209 $wgDBservers[$i]['password'] = $wgDBpassword;
214 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
215 $fn = MW_CMDLINE_CALLBACK;
219 ini_set( 'memory_limit', -1 );
221 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
222 // Send PHP warnings and errors to stderr instead of stdout.
223 // This aids in diagnosing problems, while keeping messages
224 // out of redirected output.
225 if( ini_get( 'display_errors' ) ) {
226 ini_set( 'display_errors', 'stderr' );
229 // Don't touch the setting on earlier versions of PHP,
230 // as setting it would disable output if you'd wanted it.
232 // Note that exceptions are also sent to stderr when
233 // command-line mode is on, regardless of PHP version.
235 $wgShowSQLErrors = true;
237 require_once( "$IP/includes/Setup.php" );
238 require_once( "$IP/install-utils.inc" );
239 $wgTitle = null; # Much much faster startup than creating a title object