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;
48 call_user_func_array( array( $test, 'test' ), array( &$ok ) );
50 echo "PHP 5.2.11, 5.2.12, and 5.3.1 (your version: " . phpversion() . ") are not compatible with\n" .
51 "MediaWiki due to a bug involving reference parameters to __call. Upgrade to\n" .
52 "PHP 5.3.2 (5.2.13 for 5.2 users), or downgrade to PHP 5.3.0 (5.2.10 for 5.2\n" .
53 "users) to fix this. ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
58 global $wgCommandLineMode;
59 $wgCommandLineMode = true;
65 * Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
66 * http://bugs.php.net/bug.php?id=45996
67 * Known fixed with PHP 5.2.9 + libxml2-2.7.3
69 class PhpXmlBugTester {
70 private $parsedData = '';
72 public function __construct() {
73 $charData = '<b>c</b>';
74 $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
76 $parser = xml_parser_create();
77 xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
78 $parsedOk = xml_parse($parser, $xml, true);
79 $this->ok = $parsedOk && ($this->parsedData == $charData);
81 public function chardata($parser, $data) {
82 $this->parsedData .= $data;
87 * Test for PHP bug #50394
89 class PhpRefCallBugTester {
90 function __call( $name, $args ) {
95 function readconsole( $prompt = '' ) {
96 static $isatty = null;
97 if ( is_null( $isatty ) ) {
98 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
105 if ( $isatty && function_exists( 'readline' ) ) {
106 return readline( $prompt );
109 $st = readlineEmulation( $prompt );
111 if ( feof( STDIN ) ) {
114 $st = fgets(STDIN, 1024);
117 if ($st === false) return false;
123 function findExecutable( $name ) {
124 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
125 foreach( $paths as $path ) {
126 $full = $path . DIRECTORY_SEPARATOR . $name;
127 if( file_exists( $full ) ) {
128 if( wfIsWindows() || is_executable( $full ) ) {
136 function readlineEmulation( $prompt ) {
138 if( !wfIsWindows() && findExecutable( $bash ) ) {
140 $encPrompt = wfEscapeShellArg( $prompt );
141 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
142 $encCommand = wfEscapeShellArg( $command );
143 $line = wfShellExec( "$bash -c $encCommand", $retval );
147 } elseif( $retval == 127 ) {
148 // Couldn't execute bash even though we thought we saw it.
149 // Shell probably spit out an error message, sorry :(
150 // Fall through to fgets()...
157 // Fallback... we'll have no editing controls, EWWW
158 if ( feof( STDIN ) ) {
162 return fgets(STDIN, 1024);
167 # Read and execute SQL commands from a file
169 function dbsource( $fname, $db = false ) {
170 wfDeprecated( __METHOD__ );
172 // Try $wgDatabase, which is used in the install and update scripts
174 if ( isset( $wgDatabase ) ) {
177 // No? Well, we must be outside of those scripts, so use the standard method
178 $db = wfGetDB( DB_MASTER );
181 $error = $db->sourceFile( $fname );
182 if ( $error !== true ) {
189 * Get the value of session.save_path
191 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
192 * this might have some additional preceding parts which need to be
197 function mw_get_session_save_path() {
198 $path = ini_get( 'session.save_path' );
199 $path = substr( $path, strrpos( $path, ';' ) );
204 * Is dl() available to us?
206 * According to http://www.php.net/manual/en/function.dl.php, dl()
207 * is *not* available when `enable_dl` is off, or under `safe_mode`
211 function mw_have_dl() {
212 return function_exists( 'dl' )
213 && is_callable( 'dl' )
214 && wfIniGetBool( 'enable_dl' )
215 && !wfIniGetBool( 'safe_mode' );