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";
46 $test = new PhpRefCallBugTester;
49 echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" .
50 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
51 "downgrade to PHP 5.3.0 to fix this.\n" .
52 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
56 global $wgCommandLineMode;
57 $wgCommandLineMode = true;
63 * Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
64 * http://bugs.php.net/bug.php?id=45996
65 * Known fixed with PHP 5.2.9 + libxml2-2.7.3
67 class PhpXmlBugTester {
68 private $parsedData = '';
70 public function __construct() {
71 $charData = '<b>c</b>';
72 $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
74 $parser = xml_parser_create();
75 xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
76 $parsedOk = xml_parse($parser, $xml, true);
77 $this->ok = $parsedOk && ($this->parsedData == $charData);
79 public function chardata($parser, $data) {
80 $this->parsedData .= $data;
85 * Test for PHP bug #50394 (PHP 5.3.x conversion to null only, not 5.2.x)
87 class PhpRefCallBugTester {
90 function __call( $name, $args ) {
91 $old = error_reporting( E_ALL & ~E_WARNING );
92 call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
93 error_reporting( $old );
96 function checkForBrokenRef( &$var ) {
104 call_user_func_array( array( $this, 'foo' ), array( &$var ) );
108 function readconsole( $prompt = '' ) {
109 static $isatty = null;
110 if ( is_null( $isatty ) ) {
111 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
118 if ( $isatty && function_exists( 'readline' ) ) {
119 return readline( $prompt );
122 $st = readlineEmulation( $prompt );
124 if ( feof( STDIN ) ) {
127 $st = fgets(STDIN, 1024);
130 if ($st === false) return false;
136 function findExecutable( $name ) {
137 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
138 foreach( $paths as $path ) {
139 $full = $path . DIRECTORY_SEPARATOR . $name;
140 if( file_exists( $full ) ) {
141 if( wfIsWindows() || is_executable( $full ) ) {
149 function readlineEmulation( $prompt ) {
151 if( !wfIsWindows() && findExecutable( $bash ) ) {
153 $encPrompt = wfEscapeShellArg( $prompt );
154 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
155 $encCommand = wfEscapeShellArg( $command );
156 $line = wfShellExec( "$bash -c $encCommand", $retval );
160 } elseif( $retval == 127 ) {
161 // Couldn't execute bash even though we thought we saw it.
162 // Shell probably spit out an error message, sorry :(
163 // Fall through to fgets()...
170 // Fallback... we'll have no editing controls, EWWW
171 if ( feof( STDIN ) ) {
175 return fgets(STDIN, 1024);
180 # Read and execute SQL commands from a file
182 function dbsource( $fname, $db = false ) {
183 wfDeprecated( __METHOD__ );
185 // Try $wgDatabase, which is used in the install and update scripts
187 if ( isset( $wgDatabase ) ) {
190 // No? Well, we must be outside of those scripts, so use the standard method
191 $db = wfGetDB( DB_MASTER );
194 $error = $db->sourceFile( $fname );
195 if ( $error !== true ) {
202 * Get the value of session.save_path
204 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
205 * this might have some additional preceding parts which need to be
210 function mw_get_session_save_path() {
211 $path = ini_get( 'session.save_path' );
212 $path = substr( $path, strrpos( $path, ';' ) );
217 * Is dl() available to us?
219 * According to http://www.php.net/manual/en/function.dl.php, dl()
220 * is *not* available when `enable_dl` is off, or under `safe_mode`
224 function mw_have_dl() {
225 return function_exists( 'dl' )
226 && is_callable( 'dl' )
227 && wfIniGetBool( 'enable_dl' )
228 && !wfIniGetBool( 'safe_mode' );