Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

commandLine.inc

Go to the documentation of this file.
00001 <?php 00002 00003 # Abort if called from a web server 00004 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) { 00005 print "This script must be run from the command line\n"; 00006 exit(); 00007 } 00008 00009 # Process command line arguments 00010 # $options becomes an array with keys set to the option names 00011 # $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned 00012 # in the values of $options. 00013 00014 if ( !isset( $optionsWithArgs ) ) { 00015 $optionsWithArgs = array(); 00016 } 00017 00018 $self = array_shift( $argv ); 00019 $IP = realpath( dirname( $self ) . "/.." ); 00020 chdir( $IP ); 00021 00022 $options = array(); 00023 $args = array(); 00024 00025 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) { 00026 if ( substr( $arg, 0, 2 ) == '--' ) { 00027 # Long options 00028 $option = substr( $arg, 2 ); 00029 if ( in_array( $option, $optionsWithArgs ) ) { 00030 $param = next( $argv ); 00031 if ( $param === false ) { 00032 die( "$arg needs an value after it\n" ); 00033 } 00034 $options[$option] = $param; 00035 } else { 00036 $options[$option] = 1; 00037 } 00038 } elseif ( $arg{0} == '-' ) { 00039 # Short options 00040 for ( $p=1; $p<strlen( $arg ); $p++ ) { 00041 $option = $arg{$p}; 00042 if ( in_array( $option, $optionsWithArgs ) ) { 00043 $param = next( $argv ); 00044 if ( $param === false ) { 00045 die( "$arg needs an value after it\n" ); 00046 } 00047 $options[$option] = $param; 00048 } else { 00049 $options[$option] = 1; 00050 } 00051 } 00052 } else { 00053 $args[] = $arg; 00054 } 00055 } 00056 00057 # General initialisation 00058 00059 $wgCommandLineMode = true; 00060 # Turn off output buffering if it's on 00061 @ob_end_flush(); 00062 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":"; 00063 00064 if ( $sep == ":" && strpos( `hostname -a`, "wikimedia.org" ) !== false ) { 00065 $wgWikiFarm = true; 00066 if ( isset( $args[0] ) ) { 00067 $lang = array_shift( $args ); 00068 } else { 00069 $lang = "aa"; 00070 } 00071 if ( isset( $args[0] ) ) { 00072 $site = array_shift( $args ); 00073 } else { 00074 $site = "wikipedia"; 00075 } 00076 00077 # This is for the IRC scripts, which now run as the apache user 00078 # The apache user doesn't have access to the wikiadmin_pass command 00079 if ( $_ENV['USER'] != "apache" ) { 00080 $wgDBadminuser = "wikiadmin"; 00081 $wgDBadminpassword = trim(`wikiadmin_pass`); 00082 } 00083 00084 putenv( "wikilang=$lang"); 00085 00086 $DP = $IP; 00087 ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" ); 00088 00089 require_once( "/home/wikipedia/common/php-new/CommonSettings.php" ); 00090 } else { 00091 $wgWikiFarm = false; 00092 $settingsFile = "$IP/LocalSettings.php"; 00093 00094 if ( ! is_readable( $settingsFile ) ) { 00095 print "A copy of your installation's LocalSettings.php\n" . 00096 "must exist in the source directory.\n"; 00097 exit(); 00098 } 00099 $wgCommandLineMode = true; 00100 $DP = $IP; 00101 include_once( $settingsFile ); 00102 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); 00103 include_once( "$IP/AdminSettings.php" ); 00104 } 00105 00106 # Turn off output buffering again, it might have been turned on in the settings files 00107 @ob_end_flush(); 00108 # Same with this one 00109 $wgCommandLineMode = true; 00110 00111 $wgUsePHPTal = false; 00112 define("MEDIAWIKI",true); 00113 require_once( "Setup.php" ); 00114 require_once( "install-utils.inc" ); 00115 $wgTitle = Title::newFromText( "Command line script" ); 00116 set_time_limit(0); 00117 00118 ?>

Generated on Tue Jun 29 23:40:03 2004 for Mediawiki by doxygen 1.3.7