00001 <?php
00009 $wgRequestTime = microtime(true);
00010
00012 # Abort if called from a web server
00013 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
00014 print "This script must be run from the command line\n";
00015 exit();
00016 }
00017
00018 if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
00019 print "Sorry! This version of MediaWiki requires PHP 5; you are running " .
00020 PHP_VERSION . ".\n\n" .
00021 "If you are sure you already have PHP 5 installed, it may be " .
00022 "installed\n" .
00023 "in a different path from PHP 4. Check with your system administrator.\n";
00024 die( -1 );
00025 }
00026
00027 define('MEDIAWIKI',true);
00028
00029 # Process command line arguments
00030 # $options becomes an array with keys set to the option names
00031 # $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned
00032 # in the values of $options.
00033 # $args becomes a zero-based array containing the non-option arguments
00034
00035 if ( !isset( $optionsWithArgs ) ) {
00036 $optionsWithArgs = array();
00037 }
00038 $optionsWithArgs[] = 'conf'; # For specifying the location of LocalSettings.php
00039 $optionsWithArgs[] = 'aconf'; # As above for AdminSettings.php
00040 $optionsWithArgs[] = 'wiki'; # For specifying the wiki ID
00041
00042 $self = array_shift( $argv );
00043 $IP = strval( getenv('MW_INSTALL_PATH') ) !== ''
00044 ? getenv('MW_INSTALL_PATH')
00045 : realpath( dirname( __FILE__ ) . '/..' );
00046 #chdir( $IP );
00047 require_once( "$IP/StartProfiler.php" );
00048
00049 $options = array();
00050 $args = array();
00051
00052
00053 # Parse arguments
00054 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
00055 if ( $arg == '--' ) {
00056 # End of options, remainder should be considered arguments
00057 $arg = next( $argv );
00058 while( $arg !== false ) {
00059 $args[] = $arg;
00060 $arg = next( $argv );
00061 }
00062 break;
00063 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
00064 # Long options
00065 $option = substr( $arg, 2 );
00066 if ( in_array( $option, $optionsWithArgs ) ) {
00067 $param = next( $argv );
00068 if ( $param === false ) {
00069 echo "$arg needs a value after it\n";
00070 die( -1 );
00071 }
00072 $options[$option] = $param;
00073 } else {
00074 $bits = explode( '=', $option, 2 );
00075 if( count( $bits ) > 1 ) {
00076 $option = $bits[0];
00077 $param = $bits[1];
00078 } else {
00079 $param = 1;
00080 }
00081 $options[$option] = $param;
00082 }
00083 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
00084 # Short options
00085 for ( $p=1; $p<strlen( $arg ); $p++ ) {
00086 $option = $arg{$p};
00087 if ( in_array( $option, $optionsWithArgs ) ) {
00088 $param = next( $argv );
00089 if ( $param === false ) {
00090 echo "$arg needs a value after it\n";
00091 die( -1 );
00092 }
00093 $options[$option] = $param;
00094 } else {
00095 $options[$option] = 1;
00096 }
00097 }
00098 } else {
00099 $args[] = $arg;
00100 }
00101 }
00102
00103
00104 # General initialisation
00105
00106 $wgCommandLineMode = true;
00107 # Turn off output buffering if it's on
00108 @ob_end_flush();
00109 $sep = PATH_SEPARATOR;
00110
00111 if (!isset( $wgUseNormalUser ) ) {
00112 $wgUseNormalUser = false;
00113 }
00114
00115 if ( file_exists( dirname(__FILE__).'/wikimedia-mode' ) ) {
00116 $wgWikiFarm = true;
00117 $cluster = 'pmtpa';
00118 require_once( "$IP/includes/AutoLoader.php" );
00119 require_once( "$IP/includes/SiteConfiguration.php" );
00120
00121 # Get $wgConf
00122 require( "$IP/wgConf.php" );
00123
00124 if ( empty( $wgNoDBParam ) ) {
00125 # Check if we were passed a db name
00126 if ( isset( $options['wiki'] ) ) {
00127 $db = $options['wiki'];
00128 } else {
00129 $db = array_shift( $args );
00130 }
00131 list( $site, $lang ) = $wgConf->siteFromDB( $db );
00132
00133 # If not, work out the language and site the old way
00134 if ( is_null( $site ) || is_null( $lang ) ) {
00135 if ( !$db ) {
00136 $lang = 'aa';
00137 } else {
00138 $lang = $db;
00139 }
00140 if ( isset( $args[0] ) ) {
00141 $site = array_shift( $args );
00142 } else {
00143 $site = 'wikipedia';
00144 }
00145 }
00146 } else {
00147 $lang = 'aa';
00148 $site = 'wikipedia';
00149 }
00150
00151 # This is for the IRC scripts, which now run as the apache user
00152 # The apache user doesn't have access to the wikiadmin_pass command
00153 if ( $_ENV['USER'] == 'apache' ) {
00154 #if ( posix_geteuid() == 48 ) {
00155 $wgUseNormalUser = true;
00156 }
00157
00158 putenv( 'wikilang='.$lang);
00159
00160 $DP = $IP;
00161 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
00162
00163 if ( $lang == 'test' && $site == 'wikipedia' ) {
00164 define( 'TESTWIKI', 1 );
00165 }
00166
00167 #require_once( $IP.'/includes/ProfilerStub.php' );
00168 require( $IP.'/includes/Defines.php' );
00169 require( $IP.'/CommonSettings.php' );
00170 if ( !$wgUseNormalUser ) {
00171 require( $IP.'/AdminSettings.php' );
00172 }
00173 } else {
00174 $wgWikiFarm = false;
00175 if ( isset( $options['conf'] ) ) {
00176 $settingsFile = $options['conf'];
00177 } else {
00178 $settingsFile = "$IP/LocalSettings.php";
00179 }
00180 if ( isset( $options['wiki'] ) ) {
00181 $bits = explode( '-', $options['wiki'] );
00182 if ( count( $bits ) == 1 ) {
00183 $bits[] = '';
00184 }
00185 define( 'MW_DB', $bits[0] );
00186 define( 'MW_PREFIX', $bits[1] );
00187 }
00188
00189 if ( ! is_readable( $settingsFile ) ) {
00190 print "A copy of your installation's LocalSettings.php\n" .
00191 "must exist and be readable in the source directory.\n";
00192 exit( 1 );
00193 }
00194 $wgCommandLineMode = true;
00195 $DP = $IP;
00196 require_once( "$IP/includes/AutoLoader.php" );
00197 #require_once( $IP.'/includes/ProfilerStub.php' );
00198 require_once( $IP.'/includes/Defines.php' );
00199 require_once( $settingsFile );
00200
00201
00202 $adminSettings = isset( $options['aconf'] )
00203 ? $options['aconf']
00204 : "{$IP}/AdminSettings.php";
00205 if( is_readable( $adminSettings ) )
00206 require_once( $adminSettings );
00207
00208 }
00209
00210 # Turn off output buffering again, it might have been turned on in the settings files
00211 if( ob_get_level() ) {
00212 ob_end_flush();
00213 }
00214 # Same with these
00215 $wgCommandLineMode = true;
00216
00217 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
00218 $wgDBuser = $wgDBadminuser;
00219 $wgDBpassword = $wgDBadminpassword;
00220
00221 if( $wgDBservers ) {
00222 foreach ( $wgDBservers as $i => $server ) {
00223 $wgDBservers[$i]['user'] = $wgDBuser;
00224 $wgDBservers[$i]['password'] = $wgDBpassword;
00225 }
00226 }
00227 if( isset( $wgLBFactoryConf['serverTemplate'] ) ) {
00228 $wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
00229 $wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
00230 }
00231 }
00232
00233 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
00234 $fn = MW_CMDLINE_CALLBACK;
00235 $fn();
00236 }
00237
00238 ini_set( 'memory_limit', -1 );
00239
00240 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
00241
00242
00243
00244 if( ini_get( 'display_errors' ) ) {
00245 ini_set( 'display_errors', 'stderr' );
00246 }
00247
00248
00249
00250
00251
00252
00253 }
00254 $wgShowSQLErrors = true;
00255
00256 require_once( "$IP/includes/Setup.php" );
00257 require_once( "$IP/install-utils.inc" );
00258 $wgTitle = null; # Much much faster startup than creating a title object
00259 @set_time_limit(0);
00260
00261 $wgProfiling = false;