Some minor changes to the installer after I reinstalled MW from scracth:
[lhc/web/wiklou.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. 4.3.2 or higher is required. ABORTING.\n";
11 die( -1 );
12 }
13 if( version_compare( phpversion(), '4.3.2' ) < 0 ) {
14 echo "PHP 4.3.2 or higher is required. ABORTING.\n";
15 die( -1 );
16 }
17
18 $gotdatabase = 0;
19 ## XXX We should quiet the warnings thrown here
20 if (extension_loaded('mysql') or @dl('mysql.so')) {
21 $gotdatabase = 'mysql';
22 }
23 else if (extension_loaded('pgsql') or @dl('pgsql.so')) {
24 $gotdatabase = 'pg';
25 }
26 if (!$gotdatabase) {
27 global $wgCommandLineMode;
28
29 $error ="Could not load the MySQL or the PostgreSQL driver! Please compile ".
30 "php with either --with-mysql or --with-pgsql, or install the mysql.so or pg.so module.<br/>\n".
31 " If the database extension is installed (eg php-mysql), make sure it is enabled in your php.ini.\n";
32 if( $wgCommandLineMode ) { print $error; }
33 else { outputFooter($error); }
34 exit;
35 }
36
37 global $wgCommandLineMode;
38 $wgCommandLineMode = true;
39 umask( 000 );
40 set_time_limit( 0 );
41 }
42
43 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
44 copyfileto( $sdir, $name, $ddir, $name, $perms );
45 }
46
47 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
48 global $wgInstallOwner, $wgInstallGroup;
49
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 }
60 }
61
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 }
70 }
71
72 function readconsole( $prompt = '' ) {
73 static $isatty = null, $fp = null;
74 if ( is_null( $fp ) ) {
75 $fp = fopen( 'php://stdin', 'r' );
76 }
77 if ( is_null( $isatty ) ) {
78 if ( !function_exists( 'posix_isatty' ) || posix_isatty( $fp ) ) {
79 $isatty = true;
80 } else {
81 $isatty = false;
82 }
83 }
84
85 if ( $isatty && function_exists( 'readline' ) ) {
86 return readline( $prompt );
87 } else {
88 if ( $isatty ) {
89 print $prompt;
90 }
91 if ( feof( $fp ) ) {
92 return false;
93 }
94 $st = fgets($fp, 1024);
95 if ($st === false) return false;
96 $resp = trim( $st );
97 return $resp;
98 }
99 }
100
101 #
102 # Read and execute SQL commands from a file
103 #
104 function dbsource( $fname, $db = false ) {
105 if ( !$db ) {
106 // Try $wgDatabase, which is used in the install and update scripts
107 global $wgDatabase;
108 if ( isset( $wgDatabase ) ) {
109 $db =& $wgDatabase;
110 } else {
111 // No? Well, we must be outside of those scripts, so use the standard method
112 $db =& wfGetDB( DB_MASTER );
113 }
114 }
115 $error = $db->sourceFile( $fname );
116 if ( $error !== true ) {
117 print $error;
118 exit(1);
119 }
120 }
121
122 # Obsolete, use Database::fieldExists()
123 function field_exists( $table, $field ) {
124 $fname = 'Update script: field_exists';
125 $db =& wfGetDB( DB_SLAVE );
126 $res = $db->query( "DESCRIBE $table", $fname );
127 $found = false;
128
129 while ( $row = $db->fetchObject( $res ) ) {
130 if ( $row->Field == $field ) {
131 $found = true;
132 break;
133 }
134 }
135 return $found;
136 }
137
138 # Obsolete Database::tableExists()
139 function table_exists( $db ) {
140 global $wgDBname;
141 $res = mysql_list_tables( $wgDBname );
142 if( !$res ) {
143 echo "** " . mysql_error() . "\n";
144 return false;
145 }
146 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
147 if( mysql_tablename( $res, $i ) == $db ) return true;
148 }
149 return false;
150 }
151
152 # Obsolete, use Database:fieldInfo()
153 function field_info( $table, $field ) {
154 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
155 $n = mysql_num_fields( $res );
156 for( $i = 0; $i < $n; $i++ ) {
157 $meta = mysql_fetch_field( $res, $i );
158 if( $field == $meta->name ) {
159 return $meta;
160 }
161 }
162 return false;
163 }
164
165 /**
166 * Used to end the HTML stream when we die out
167 */
168 function outputFooter( $text ) {
169 print $text;
170 print <<<END
171 </div></div></div>
172
173
174 <div id="column-one">
175 <div class="portlet" id="p-logo">
176 <a style="background-image: url(../skins/common/images/mediawiki.png);"
177 href="http://www.mediawiki.org/"
178 title="Main Page"></a>
179 </div>
180 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
181 <div class='portlet'><div class='pBody'>
182 <ul>
183 <li><strong><a href="http://www.mediawiki.org/">MediaWiki home</a></strong></li>
184 <li><a href="../README">Readme</a></li>
185 <li><a href="../RELEASE-NOTES">Release notes</a></li>
186 <li><a href="../docs/">Documentation</a></li>
187 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
188 <li><a href="http://meta.wikimedia.org/wiki/MediaWiki_FAQ">FAQ</a></li>
189 </ul>
190 <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright &copy; 2001-2006 by Magnus Manske, Brion Vibber, Lee Daniel Crocker, Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
191 </div></div>
192 </div>
193
194 </div>
195
196 </body>
197 </html>
198
199 END;
200
201 }
202 ?>