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 $options[$option] = 1;
46 } elseif ( $arg{0} == '-' ) {
48 for ( $p=1; $p<strlen( $arg ); $p++ ) {
50 if ( in_array( $option, $optionsWithArgs ) ) {
51 $param = next( $argv );
52 if ( $param === false ) {
53 die( "$arg needs an value after it\n" );
55 $options[$option] = $param;
57 $options[$option] = 1;
65 # General initialisation
67 $wgCommandLineMode = true;
68 # Turn off output buffering if it's on
70 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
72 if ( $sep == ":" && strpos( `hostname`, "wikimedia.org" ) !== false ) {
74 require_once( "$IP/includes/SiteConfiguration.php" );
77 require( "$IP/InitialiseSettings.php" );
79 # Check if we were passed a db name
80 $db = array_shift( $args );
81 list( $site, $lang ) = $conf->siteFromDB( $db );
83 # If not, work out the language and site the old way
84 if ( is_null( $site ) || is_null( $lang ) ) {
90 if ( isset( $args[0] ) ) {
91 $site = array_shift( $args );
97 # This is for the IRC scripts, which now run as the apache user
98 # The apache user doesn't have access to the wikiadmin_pass command
99 if ( $_ENV['USER'] != "apache" ) {
100 $wgDBuser = $wgDBadminuser = "wikiadmin";
101 $wgDBpassword = $wgDBadminpassword = trim(`wikiadmin_pass`);
104 putenv( "wikilang=$lang");
107 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
109 require_once( "$IP/includes/Defines.php" );
110 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
113 $settingsFile = "$IP/LocalSettings.php";
115 if ( ! is_readable( $settingsFile ) ) {
116 print "A copy of your installation's LocalSettings.php\n" .
117 "must exist in the source directory.\n";
120 $wgCommandLineMode = true;
122 require_once( "$IP/includes/Defines.php" );
123 require_once( $settingsFile );
124 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" );
125 require_once( "$IP/AdminSettings.php" );
128 # Turn off output buffering again, it might have been turned on in the settings files
131 $wgCommandLineMode = true;
132 $wgDBuser = $wgDBadminuser;
133 $wgDBpassword = $wgDBadminpassword;
136 $wgUsePHPTal = false;
137 require_once( "Setup.php" );
138 require_once( "install-utils.inc" );
139 $wgTitle = Title::newFromText( "Command line script" );