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.0.0 or higher is required. ABORTING.\n";
00018 die( -1 );
00019 }
00020 if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
00021 echo "PHP 5.0.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
00028
00029
00030 $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
00031 if( !isset( $borked[-1] ) ) {
00032 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
00033 "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
00034 die( -1 );
00035 }
00036
00037 $test = new PhpXmlBugTester();
00038 if( !$test->ok ) {
00039 echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
00040 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
00041 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
00042 "ABORTING (http://bugs.php.net/bug.php?id=45996 for details).\n";
00043 die( -1 );
00044 }
00045
00046
00047 $test = new PhpRefCallBugTester;
00048 $test->execute();
00049 if ( !$test->ok ) {
00050 echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" .
00051 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
00052 "downgrade to PHP 5.3.0 to fix this.\n" .
00053 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
00054 die( -1 );
00055 }
00056
00057 global $wgCommandLineMode;
00058 $wgCommandLineMode = true;
00059 umask( 000 );
00060 @set_time_limit( 0 );
00061 }
00062
00063 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
00064 copyfileto( $sdir, $name, $ddir, $name, $perms );
00065 }
00066
00067 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
00068 global $wgInstallOwner, $wgInstallGroup;
00069
00070 $d = "{$ddir}/{$dname}";
00071 if ( copy( "{$sdir}/{$sname}", $d ) ) {
00072 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
00073 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
00074 chmod( $d, $perms );
00075 # print "Copied \"{$sname}\" to \"{$d}\".\n";
00076 } else {
00077 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
00078 exit();
00079 }
00080 }
00081
00082 function copydirectory( $source, $dest ) {
00083 $handle = opendir( $source );
00084 while ( false !== ( $f = readdir( $handle ) ) ) {
00085 $fullname = "$source/$f";
00086 if ( $f{0} != '.' && is_file( $fullname ) ) {
00087 copyfile( $source, $f, $dest );
00088 }
00089 }
00090 }
00091
00097 class PhpXmlBugTester {
00098 var $parsedData = '';
00099 var $ok = false;
00100 function __construct() {
00101 $charData = '<b>c</b>';
00102 $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
00103
00104 $parser = xml_parser_create();
00105 xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
00106 $parsedOk = xml_parse($parser, $xml, true);
00107 $this->ok = $parsedOk && ($this->parsedData == $charData);
00108 }
00109 function chardata($parser, $data) {
00110 $this->parsedData .= $data;
00111 }
00112 }
00113
00117 class PhpRefCallBugTester {
00118 public $ok = false;
00119
00120 function __call( $name, $args ) {
00121 $old = error_reporting( E_ALL & ~E_WARNING );
00122 call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
00123 error_reporting( $old );
00124 }
00125
00126 function checkForBrokenRef( &$var ) {
00127 if ( $var ) {
00128 $this->ok = true;
00129 }
00130 }
00131
00132 function execute() {
00133 $var = true;
00134 call_user_func_array( array( $this, 'foo' ), array( &$var ) );
00135 }
00136 }
00137
00138 function readconsole( $prompt = '' ) {
00139 static $isatty = null;
00140 if ( is_null( $isatty ) ) {
00141 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 ) ) {
00142 $isatty = true;
00143 } else {
00144 $isatty = false;
00145 }
00146 }
00147
00148 if ( $isatty && function_exists( 'readline' ) ) {
00149 return readline( $prompt );
00150 } else {
00151 if ( $isatty ) {
00152 print $prompt;
00153 }
00154 if ( feof( STDIN ) ) {
00155 return false;
00156 }
00157 $st = fgets(STDIN, 1024);
00158 if ($st === false) return false;
00159 $resp = trim( $st );
00160 return $resp;
00161 }
00162 }
00163
00164 #
00165 # Read and execute SQL commands from a file
00166 #
00167 function dbsource( $fname, $db = false ) {
00168 if ( !$db ) {
00169
00170 global $wgDatabase;
00171 if ( isset( $wgDatabase ) ) {
00172 $db = $wgDatabase;
00173 } else {
00174
00175 $db = wfGetDB( DB_MASTER );
00176 }
00177 }
00178 $error = $db->sourceFile( $fname );
00179 if ( $error !== true ) {
00180 print $error;
00181 exit(1);
00182 }
00183 }
00184
00194 function mw_get_session_save_path() {
00195 $path = ini_get( 'session.save_path' );
00196 $path = substr( $path, strrpos( $path, ';' ) );
00197 return $path;
00198 }
00199
00208 function mw_have_dl() {
00209 return function_exists( 'dl' )
00210 && is_callable( 'dl' )
00211 && wfIniGetBool( 'enable_dl' )
00212 && !wfIniGetBool( 'safe_mode' );
00213 }