3 function install_version_checks() {
4 # We dare not turn output buffer _off_ since this will break completely
5 # if PHP is globally configured to run through a gzip filter.
6 @ob_implicit_flush( true );
8 if( !function_exists( 'version_compare' ) ) {
9 # version_compare was introduced in 4.1.0
10 echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
13 if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
14 echo "PHP 5.0.0 or higher is required. If PHP 5 is available only when \n".
15 "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
16 "to continue installation. ABORTING.\n";
20 // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
21 // As of 1.8 this breaks lots of common operations instead
22 // of just some rare ones like export.
23 $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
24 if( !isset( $borked[-1] ) ) {
25 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
26 "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
30 global $wgCommandLineMode;
31 $wgCommandLineMode = true;
36 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
37 copyfileto( $sdir, $name, $ddir, $name, $perms );
40 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
41 global $wgInstallOwner, $wgInstallGroup;
43 $d = "{$ddir}/{$dname}";
44 if ( copy( "{$sdir}/{$sname}", $d ) ) {
45 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
46 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
48 # print "Copied \"{$sname}\" to \"{$d}\".\n";
50 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
55 function copydirectory( $source, $dest ) {
56 $handle = opendir( $source );
57 while ( false !== ( $f = readdir( $handle ) ) ) {
58 $fullname = "$source/$f";
59 if ( $f{0} != '.' && is_file( $fullname ) ) {
60 copyfile( $source, $f, $dest );
65 function readconsole( $prompt = '' ) {
66 static $isatty = null;
67 if ( is_null( $isatty ) ) {
68 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
75 if ( $isatty && function_exists( 'readline' ) ) {
76 return readline( $prompt );
81 if ( feof( STDIN ) ) {
84 $st = fgets(STDIN, 1024);
85 if ($st === false) return false;
92 # Read and execute SQL commands from a file
94 function dbsource( $fname, $db = false ) {
96 // Try $wgDatabase, which is used in the install and update scripts
98 if ( isset( $wgDatabase ) ) {
101 // No? Well, we must be outside of those scripts, so use the standard method
102 $db = wfGetDB( DB_MASTER );
105 $error = $db->sourceFile( $fname );
106 if ( $error !== true ) {
113 * Get the value of session.save_path
115 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
116 * this might have some additional preceding parts which need to be
121 function mw_get_session_save_path() {
122 $path = ini_get( 'session.save_path' );
123 $path = substr( $path, strrpos( $path, ';' ) );
128 * Is dl() available to us?
130 * According to http://www.php.net/manual/en/function.dl.php, dl()
131 * is *not* available when `enable_dl` is off, or under `safe_mode`
135 function mw_have_dl() {
136 return function_exists( 'dl' )
137 && is_callable( 'dl' )
138 && wfIniGetBool( 'enable_dl' )
139 && !wfIniGetBool( 'safe_mode' );