including the new Defines.php
[lhc/web/wiklou.git] / maintenance / commandLine.inc
1 <?php
2
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();
7 }
8
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.
13
14 if ( !isset( $optionsWithArgs ) ) {
15 $optionsWithArgs = array();
16 }
17
18 $self = array_shift( $argv );
19 $IP = realpath( dirname( $self ) . "/.." );
20 chdir( $IP );
21
22 $options = array();
23 $args = array();
24
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 }
55 }
56
57 # General initialisation
58
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" ), ";" ) ? ";" : ":";
63
64 if ( $sep == ":" && strpos( `hostname`, "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 }
76
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`);
82 }
83
84 putenv( "wikilang=$lang");
85
86 $DP = $IP;
87 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
88
89 require_once( "$IP/includes/Defines.php" );
90 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
91 } else {
92 $wgWikiFarm = false;
93 $settingsFile = "$IP/LocalSettings.php";
94
95 if ( ! is_readable( $settingsFile ) ) {
96 print "A copy of your installation's LocalSettings.php\n" .
97 "must exist in the source directory.\n";
98 exit();
99 }
100 $wgCommandLineMode = true;
101 $DP = $IP;
102 require_once( "$IP/includes/Defines.php" );
103 include_once( $settingsFile );
104 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" );
105 include_once( "$IP/AdminSettings.php" );
106 }
107
108 # Turn off output buffering again, it might have been turned on in the settings files
109 @ob_end_flush();
110 # Same with these
111 $wgCommandLineMode = true;
112 $wgDBuser = $wgDBadminuser;
113 $wgDBpassword = $wgDBadminpassword;
114
115
116 $wgUsePHPTal = false;
117 define("MEDIAWIKI",true);
118 require_once( "Setup.php" );
119 require_once( "install-utils.inc" );
120 $wgTitle = Title::newFromText( "Command line script" );
121 set_time_limit(0);
122
123 ?>