00001 <?php
00002
00010 function install_version_checks() {
00011 # We dare not turn output buffer _off_ since this will break completely
00012 # if PHP is globally configured to run through a gzip filter.
00013 @ob_implicit_flush( true );
00014
00015 if( !function_exists( 'version_compare' ) ) {
00016 # version_compare was introduced in 4.1.0
00017 echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.1.0 or higher is required. ABORTING.\n";
00018 die( 1 );
00019 }
00020 if( version_compare( phpversion(), '5.1.0' ) < 0 ) {
00021 echo "PHP 5.1.0 or higher is required. If PHP 5 is available only when \n".
00022 "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
00023 "to continue installation. ABORTING.\n";
00024 die( 1 );
00025 }
00026
00027 $test = new PhpXmlBugTester();
00028 if( !$test->ok ) {
00029 echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
00030 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
00031 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
00032 "ABORTING (http://bugs.php.net/bug.php?id=45996 for details).\n";
00033 die( 1 );
00034 }
00035
00036 $test = new PhpRefCallBugTester;
00037 $test->execute();
00038 if ( !$test->ok ) {
00039 echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" .
00040 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
00041 "downgrade to PHP 5.3.0 to fix this.\n" .
00042 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
00043 die( 1 );
00044 }
00045
00046 global $wgCommandLineMode;
00047 $wgCommandLineMode = true;
00048 umask( 000 );
00049 @set_time_limit( 0 );
00050 }
00051
00057 class PhpXmlBugTester {
00058 private $parsedData = '';
00059 public $ok = false;
00060 public function __construct() {
00061 $charData = '<b>c</b>';
00062 $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
00063
00064 $parser = xml_parser_create();
00065 xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
00066 $parsedOk = xml_parse($parser, $xml, true);
00067 $this->ok = $parsedOk && ($this->parsedData == $charData);
00068 }
00069 public function chardata($parser, $data) {
00070 $this->parsedData .= $data;
00071 }
00072 }
00073
00077 class PhpRefCallBugTester {
00078 public $ok = false;
00079
00080 function __call( $name, $args ) {
00081 $old = error_reporting( E_ALL & ~E_WARNING );
00082 call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
00083 error_reporting( $old );
00084 }
00085
00086 function checkForBrokenRef( &$var ) {
00087 if ( $var ) {
00088 $this->ok = true;
00089 }
00090 }
00091
00092 function execute() {
00093 $var = true;
00094 call_user_func_array( array( $this, 'foo' ), array( &$var ) );
00095 }
00096 }
00097
00098 function readconsole( $prompt = '' ) {
00099 static $isatty = null;
00100 if ( is_null( $isatty ) ) {
00101 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 ) ) {
00102 $isatty = true;
00103 } else {
00104 $isatty = false;
00105 }
00106 }
00107
00108 if ( $isatty && function_exists( 'readline' ) ) {
00109 return readline( $prompt );
00110 } else {
00111 if ( $isatty ) {
00112 $st = readlineEmulation( $prompt );
00113 } else {
00114 if ( feof( STDIN ) ) {
00115 $st = false;
00116 } else {
00117 $st = fgets(STDIN, 1024);
00118 }
00119 }
00120 if ($st === false) return false;
00121 $resp = trim( $st );
00122 return $resp;
00123 }
00124 }
00125
00126 function findExecutable( $name ) {
00127 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
00128 foreach( $paths as $path ) {
00129 $full = $path . DIRECTORY_SEPARATOR . $name;
00130 if( file_exists( $full ) ) {
00131 if( wfIsWindows() || is_executable( $full ) ) {
00132 return $full;
00133 }
00134 }
00135 }
00136 return false;
00137 }
00138
00139 function readlineEmulation( $prompt ) {
00140 $bash = "bash";
00141 if( !wfIsWindows() && findExecutable( $bash ) ) {
00142 $retval = false;
00143 $encPrompt = wfEscapeShellArg( $prompt );
00144 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
00145 $encCommand = wfEscapeShellArg( $command );
00146 $line = wfShellExec( "$bash -c $encCommand", $retval );
00147
00148 if( $retval == 0 ) {
00149 return $line;
00150 } elseif( $retval == 127 ) {
00151
00152
00153
00154 } else {
00155
00156 return false;
00157 }
00158 }
00159
00160
00161 if ( feof( STDIN ) ) {
00162 return false;
00163 }
00164 print $prompt;
00165 return fgets(STDIN, 1024);
00166 }
00167
00168
00169 #
00170 # Read and execute SQL commands from a file
00171 #
00172 function dbsource( $fname, $db = false ) {
00173 wfDeprecated( __METHOD__ );
00174 if ( !$db ) {
00175
00176 global $wgDatabase;
00177 if ( isset( $wgDatabase ) ) {
00178 $db = $wgDatabase;
00179 } else {
00180
00181 $db = wfGetDB( DB_MASTER );
00182 }
00183 }
00184 $error = $db->sourceFile( $fname );
00185 if ( $error !== true ) {
00186 print $error;
00187 exit(1);
00188 }
00189 }
00190
00200 function mw_get_session_save_path() {
00201 $path = ini_get( 'session.save_path' );
00202 $path = substr( $path, strrpos( $path, ';' ) );
00203 return $path;
00204 }
00205
00214 function mw_have_dl() {
00215 return function_exists( 'dl' )
00216 && is_callable( 'dl' )
00217 && wfIniGetBool( 'enable_dl' )
00218 && !wfIniGetBool( 'safe_mode' );
00219 }