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 global $wgCommandLineMode;
38 $wgCommandLineMode = true;
43 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
44 copyfileto( $sdir, $name, $ddir, $name, $perms );
47 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
48 global $wgInstallOwner, $wgInstallGroup;
50 $d = "{$ddir}/{$dname}";
51 if ( copy( "{$sdir}/{$sname}", $d ) ) {
52 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
53 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
55 # print "Copied \"{$sname}\" to \"{$d}\".\n";
57 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
62 function copydirectory( $source, $dest ) {
63 $handle = opendir( $source );
64 while ( false !== ( $f = readdir( $handle ) ) ) {
65 $fullname = "$source/$f";
66 if ( $f{0} != '.' && is_file( $fullname ) ) {
67 copyfile( $source, $f, $dest );
72 function readconsole( $prompt = '' ) {
73 static $isatty = null;
74 if ( is_null( $isatty ) ) {
75 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
82 if ( $isatty && function_exists( 'readline' ) ) {
83 return readline( $prompt );
86 $st = readlineEmulation( $prompt );
88 if ( feof( STDIN ) ) {
91 $st = fgets(STDIN, 1024);
94 if ($st === false) return false;
100 function findExecutable( $name ) {
101 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
102 foreach( $paths as $path ) {
103 $full = $path . DIRECTORY_SEPARATOR . $name;
104 if( file_exists( $full ) ) {
105 if( wfIsWindows() || is_executable( $full ) ) {
113 function readlineEmulation( $prompt ) {
115 if( !wfIsWindows() && findExecutable( $bash ) ) {
117 $encPrompt = wfEscapeShellArg( $prompt );
118 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
119 $encCommand = wfEscapeShellArg( $command );
120 $line = wfShellExec( "$bash -c $encCommand", $retval );
124 } elseif( $retval == 127 ) {
125 // Couldn't execute bash even though we thought we saw it.
126 // Shell probably spit out an error message, sorry :(
127 // Fall through to fgets()...
134 // Fallback... we'll have no editing controls, EWWW
135 if ( feof( STDIN ) ) {
139 return fgets(STDIN, 1024);
144 # Read and execute SQL commands from a file
146 function dbsource( $fname, $db = false ) {
147 wfDeprecated( __METHOD__ );
149 // Try $wgDatabase, which is used in the install and update scripts
151 if ( isset( $wgDatabase ) ) {
154 // No? Well, we must be outside of those scripts, so use the standard method
155 $db = wfGetDB( DB_MASTER );
158 $error = $db->sourceFile( $fname );
159 if ( $error !== true ) {
166 * Get the value of session.save_path
168 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
169 * this might have some additional preceding parts which need to be
174 function mw_get_session_save_path() {
175 $path = ini_get( 'session.save_path' );
176 $path = substr( $path, strrpos( $path, ';' ) );
181 * Is dl() available to us?
183 * According to http://www.php.net/manual/en/function.dl.php, dl()
184 * is *not* available when `enable_dl` is off, or under `safe_mode`
188 function mw_have_dl() {
189 return function_exists( 'dl' )
190 && is_callable( 'dl' )
191 && wfIniGetBool( 'enable_dl' )
192 && !wfIniGetBool( 'safe_mode' );