]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - install-utils.inc
MediaWiki 1.14.0-scripts
[autoinstallsdev/mediawiki.git] / install-utils.inc
1 <?php
2
3 function install_version_checks() {
4         # We dare not turn output buffer _off_ since this will break completely
5         # if PHP is globally configured to run through a gzip filter.
6         @ob_implicit_flush( true );
7
8         if( !function_exists( 'version_compare' ) ) {
9                 # version_compare was introduced in 4.1.0
10                 echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
11                 die( -1 );
12         }
13         if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
14                 echo "PHP 5.0.0 or higher is required. If PHP 5 is available only when \n".
15    "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
16    "to continue installation. ABORTING.\n";
17                 die( -1 );
18         }
19         
20         // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
21         // As of 1.8 this breaks lots of common operations instead
22         // of just some rare ones like export.
23         $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
24         if( !isset( $borked[-1] ) ) {
25                 echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
26                         "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
27                 die( -1 );
28         }
29
30         global $wgCommandLineMode;
31         $wgCommandLineMode = true;
32         umask( 000 );
33         @set_time_limit( 0 );
34 }
35
36 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
37         copyfileto( $sdir, $name, $ddir, $name, $perms );
38 }
39
40 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
41         global $wgInstallOwner, $wgInstallGroup;
42
43         $d = "{$ddir}/{$dname}";
44         if ( copy( "{$sdir}/{$sname}", $d ) ) {
45                 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
46                 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
47                 chmod( $d, $perms );
48                 # print "Copied \"{$sname}\" to \"{$d}\".\n";
49         } else {
50                 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
51                 exit();
52         }
53 }
54
55 function copydirectory( $source, $dest ) {
56         $handle = opendir( $source );
57         while ( false !== ( $f = readdir( $handle ) ) ) {
58                 $fullname = "$source/$f";
59                 if ( $f{0} != '.' && is_file( $fullname ) ) {
60                         copyfile( $source, $f, $dest );
61                 }
62         }
63 }
64
65 function readconsole( $prompt = '' ) {
66         static $isatty = null;
67         if ( is_null( $isatty ) ) {
68                 if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
69                         $isatty = true;
70                 } else {
71                         $isatty = false;
72                 }
73         }
74
75         if ( $isatty && function_exists( 'readline' ) ) {
76                 return readline( $prompt );
77         } else {
78                 if ( $isatty ) {
79                         print $prompt;
80                 }
81                 if ( feof( STDIN ) ) {
82                         return false;
83                 }
84                 $st = fgets(STDIN, 1024);
85                 if ($st === false) return false;
86                 $resp = trim( $st );
87                 return $resp;
88         }
89 }
90
91 #
92 # Read and execute SQL commands from a file
93 #
94 function dbsource( $fname, $db = false ) {
95         if ( !$db ) {
96                 // Try $wgDatabase, which is used in the install and update scripts
97                 global $wgDatabase;
98                 if ( isset( $wgDatabase ) ) {
99                         $db = $wgDatabase;
100                 } else {
101                         // No? Well, we must be outside of those scripts, so use the standard method
102                         $db = wfGetDB( DB_MASTER );
103                 }
104         }
105         $error = $db->sourceFile( $fname );
106         if ( $error !== true ) {
107                 print $error;
108                 exit(1);
109         }
110 }
111
112 /**
113  * Get the value of session.save_path
114  *
115  * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
116  * this might have some additional preceding parts which need to be
117  * ditched
118  *
119  * @return string
120  */
121 function mw_get_session_save_path() {
122         $path = ini_get( 'session.save_path' );
123         $path = substr( $path, strrpos( $path, ';' ) );
124         return $path;
125 }
126
127 /**
128  * Is dl() available to us?
129  *
130  * According to http://www.php.net/manual/en/function.dl.php, dl()
131  * is *not* available when `enable_dl` is off, or under `safe_mode`
132  *
133  * @return bool
134  */
135 function mw_have_dl() {
136         return function_exists( 'dl' )
137                 && is_callable( 'dl' )
138                 && wfIniGetBool( 'enable_dl' )
139                 && !wfIniGetBool( 'safe_mode' );
140 }