Fixed bug caused in r52944 - where the inclusion of csshover.htc was lost in the...
[mediawiki.git] / install-utils.inc
blobab8e15dc8dfc67cdf62725532821e254594c5cb9
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         if ( !$db ) {
103                 // Try $wgDatabase, which is used in the install and update scripts
104                 global $wgDatabase;
105                 if ( isset( $wgDatabase ) ) {
106                         $db = $wgDatabase;
107                 } else {
108                         // No? Well, we must be outside of those scripts, so use the standard method
109                         $db = wfGetDB( DB_MASTER );
110                 }
111         }
112         $error = $db->sourceFile( $fname );
113         if ( $error !== true ) {
114                 print $error;
115                 exit(1);
116         }
120  * Get the value of session.save_path
122  * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
123  * this might have some additional preceding parts which need to be
124  * ditched
126  * @return string
127  */
128 function mw_get_session_save_path() {
129         $path = ini_get( 'session.save_path' );
130         $path = substr( $path, strrpos( $path, ';' ) );
131         return $path;
135  * Is dl() available to us?
137  * According to http://www.php.net/manual/en/function.dl.php, dl()
138  * is *not* available when `enable_dl` is off, or under `safe_mode`
140  * @return bool
141  */
142 function mw_have_dl() {
143         return function_exists( 'dl' )
144                 && is_callable( 'dl' )
145                 && wfIniGetBool( 'enable_dl' )
146                 && !wfIniGetBool( 'safe_mode' );