Phpdoc comments and place holder. Part of the subpackage "maintenance", archives...
[lhc/web/wiklou.git] / maintenance / commandLine.inc
1 <?php
2 /**
3 * @todo document
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
7
8 /** */
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";
12 exit();
13 }
14
15 define("MEDIAWIKI",true);
16
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.
21
22 if ( !isset( $optionsWithArgs ) ) {
23 $optionsWithArgs = array();
24 }
25
26 $self = array_shift( $argv );
27 $IP = realpath( dirname( $self ) . "/.." );
28 chdir( $IP );
29
30 $options = array();
31 $args = array();
32
33 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
34 if ( substr( $arg, 0, 2 ) == '--' ) {
35 # Long options
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" );
41 }
42 $options[$option] = $param;
43 } else {
44 $options[$option] = 1;
45 }
46 } elseif ( $arg{0} == '-' ) {
47 # Short options
48 for ( $p=1; $p<strlen( $arg ); $p++ ) {
49 $option = $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" );
54 }
55 $options[$option] = $param;
56 } else {
57 $options[$option] = 1;
58 }
59 }
60 } else {
61 $args[] = $arg;
62 }
63 }
64
65 # General initialisation
66
67 $wgCommandLineMode = true;
68 # Turn off output buffering if it's on
69 @ob_end_flush();
70 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
71
72 if ( $sep == ":" && strpos( `hostname`, "wikimedia.org" ) !== false ) {
73 $wgWikiFarm = true;
74 require_once( "$IP/includes/SiteConfiguration.php" );
75
76 # Get $conf
77 require( "$IP/InitialiseSettings.php" );
78
79 # Check if we were passed a db name
80 $db = array_shift( $args );
81 list( $site, $lang ) = $conf->siteFromDB( $db );
82
83 # If not, work out the language and site the old way
84 if ( is_null( $site ) || is_null( $lang ) ) {
85 if ( !$db ) {
86 $lang = "aa";
87 } else {
88 $lang = $db;
89 }
90 if ( isset( $args[0] ) ) {
91 $site = array_shift( $args );
92 } else {
93 $site = "wikipedia";
94 }
95 }
96
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`);
102 }
103
104 putenv( "wikilang=$lang");
105
106 $DP = $IP;
107 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
108
109 require_once( "$IP/includes/Defines.php" );
110 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
111 } else {
112 $wgWikiFarm = false;
113 $settingsFile = "$IP/LocalSettings.php";
114
115 if ( ! is_readable( $settingsFile ) ) {
116 print "A copy of your installation's LocalSettings.php\n" .
117 "must exist in the source directory.\n";
118 exit();
119 }
120 $wgCommandLineMode = true;
121 $DP = $IP;
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" );
126 }
127
128 # Turn off output buffering again, it might have been turned on in the settings files
129 @ob_end_flush();
130 # Same with these
131 $wgCommandLineMode = true;
132 $wgDBuser = $wgDBadminuser;
133 $wgDBpassword = $wgDBadminpassword;
134
135
136 $wgUsePHPTal = false;
137 require_once( "Setup.php" );
138 require_once( "install-utils.inc" );
139 $wgTitle = Title::newFromText( "Command line script" );
140 set_time_limit(0);
141
142 ?>