Show change flag tooltips everywhere, not just RC
[mediawiki.git] / install-utils.inc
blob0e3ebc0ef39dd5ccab4f20a51eb0cb6ced2cef87
1 <?php
3 /**
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.
6  *
7  * @file
8  */
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";
18                 die( -1 );
19         }
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";
24                 die( -1 );
25         }
26         
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";
34                 die( -1 );
35         }
37         global $wgCommandLineMode;
38         $wgCommandLineMode = true;
39         umask( 000 );
40         @set_time_limit( 0 );
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 ); }
54                 chmod( $d, $perms );
55                 # print "Copied \"{$sname}\" to \"{$d}\".\n";
56         } else {
57                 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
58                 exit();
59         }
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 );
68                 }
69         }
72 function readconsole( $prompt = '' ) {
73         static $isatty = null;
74         if ( is_null( $isatty ) ) {
75                 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
76                         $isatty = true;
77                 } else {
78                         $isatty = false;
79                 }
80         }
82         if ( $isatty && function_exists( 'readline' ) ) {
83                 return readline( $prompt );
84         } else {
85                 if ( $isatty ) {
86                         print $prompt;
87                 }
88                 if ( feof( STDIN ) ) {
89                         return false;
90                 }
91                 $st = fgets(STDIN, 1024);
92                 if ($st === false) return false;
93                 $resp = trim( $st );
94                 return $resp;
95         }
99 # Read and execute SQL commands from a file
101 function dbsource( $fname, $db = false ) {
102         wfDeprecated( __METHOD__ );
103         if ( !$db ) {
104                 // Try $wgDatabase, which is used in the install and update scripts
105                 global $wgDatabase;
106                 if ( isset( $wgDatabase ) ) {
107                         $db = $wgDatabase;
108                 } else {
109                         // No? Well, we must be outside of those scripts, so use the standard method
110                         $db = wfGetDB( DB_MASTER );
111                 }
112         }
113         $error = $db->sourceFile( $fname );
114         if ( $error !== true ) {
115                 print $error;
116                 exit(1);
117         }
121  * Get the value of session.save_path
123  * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
124  * this might have some additional preceding parts which need to be
125  * ditched
127  * @return string
128  */
129 function mw_get_session_save_path() {
130         $path = ini_get( 'session.save_path' );
131         $path = substr( $path, strrpos( $path, ';' ) );
132         return $path;
136  * Is dl() available to us?
138  * According to http://www.php.net/manual/en/function.dl.php, dl()
139  * is *not* available when `enable_dl` is off, or under `safe_mode`
141  * @return bool
142  */
143 function mw_have_dl() {
144         return function_exists( 'dl' )
145                 && is_callable( 'dl' )
146                 && wfIniGetBool( 'enable_dl' )
147                 && !wfIniGetBool( 'safe_mode' );