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 global $wgCommandLineMode;
00038 $wgCommandLineMode = true;
00039 umask( 000 );
00040 @set_time_limit( 0 );
00041 }
00042
00043 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
00044 copyfileto( $sdir, $name, $ddir, $name, $perms );
00045 }
00046
00047 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
00048 global $wgInstallOwner, $wgInstallGroup;
00049
00050 $d = "{$ddir}/{$dname}";
00051 if ( copy( "{$sdir}/{$sname}", $d ) ) {
00052 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
00053 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
00054 chmod( $d, $perms );
00055 # print "Copied \"{$sname}\" to \"{$d}\".\n";
00056 } else {
00057 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
00058 exit();
00059 }
00060 }
00061
00062 function copydirectory( $source, $dest ) {
00063 $handle = opendir( $source );
00064 while ( false !== ( $f = readdir( $handle ) ) ) {
00065 $fullname = "$source/$f";
00066 if ( $f{0} != '.' && is_file( $fullname ) ) {
00067 copyfile( $source, $f, $dest );
00068 }
00069 }
00070 }
00071
00072 function readconsole( $prompt = '' ) {
00073 static $isatty = null;
00074 if ( is_null( $isatty ) ) {
00075 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 ) ) {
00076 $isatty = true;
00077 } else {
00078 $isatty = false;
00079 }
00080 }
00081
00082 if ( $isatty && function_exists( 'readline' ) ) {
00083 return readline( $prompt );
00084 } else {
00085 if ( $isatty ) {
00086 print $prompt;
00087 }
00088 if ( feof( STDIN ) ) {
00089 return false;
00090 }
00091 $st = fgets(STDIN, 1024);
00092 if ($st === false) return false;
00093 $resp = trim( $st );
00094 return $resp;
00095 }
00096 }
00097
00098 #
00099 # Read and execute SQL commands from a file
00100 #
00101 function dbsource( $fname, $db = false ) {
00102 if ( !$db ) {
00103
00104 global $wgDatabase;
00105 if ( isset( $wgDatabase ) ) {
00106 $db = $wgDatabase;
00107 } else {
00108
00109 $db = wfGetDB( DB_MASTER );
00110 }
00111 }
00112 $error = $db->sourceFile( $fname );
00113 if ( $error !== true ) {
00114 print $error;
00115 exit(1);
00116 }
00117 }
00118
00128 function mw_get_session_save_path() {
00129 $path = ini_get( 'session.save_path' );
00130 $path = substr( $path, strrpos( $path, ';' ) );
00131 return $path;
00132 }
00133
00142 function mw_have_dl() {
00143 return function_exists( 'dl' )
00144 && is_callable( 'dl' )
00145 && wfIniGetBool( 'enable_dl' )
00146 && !wfIniGetBool( 'safe_mode' );
00147 }