4 * This file contains functions used by the install script (config/index.php)
5 * and maintenance scripts. It is not loaded in normal web requests.
10 function install_version_checks() {
11 # We dare not turn output buffer _off_ since this will break completely
12 # if PHP is globally configured to run through a gzip filter.
13 @ob_implicit_flush( true );
15 if( !function_exists( 'version_compare' ) ) {
16 # version_compare was introduced in 4.1.0
17 echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
20 if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
21 echo "PHP 5.0.0 or higher is required. If PHP 5 is available only when \n".
22 "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
23 "to continue installation. ABORTING.\n";
27 // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
28 // As of 1.8 this breaks lots of common operations instead
29 // of just some rare ones like export.
30 $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
31 if( !isset( $borked[-1] ) ) {
32 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
33 "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
37 global $wgCommandLineMode;
38 $wgCommandLineMode = true;
43 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
44 copyfileto( $sdir, $name, $ddir, $name, $perms );
47 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
48 global $wgInstallOwner, $wgInstallGroup;
50 $d = "{$ddir}/{$dname}";
51 if ( copy( "{$sdir}/{$sname}", $d ) ) {
52 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
53 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
55 # print "Copied \"{$sname}\" to \"{$d}\".\n";
57 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
62 function copydirectory( $source, $dest ) {
63 $handle = opendir( $source );
64 while ( false !== ( $f = readdir( $handle ) ) ) {
65 $fullname = "$source/$f";
66 if ( $f{0} != '.' && is_file( $fullname ) ) {
67 copyfile( $source, $f, $dest );
72 function readconsole( $prompt = '' ) {
73 static $isatty = null;
74 if ( is_null( $isatty ) ) {
75 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
82 if ( $isatty && function_exists( 'readline' ) ) {
83 return readline( $prompt );
88 if ( feof( STDIN ) ) {
91 $st = fgets(STDIN, 1024);
92 if ($st === false) return false;
99 # Read and execute SQL commands from a file
101 function dbsource( $fname, $db = false ) {
103 // Try $wgDatabase, which is used in the install and update scripts
105 if ( isset( $wgDatabase ) ) {
108 // No? Well, we must be outside of those scripts, so use the standard method
109 $db = wfGetDB( DB_MASTER );
112 $error = $db->sourceFile( $fname );
113 if ( $error !== true ) {
120 * Get the value of session.save_path
122 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
123 * this might have some additional preceding parts which need to be
128 function mw_get_session_save_path() {
129 $path = ini_get( 'session.save_path' );
130 $path = substr( $path, strrpos( $path, ';' ) );
135 * Is dl() available to us?
137 * According to http://www.php.net/manual/en/function.dl.php, dl()
138 * is *not* available when `enable_dl` is off, or under `safe_mode`
142 function mw_have_dl() {
143 return function_exists( 'dl' )
144 && is_callable( 'dl' )
145 && wfIniGetBool( 'enable_dl' )
146 && !wfIniGetBool( 'safe_mode' );