3 # Abort if called from a web server
4 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
5 print "This script must be run from the command line\n";
9 # Process command line arguments
10 # $options becomes an array with keys set to the option names
11 # $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned
12 # in the values of $options.
14 if ( !isset( $optionsWithArgs ) ) {
15 $optionsWithArgs = array();
18 $self = array_shift( $argv );
19 $IP = realpath( dirname( $self ) . "/.." );
25 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
26 if ( substr( $arg, 0, 2 ) == '--' ) {
28 $option = substr( $arg, 2 );
29 if ( in_array( $option, $optionsWithArgs ) ) {
30 $param = next( $argv );
31 if ( $param === false ) {
32 die( "$arg needs an value after it\n" );
34 $options[$option] = $param;
36 $options[$option] = 1;
38 } elseif ( $arg{0} == '-' ) {
40 for ( $p=1; $p<strlen( $arg ); $p++ ) {
42 if ( in_array( $option, $optionsWithArgs ) ) {
43 $param = next( $argv );
44 if ( $param === false ) {
45 die( "$arg needs an value after it\n" );
47 $options[$option] = $param;
49 $options[$option] = 1;
57 # General initialisation
59 $wgCommandLineMode = true;
60 # Turn off output buffering if it's on
62 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
64 if ( $sep == ":" && strpos( `hostname -a`, "wikimedia.org" ) !== false ) {
66 if ( isset( $args[0] ) ) {
67 $lang = array_shift( $args );
71 if ( isset( $args[0] ) ) {
72 $site = array_shift( $args );
77 # This is for the IRC scripts, which now run as the apache user
78 # The apache user doesn't have access to the wikiadmin_pass command
79 if ( $_ENV['USER'] != "apache" ) {
80 $wgDBuser = $wgDBadminuser = "wikiadmin";
81 $wgDBpassword = $wgDBadminpassword = trim(`wikiadmin_pass`);
84 putenv( "wikilang=$lang");
87 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
89 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
92 $settingsFile = "$IP/LocalSettings.php";
94 if ( ! is_readable( $settingsFile ) ) {
95 print "A copy of your installation's LocalSettings.php\n" .
96 "must exist in the source directory.\n";
99 $wgCommandLineMode = true;
101 include_once( $settingsFile );
102 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" );
103 include_once( "$IP/AdminSettings.php" );
106 # Turn off output buffering again, it might have been turned on in the settings files
109 $wgCommandLineMode = true;
110 $wgDBuser = $wgDBadminuser;
111 $wgDBpassword = $wgDBadminpassword;
114 $wgUsePHPTal = false;
115 define("MEDIAWIKI",true);
116 require_once( "Setup.php" );
117 require_once( "install-utils.inc" );
118 $wgTitle = Title::newFromText( "Command line script" );