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.1.0 or higher is required. ABORTING.\n";
20 if( version_compare( phpversion(), '5.1.0' ) < 0 ) {
21 echo "PHP 5.1.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 = new PhpXmlBugTester();
29 echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
30 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
31 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
32 "ABORTING (http://bugs.php.net/bug.php?id=45996 for details).\n";
36 $test = new PhpRefCallBugTester;
39 echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" .
40 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
41 "downgrade to PHP 5.3.0 to fix this.\n" .
42 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
46 global $wgCommandLineMode;
47 $wgCommandLineMode = true;
53 * Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
54 * http://bugs.php.net/bug.php?id=45996
55 * Known fixed with PHP 5.2.9 + libxml2-2.7.3
57 class PhpXmlBugTester {
58 private $parsedData = '';
60 public function __construct() {
61 $charData = '<b>c</b>';
62 $xml = '<a>' . htmlspecialchars( $charData ) . '</a>';
64 $parser = xml_parser_create();
65 xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
66 $parsedOk = xml_parse($parser, $xml, true);
67 $this->ok = $parsedOk && ($this->parsedData == $charData);
69 public function chardata($parser, $data) {
70 $this->parsedData .= $data;
75 * Test for PHP bug #50394 (PHP 5.3.x conversion to null only, not 5.2.x)
77 class PhpRefCallBugTester {
80 function __call( $name, $args ) {
81 $old = error_reporting( E_ALL & ~E_WARNING );
82 call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
83 error_reporting( $old );
86 function checkForBrokenRef( &$var ) {
94 call_user_func_array( array( $this, 'foo' ), array( &$var ) );
98 function readconsole( $prompt = '' ) {
99 static $isatty = null;
100 if ( is_null( $isatty ) ) {
101 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
108 if ( $isatty && function_exists( 'readline' ) ) {
109 return readline( $prompt );
112 $st = readlineEmulation( $prompt );
114 if ( feof( STDIN ) ) {
117 $st = fgets(STDIN, 1024);
120 if ($st === false) return false;
126 function findExecutable( $name ) {
127 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
128 foreach( $paths as $path ) {
129 $full = $path . DIRECTORY_SEPARATOR . $name;
130 if( file_exists( $full ) ) {
131 if( wfIsWindows() || is_executable( $full ) ) {
139 function readlineEmulation( $prompt ) {
141 if( !wfIsWindows() && findExecutable( $bash ) ) {
143 $encPrompt = wfEscapeShellArg( $prompt );
144 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
145 $encCommand = wfEscapeShellArg( $command );
146 $line = wfShellExec( "$bash -c $encCommand", $retval );
150 } elseif( $retval == 127 ) {
151 // Couldn't execute bash even though we thought we saw it.
152 // Shell probably spit out an error message, sorry :(
153 // Fall through to fgets()...
160 // Fallback... we'll have no editing controls, EWWW
161 if ( feof( STDIN ) ) {
165 return fgets(STDIN, 1024);
170 # Read and execute SQL commands from a file
172 function dbsource( $fname, $db = false ) {
173 wfDeprecated( __METHOD__ );
175 // Try $wgDatabase, which is used in the install and update scripts
177 if ( isset( $wgDatabase ) ) {
180 // No? Well, we must be outside of those scripts, so use the standard method
181 $db = wfGetDB( DB_MASTER );
184 $error = $db->sourceFile( $fname );
185 if ( $error !== true ) {
192 * Get the value of session.save_path
194 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
195 * this might have some additional preceding parts which need to be
200 function mw_get_session_save_path() {
201 $path = ini_get( 'session.save_path' );
202 $path = substr( $path, strrpos( $path, ';' ) );
207 * Is dl() available to us?
209 * According to http://www.php.net/manual/en/function.dl.php, dl()
210 * is *not* available when `enable_dl` is off, or under `safe_mode`
214 function mw_have_dl() {
215 return function_exists( 'dl' )
216 && is_callable( 'dl' )
217 && wfIniGetBool( 'enable_dl' )
218 && !wfIniGetBool( 'safe_mode' );