6 * @defgroup Maintenance Maintenance
9 $wgRequestTime = microtime(true);
12 # Abort if called from a web server
13 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
14 print "This script must be run from the command line\n";
18 if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
19 print "Sorry! This version of MediaWiki requires PHP 5; you are running " .
20 PHP_VERSION . ".\n\n" .
21 "If you are sure you already have PHP 5 installed, it may be " .
23 "in a different path from PHP 4. Check with your system administrator.\n";
27 define('MEDIAWIKI',true);
29 # Process command line arguments
30 # $options becomes an array with keys set to the option names
31 # $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned
32 # in the values of $options.
33 # $args becomes a zero-based array containing the non-option arguments
35 if ( !isset( $optionsWithArgs ) ) {
36 $optionsWithArgs = array();
38 $optionsWithArgs[] = 'conf'; # For specifying the location of LocalSettings.php
39 $optionsWithArgs[] = 'aconf'; # As above for AdminSettings.php
40 $optionsWithArgs[] = 'wiki'; # For specifying the wiki ID
42 $self = array_shift( $argv );
43 $IP = strval( getenv('MW_INSTALL_PATH') ) !== ''
44 ? getenv('MW_INSTALL_PATH')
45 : realpath( dirname( __FILE__ ) . '/..' );
47 require_once( "$IP/StartProfiler.php" );
54 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
56 # End of options, remainder should be considered arguments
58 while( $arg !== false ) {
63 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
65 $option = substr( $arg, 2 );
66 if ( in_array( $option, $optionsWithArgs ) ) {
67 $param = next( $argv );
68 if ( $param === false ) {
69 echo "$arg needs a value after it\n";
72 $options[$option] = $param;
74 $bits = explode( '=', $option, 2 );
75 if( count( $bits ) > 1 ) {
81 $options[$option] = $param;
83 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
85 for ( $p=1; $p<strlen( $arg ); $p++ ) {
87 if ( in_array( $option, $optionsWithArgs ) ) {
88 $param = next( $argv );
89 if ( $param === false ) {
90 echo "$arg needs a value after it\n";
93 $options[$option] = $param;
95 $options[$option] = 1;
104 # General initialisation
106 $wgCommandLineMode = true;
107 # Turn off output buffering if it's on
109 $sep = PATH_SEPARATOR;
111 if (!isset( $wgUseNormalUser ) ) {
112 $wgUseNormalUser = false;
115 if ( file_exists( dirname(__FILE__).'/wikimedia-mode' ) ) {
118 require_once( "$IP/includes/AutoLoader.php" );
119 require_once( "$IP/includes/SiteConfiguration.php" );
122 require( "$IP/wgConf.php" );
124 if ( empty( $wgNoDBParam ) ) {
125 # Check if we were passed a db name
126 if ( isset( $options['wiki'] ) ) {
127 $db = $options['wiki'];
129 $db = array_shift( $args );
131 list( $site, $lang ) = $wgConf->siteFromDB( $db );
133 # If not, work out the language and site the old way
134 if ( is_null( $site ) || is_null( $lang ) ) {
140 if ( isset( $args[0] ) ) {
141 $site = array_shift( $args );
151 # This is for the IRC scripts, which now run as the apache user
152 # The apache user doesn't have access to the wikiadmin_pass command
153 if ( $_ENV['USER'] == 'apache' ) {
154 #if ( posix_geteuid() == 48 ) {
155 $wgUseNormalUser = true;
158 putenv( 'wikilang='.$lang);
161 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
163 if ( $lang == 'test' && $site == 'wikipedia' ) {
164 define( 'TESTWIKI', 1 );
167 #require_once( $IP.'/includes/ProfilerStub.php' );
168 require( $IP.'/includes/Defines.php' );
169 require( $IP.'/CommonSettings.php' );
170 if ( !$wgUseNormalUser ) {
171 require( $IP.'/AdminSettings.php' );
175 if ( isset( $options['conf'] ) ) {
176 $settingsFile = $options['conf'];
178 $settingsFile = "$IP/LocalSettings.php";
180 if ( isset( $options['wiki'] ) ) {
181 $bits = explode( '-', $options['wiki'] );
182 if ( count( $bits ) == 1 ) {
185 define( 'MW_DB', $bits[0] );
186 define( 'MW_PREFIX', $bits[1] );
189 if ( ! is_readable( $settingsFile ) ) {
190 print "A copy of your installation's LocalSettings.php\n" .
191 "must exist and be readable in the source directory.\n";
194 $wgCommandLineMode = true;
196 require_once( "$IP/includes/AutoLoader.php" );
197 #require_once( $IP.'/includes/ProfilerStub.php' );
198 require_once( $IP.'/includes/Defines.php' );
199 require_once( $settingsFile );
200 /* ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); */
202 $adminSettings = isset( $options['aconf'] )
204 : "{$IP}/AdminSettings.php";
205 if( is_readable( $adminSettings ) )
206 require_once( $adminSettings );
210 # Turn off output buffering again, it might have been turned on in the settings files
211 if( ob_get_level() ) {
215 $wgCommandLineMode = true;
217 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
218 $wgDBuser = $wgDBadminuser;
219 $wgDBpassword = $wgDBadminpassword;
222 foreach ( $wgDBservers as $i => $server ) {
223 $wgDBservers[$i]['user'] = $wgDBuser;
224 $wgDBservers[$i]['password'] = $wgDBpassword;
227 if( isset( $wgLBFactoryConf['serverTemplate'] ) ) {
228 $wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
229 $wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
233 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
234 $fn = MW_CMDLINE_CALLBACK;
238 ini_set( 'memory_limit', -1 );
240 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
241 // Send PHP warnings and errors to stderr instead of stdout.
242 // This aids in diagnosing problems, while keeping messages
243 // out of redirected output.
244 if( ini_get( 'display_errors' ) ) {
245 ini_set( 'display_errors', 'stderr' );
248 // Don't touch the setting on earlier versions of PHP,
249 // as setting it would disable output if you'd wanted it.
251 // Note that exceptions are also sent to stderr when
252 // command-line mode is on, regardless of PHP version.
254 $wgShowSQLErrors = true;
256 require_once( "$IP/includes/Setup.php" );
257 require_once( "$IP/install-utils.inc" );
258 $wgTitle = null; # Much much faster startup than creating a title object
261 $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors