For HTML 5, drop type="" attributes for CSS/JS
[lhc/web/wiklou.git] / install-utils.inc
1 <?php
2
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 */
9
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 );
14
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 }
36
37 global $wgCommandLineMode;
38 $wgCommandLineMode = true;
39 umask( 000 );
40 @set_time_limit( 0 );
41 }
42
43 function readconsole( $prompt = '' ) {
44 static $isatty = null;
45 if ( is_null( $isatty ) ) {
46 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
47 $isatty = true;
48 } else {
49 $isatty = false;
50 }
51 }
52
53 if ( $isatty && function_exists( 'readline' ) ) {
54 return readline( $prompt );
55 } else {
56 if ( $isatty ) {
57 $st = readlineEmulation( $prompt );
58 } else {
59 if ( feof( STDIN ) ) {
60 $st = false;
61 } else {
62 $st = fgets(STDIN, 1024);
63 }
64 }
65 if ($st === false) return false;
66 $resp = trim( $st );
67 return $resp;
68 }
69 }
70
71 function findExecutable( $name ) {
72 $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
73 foreach( $paths as $path ) {
74 $full = $path . DIRECTORY_SEPARATOR . $name;
75 if( file_exists( $full ) ) {
76 if( wfIsWindows() || is_executable( $full ) ) {
77 return $full;
78 }
79 }
80 }
81 return false;
82 }
83
84 function readlineEmulation( $prompt ) {
85 $bash = "bash";
86 if( !wfIsWindows() && findExecutable( $bash ) ) {
87 $retval = false;
88 $encPrompt = wfEscapeShellArg( $prompt );
89 $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
90 $encCommand = wfEscapeShellArg( $command );
91 $line = wfShellExec( "$bash -c $encCommand", $retval );
92
93 if( $retval == 0 ) {
94 return $line;
95 } elseif( $retval == 127 ) {
96 // Couldn't execute bash even though we thought we saw it.
97 // Shell probably spit out an error message, sorry :(
98 // Fall through to fgets()...
99 } else {
100 // EOF/ctrl+D
101 return false;
102 }
103 }
104
105 // Fallback... we'll have no editing controls, EWWW
106 if ( feof( STDIN ) ) {
107 return false;
108 }
109 print $prompt;
110 return fgets(STDIN, 1024);
111 }
112
113
114 #
115 # Read and execute SQL commands from a file
116 #
117 function dbsource( $fname, $db = false ) {
118 wfDeprecated( __METHOD__ );
119 if ( !$db ) {
120 // Try $wgDatabase, which is used in the install and update scripts
121 global $wgDatabase;
122 if ( isset( $wgDatabase ) ) {
123 $db = $wgDatabase;
124 } else {
125 // No? Well, we must be outside of those scripts, so use the standard method
126 $db = wfGetDB( DB_MASTER );
127 }
128 }
129 $error = $db->sourceFile( $fname );
130 if ( $error !== true ) {
131 print $error;
132 exit(1);
133 }
134 }
135
136 /**
137 * Get the value of session.save_path
138 *
139 * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
140 * this might have some additional preceding parts which need to be
141 * ditched
142 *
143 * @return string
144 */
145 function mw_get_session_save_path() {
146 $path = ini_get( 'session.save_path' );
147 $path = substr( $path, strrpos( $path, ';' ) );
148 return $path;
149 }
150
151 /**
152 * Is dl() available to us?
153 *
154 * According to http://www.php.net/manual/en/function.dl.php, dl()
155 * is *not* available when `enable_dl` is off, or under `safe_mode`
156 *
157 * @return bool
158 */
159 function mw_have_dl() {
160 return function_exists( 'dl' )
161 && is_callable( 'dl' )
162 && wfIniGetBool( 'enable_dl' )
163 && !wfIniGetBool( 'safe_mode' );
164 }