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 $test = new PhpXmlBugTester();
39 echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
40 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
41 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
42 "ABORTING (http://bugs.php.net/bug.php?id=45996 for details).\n";
47 $test = new PhpRefCallBugTester;
50 echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" .
51 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
52 "downgrade to PHP 5.3.0 to fix this.\n" .
53 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
57 global $wgCommandLineMode;
58 $wgCommandLineMode = true;
63 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
64 copyfileto( $sdir, $name, $ddir, $name, $perms );
67 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
68 global $wgInstallOwner, $wgInstallGroup;
70 $d = "{$ddir}/{$dname}";
71 if ( copy( "{$sdir}/{$sname}", $d ) ) {
72 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
73 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
75 # print "Copied \"{$sname}\" to \"{$d}\".\n";
77 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
82 function copydirectory( $source, $dest ) {
83 $handle = opendir( $source );
84 while ( false !== ( $f = readdir( $handle ) ) ) {
85 $fullname = "$source/$f";
86 if ( $f{0} != '.' && is_file( $fullname ) ) {
87 copyfile( $source, $f, $dest );
93 * Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
94 * http://bugs.php.net/bug.php?id=45996
95 * Known fixed with PHP 5.2.9 + libxml2-2.7.3
97 class PhpXmlBugTester {
100 function __construct() {
101 $charData = '<b>c</b>';
102 $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
104 $parser = xml_parser_create();
105 xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
106 $parsedOk = xml_parse($parser, $xml, true);
107 $this->ok = $parsedOk && ($this->parsedData == $charData);
109 function chardata($parser, $data) {
110 $this->parsedData .= $data;
115 * Test for PHP bug #50394 (PHP 5.3.x conversion to null only, not 5.2.x)
117 class PhpRefCallBugTester {
120 function __call( $name, $args ) {
121 $old = error_reporting( E_ALL & ~E_WARNING );
122 call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
123 error_reporting( $old );
126 function checkForBrokenRef( &$var ) {
134 call_user_func_array( array( $this, 'foo' ), array( &$var ) );
138 function readconsole( $prompt = '' ) {
139 static $isatty = null;
140 if ( is_null( $isatty ) ) {
141 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
148 if ( $isatty && function_exists( 'readline' ) ) {
149 return readline( $prompt );
154 if ( feof( STDIN ) ) {
157 $st = fgets(STDIN, 1024);
158 if ($st === false) return false;
165 # Read and execute SQL commands from a file
167 function dbsource( $fname, $db = false ) {
169 // Try $wgDatabase, which is used in the install and update scripts
171 if ( isset( $wgDatabase ) ) {
174 // No? Well, we must be outside of those scripts, so use the standard method
175 $db = wfGetDB( DB_MASTER );
178 $error = $db->sourceFile( $fname );
179 if ( $error !== true ) {
186 * Get the value of session.save_path
188 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
189 * this might have some additional preceding parts which need to be
194 function mw_get_session_save_path() {
195 $path = ini_get( 'session.save_path' );
196 $path = substr( $path, strrpos( $path, ';' ) );
201 * Is dl() available to us?
203 * According to http://www.php.net/manual/en/function.dl.php, dl()
204 * is *not* available when `enable_dl` is off, or under `safe_mode`
208 function mw_have_dl() {
209 return function_exists( 'dl' )
210 && is_callable( 'dl' )
211 && wfIniGetBool( 'enable_dl' )
212 && !wfIniGetBool( 'safe_mode' );