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. ABORTING.\n";
18 // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
19 // As of 1.8 this breaks lots of common operations instead
20 // of just some rare ones like export.
21 $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
22 if( !isset( $borked[-1] ) ) {
23 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
24 "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
28 global $wgCommandLineMode;
29 $wgCommandLineMode = true;
34 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
35 copyfileto( $sdir, $name, $ddir, $name, $perms );
38 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
39 global $wgInstallOwner, $wgInstallGroup;
41 $d = "{$ddir}/{$dname}";
42 if ( copy( "{$sdir}/{$sname}", $d ) ) {
43 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
44 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
46 # print "Copied \"{$sname}\" to \"{$d}\".\n";
48 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
53 function copydirectory( $source, $dest ) {
54 $handle = opendir( $source );
55 while ( false !== ( $f = readdir( $handle ) ) ) {
56 $fullname = "$source/$f";
57 if ( $f{0} != '.' && is_file( $fullname ) ) {
58 copyfile( $source, $f, $dest );
63 function readconsole( $prompt = '' ) {
64 static $isatty = null;
65 if ( is_null( $isatty ) ) {
66 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
73 if ( $isatty && function_exists( 'readline' ) ) {
74 return readline( $prompt );
79 if ( feof( STDIN ) ) {
82 $st = fgets(STDIN, 1024);
83 if ($st === false) return false;
90 # Read and execute SQL commands from a file
92 function dbsource( $fname, $db = false ) {
94 // Try $wgDatabase, which is used in the install and update scripts
96 if ( isset( $wgDatabase ) ) {
99 // No? Well, we must be outside of those scripts, so use the standard method
100 $db = wfGetDB( DB_MASTER );
103 $error = $db->sourceFile( $fname );
104 if ( $error !== true ) {
111 * Get the value of session.save_path
113 * Per http://uk.php.net/manual/en/ref.session.php#ini.session.save-path,
114 * this might have some additional preceding parts which need to be
119 function mw_get_session_save_path() {
120 $path = ini_get( 'session.save_path' );
121 $path = substr( $path, strrpos( $path, ';' ) );