bug fix
[mediawiki.git] / maintenance / commandLine.inc
blobee1d78e863e2e84e4eabb6fa204ea98d07f6e30b
1 <?php
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";
6         exit();
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 ) . "/.." );
20 chdir( $IP );
22 $options = array();
23 $args = array();
25 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
26         if ( substr( $arg, 0, 2 ) == '--' ) {
27                 # Long options
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" );
33                         }
34                         $options[$option] = $param;
35                 } else {
36                         $options[$option] = 1;
37                 }
38         } elseif ( $arg{0} == '-' ) {
39                 # Short options
40                 for ( $p=1; $p<strlen( $arg ); $p++ ) {
41                         $option = $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" );
46                                 }
47                                 $options[$option] = $param;
48                         } else {
49                                 $options[$option] = 1;
50                         }
51                 }
52         } else {
53                 $args[] = $arg;
54         }
57 # General initialisation
59 $wgCommandLineMode = true;
60 # Turn off output buffering if it's on
61 @ob_end_flush();
62 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
64 if ( $sep == ":" && strpos( `hostname -a`, "wikimedia.org" ) !== false ) {
65         $wgWikiFarm = true;
66         if ( isset( $args[0] ) ) {
67                 $lang = array_shift( $args );
68         } else {
69                 $lang = "aa";
70         }
71         if ( isset( $args[0] ) ) {
72                 $site = array_shift( $args );
73         } else {
74                 $site = "wikipedia";
75         }
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                 $wgDBadminuser = "wikiadmin";
81                 $wgDBadminpassword = trim(`wikiadmin_pass`);
82         }
84         putenv( "wikilang=$lang");
86         $DP = $IP;
87         ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
89         require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
90 } else {
91         $wgWikiFarm = false;
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";
97                 exit();
98         }
99         $wgCommandLineMode = true;
100         $DP = $IP;
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
107 @ob_end_flush();
108 # Same with this one
109 $wgCommandLineMode = true;
111 $wgUsePHPTal = false;
112 define("MEDIAWIKI",true);
113 require_once( "Setup.php" );
114 require_once( "install-utils.inc" );
115 $wgTitle = Title::newFromText( "Command line script" );
116 set_time_limit(0);