Remove obsolete phase2 importer. maintenance/importPhase2.php should perhaps be updat...
[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 $bits = explode( '=', $option, 2 );
45 if( count( $bits ) > 1 ) {
46 $option = $bits[0];
47 $param = $bits[1];
48 } else {
49 $param = 1;
50 }
51 $options[$option] = $param;
52 }
53 } elseif ( $arg{0} == '-' ) {
54 # Short options
55 for ( $p=1; $p<strlen( $arg ); $p++ ) {
56 $option = $arg{$p};
57 if ( in_array( $option, $optionsWithArgs ) ) {
58 $param = next( $argv );
59 if ( $param === false ) {
60 die( "$arg needs an value after it\n" );
61 }
62 $options[$option] = $param;
63 } else {
64 $options[$option] = 1;
65 }
66 }
67 } else {
68 $args[] = $arg;
69 }
70 }
71
72 # General initialisation
73
74 $wgCommandLineMode = true;
75 # Turn off output buffering if it's on
76 @ob_end_flush();
77 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
78
79 if ( $sep == ":" && strpos( `hostname`, "wikimedia.org" ) !== false ) {
80 $wgWikiFarm = true;
81 require_once( "$IP/includes/SiteConfiguration.php" );
82
83 # Get $conf
84 require( "$IP/InitialiseSettings.php" );
85
86 # Check if we were passed a db name
87 $db = array_shift( $args );
88 list( $site, $lang ) = $conf->siteFromDB( $db );
89
90 # If not, work out the language and site the old way
91 if ( is_null( $site ) || is_null( $lang ) ) {
92 if ( !$db ) {
93 $lang = "aa";
94 } else {
95 $lang = $db;
96 }
97 if ( isset( $args[0] ) ) {
98 $site = array_shift( $args );
99 } else {
100 $site = "wikipedia";
101 }
102 }
103
104 # This is for the IRC scripts, which now run as the apache user
105 # The apache user doesn't have access to the wikiadmin_pass command
106 if ( $_ENV['USER'] != "apache" ) {
107 $wgDBuser = $wgDBadminuser = "wikiadmin";
108 $wgDBpassword = $wgDBadminpassword = trim(`wikiadmin_pass`);
109 }
110
111 putenv( "wikilang=$lang");
112
113 $DP = $IP;
114 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
115
116 require_once( "$IP/includes/Defines.php" );
117 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" );
118 } else {
119 $wgWikiFarm = false;
120 $settingsFile = "$IP/LocalSettings.php";
121
122 if ( ! is_readable( $settingsFile ) ) {
123 print "A copy of your installation's LocalSettings.php\n" .
124 "must exist in the source directory.\n";
125 exit();
126 }
127 $wgCommandLineMode = true;
128 $DP = $IP;
129 require_once( "$IP/includes/Defines.php" );
130 require_once( $settingsFile );
131 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" );
132 require_once( "$IP/AdminSettings.php" );
133 }
134
135 # Turn off output buffering again, it might have been turned on in the settings files
136 @ob_end_flush();
137 # Same with these
138 $wgCommandLineMode = true;
139 $wgDBuser = $wgDBadminuser;
140 $wgDBpassword = $wgDBadminpassword;
141
142
143 require_once( "Setup.php" );
144 require_once( "install-utils.inc" );
145 $wgTitle = Title::newFromText( "Command line script" );
146 set_time_limit(0);
147 ?>