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 if ( !function_exists( 'posix_isatty' ) ) {
99 # We default as considering stdin a tty (for nice readline methods)
100 # but treating stout as not a tty to avoid color codes
101 function posix_isatty( $fd ) {
106 function readconsole( $prompt = '' ) {
107 static $isatty = null;
108 if ( is_null( $isatty ) ) {
109 if ( posix_isatty( 0 /*STDIN*/ ) ) {
116 if ( $isatty && function_exists( 'readline' ) ) {
117 return readline( $prompt );
120 $st = readlineEmulation( $prompt );
122 if ( feof( STDIN ) ) {
125 $st = fgets( STDIN, 1024 );
128 if ( $st === false ) return false;
134 function findExecutable( $name ) {
135 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
136 foreach ( $paths as $path ) {
137 $full = $path . DIRECTORY_SEPARATOR . $name;
138 if ( file_exists( $full ) ) {
139 if ( wfIsWindows() || is_executable( $full ) ) {
147 function readlineEmulation( $prompt ) {
149 if ( !wfIsWindows() && findExecutable( $bash ) ) {
151 $encPrompt = wfEscapeShellArg( $prompt );
152 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
153 $encCommand = wfEscapeShellArg( $command );
154 $line = wfShellExec( "$bash -c $encCommand", $retval );
156 if ( $retval == 0 ) {
158 } elseif ( $retval == 127 ) {
159 // Couldn't execute bash even though we thought we saw it.
160 // Shell probably spit out an error message, sorry :(
161 // Fall through to fgets()...
168 // Fallback... we'll have no editing controls, EWWW
169 if ( feof( STDIN ) ) {
173 return fgets( STDIN, 1024 );
178 # Read and execute SQL commands from a file
180 function dbsource( $fname, $db = false ) {
181 wfDeprecated( __METHOD__ );
183 // Try $wgDatabase, which is used in the install and update scripts
185 if ( isset( $wgDatabase ) ) {
188 // No? Well, we must be outside of those scripts, so use the standard method
189 $db = wfGetDB( DB_MASTER );
192 $error = $db->sourceFile( $fname );
193 if ( $error !== true ) {
200 * Get the value of session.save_path
202 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
203 * this might have some additional preceding parts which need to be
208 function mw_get_session_save_path() {
209 $path = ini_get( 'session.save_path' );
210 $path = substr( $path, strrpos( $path, ';' ) );
215 * Is dl() available to us?
217 * According to http://www.php.net/manual/en/function.dl.php, dl()
218 * is *not* available when `enable_dl` is off, or under `safe_mode`
222 function mw_have_dl() {
223 return function_exists( 'dl' )
224 && is_callable( 'dl' )
225 && wfIniGetBool( 'enable_dl' )
226 && !wfIniGetBool( 'safe_mode' );