5 * @subpackage Maintenance
9 # Abort if called from a web server
10 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
11 print "This script must be run from the command line\n";
15 define("MEDIAWIKI",true);
17 # Process command line arguments
18 # $options becomes an array with keys set to the option names
19 # $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned
20 # in the values of $options.
22 if ( !isset( $optionsWithArgs ) ) {
23 $optionsWithArgs = array();
26 $self = array_shift( $argv );
27 $IP = realpath( dirname( $self ) . "/.." );
33 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
34 if ( substr( $arg, 0, 2 ) == '--' ) {
36 $option = substr( $arg, 2 );
37 if ( in_array( $option, $optionsWithArgs ) ) {
38 $param = next( $argv );
39 if ( $param === false ) {
40 die( "$arg needs an value after it\n" );
42 $options[$option] = $param;
44 $bits = explode( '=', $option, 2 );
45 if( count( $bits ) > 1 ) {
51 $options[$option] = $param;
53 } elseif ( $arg{0} == '-' ) {
55 for ( $p=1; $p<strlen( $arg ); $p++ ) {
57 if ( in_array( $option, $optionsWithArgs ) ) {
58 $param = next( $argv );
59 if ( $param === false ) {
60 die( "$arg needs an value after it\n" );
62 $options[$option] = $param;
64 $options[$option] = 1;
72 # General initialisation
74 $wgCommandLineMode = true;
75 # Turn off output buffering if it's on
77 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
79 if ( $sep == ":" && strpos( `hostname`, "wikimedia.org" ) !== false ) {
81 require_once( "$IP/includes/SiteConfiguration.php" );
84 require( "$IP/InitialiseSettings.php" );
86 # Check if we were passed a db name
87 $db = array_shift( $args );
88 list( $site, $lang ) = $conf->siteFromDB( $db );
90 # If not, work out the language and site the old way
91 if ( is_null( $site ) || is_null( $lang ) ) {
97 if ( isset( $args[0] ) ) {
98 $site = array_shift( $args );
104 # This is for the IRC scripts, which now run as the apache user
105 # The apache user doesn't have access to the wikiadmin_pass command
106 if ( $_ENV['USER'] != "apache" ) {
107 $wgDBuser = $wgDBadminuser = "wikiadmin";
108 $wgDBpassword = $wgDBadminpassword = trim(`wikiadmin_pass`);
111 putenv( "wikilang=$lang");
114 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
116 require_once( "$IP/includes/Defines.php" );
117 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
120 $settingsFile = "$IP/LocalSettings.php";
122 if ( ! is_readable( $settingsFile ) ) {
123 print "A copy of your installation's LocalSettings.php\n" .
124 "must exist in the source directory.\n";
127 $wgCommandLineMode = true;
129 require_once( "$IP/includes/Defines.php" );
130 require_once( $settingsFile );
131 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" );
132 require_once( "$IP/AdminSettings.php" );
135 # Turn off output buffering again, it might have been turned on in the settings files
138 $wgCommandLineMode = true;
139 $wgDBuser = $wgDBadminuser;
140 $wgDBpassword = $wgDBadminpassword;
143 $wgUsePHPTal = false;
144 require_once( "Setup.php" );
145 require_once( "install-utils.inc" );
146 $wgTitle = Title::newFromText( "Command line script" );