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
41 $self = array_shift( $argv );
42 $IP = ( getenv('MW_INSTALL_PATH') !== false
43 ? getenv('MW_INSTALL_PATH')
44 : realpath( dirname( __FILE__ ) . '/..' ) );
46 require_once( "$IP/StartProfiler.php" );
53 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
55 # End of options, remainder should be considered arguments
57 while( $arg !== false ) {
62 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
64 $option = substr( $arg, 2 );
65 if ( in_array( $option, $optionsWithArgs ) ) {
66 $param = next( $argv );
67 if ( $param === false ) {
68 echo "$arg needs a value after it\n";
71 $options[$option] = $param;
73 $bits = explode( '=', $option, 2 );
74 if( count( $bits ) > 1 ) {
80 $options[$option] = $param;
82 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
84 for ( $p=1; $p<strlen( $arg ); $p++ ) {
86 if ( in_array( $option, $optionsWithArgs ) ) {
87 $param = next( $argv );
88 if ( $param === false ) {
89 echo "$arg needs a value after it\n";
92 $options[$option] = $param;
94 $options[$option] = 1;
103 # General initialisation
105 $wgCommandLineMode = true;
106 # Turn off output buffering if it's on
108 $sep = PATH_SEPARATOR;
110 if (!isset( $wgUseNormalUser ) ) {
111 $wgUseNormalUser = false;
114 if ( file_exists( '/home/wikipedia/common/langlist' ) ) {
116 #$cluster = trim( file_get_contents( '/etc/cluster' ) );
118 require_once( "$IP/includes/SiteConfiguration.php" );
121 require( "$IP/wgConf.php" );
123 if ( empty( $wgNoDBParam ) ) {
124 # Check if we were passed a db name
125 $db = array_shift( $args );
126 list( $site, $lang ) = $wgConf->siteFromDB( $db );
128 # If not, work out the language and site the old way
129 if ( is_null( $site ) || is_null( $lang ) ) {
135 if ( isset( $args[0] ) ) {
136 $site = array_shift( $args );
146 # This is for the IRC scripts, which now run as the apache user
147 # The apache user doesn't have access to the wikiadmin_pass command
148 if ( $_ENV['USER'] == 'apache' ) {
149 #if ( posix_geteuid() == 48 ) {
150 $wgUseNormalUser = true;
153 putenv( 'wikilang='.$lang);
156 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
158 if ( $lang == 'test' && $site == 'wikipedia' ) {
159 define( 'TESTWIKI', 1 );
162 #require_once( $IP.'/includes/ProfilerStub.php' );
163 require_once( $IP.'/includes/Defines.php' );
164 require_once( $IP.'/CommonSettings.php' );
166 $bin = '/home/wikipedia/bin';
167 if ( $wgUseRootUser ) {
168 $wgDBuser = $wgDBadminuser = 'root';
169 $wgDBpassword = $wgDBadminpassword = trim(`$bin/mysql_root_pass`);
170 } elseif ( !$wgUseNormalUser ) {
171 $wgDBuser = $wgDBadminuser = 'wikiadmin';
172 $wgDBpassword = $wgDBadminpassword = trim(`$bin/wikiadmin_pass`);
176 if ( isset( $options['conf'] ) ) {
177 $settingsFile = $options['conf'];
179 $settingsFile = "$IP/LocalSettings.php";
182 if ( ! is_readable( $settingsFile ) ) {
183 print "A copy of your installation's LocalSettings.php\n" .
184 "must exist and be readable in the source directory.\n";
187 $wgCommandLineMode = true;
189 #require_once( $IP.'/includes/ProfilerStub.php' );
190 require_once( $IP.'/includes/Defines.php' );
191 require_once( $settingsFile );
192 /* ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); */
194 $adminSettings = isset( $options['aconf'] )
196 : "{$IP}/AdminSettings.php";
197 if( is_readable( $adminSettings ) )
198 require_once( $adminSettings );
202 # Turn off output buffering again, it might have been turned on in the settings files
203 if( ob_get_level() ) {
207 $wgCommandLineMode = true;
209 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
210 $wgDBuser = $wgDBadminuser;
211 $wgDBpassword = $wgDBadminpassword;
214 foreach ( $wgDBservers as $i => $server ) {
215 $wgDBservers[$i]['user'] = $wgDBuser;
216 $wgDBservers[$i]['password'] = $wgDBpassword;
219 if( isset( $wgLBFactoryConf['serverTemplate'] ) ) {
220 $wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
221 $wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
225 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
226 $fn = MW_CMDLINE_CALLBACK;
230 ini_set( 'memory_limit', -1 );
232 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
233 // Send PHP warnings and errors to stderr instead of stdout.
234 // This aids in diagnosing problems, while keeping messages
235 // out of redirected output.
236 if( ini_get( 'display_errors' ) ) {
237 ini_set( 'display_errors', 'stderr' );
240 // Don't touch the setting on earlier versions of PHP,
241 // as setting it would disable output if you'd wanted it.
243 // Note that exceptions are also sent to stderr when
244 // command-line mode is on, regardless of PHP version.
246 $wgShowSQLErrors = true;
248 require_once( "$IP/includes/Setup.php" );
249 require_once( "$IP/install-utils.inc" );
250 $wgTitle = null; # Much much faster startup than creating a title object