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 );
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";
13 if( version_compare( phpversion(), '4.3.2' ) < 0 ) {
14 echo "PHP 4.3.2 or higher is required. ABORTING.\n";
19 ## XXX We should quiet the warnings thrown here
20 if (extension_loaded('mysql') or dl('mysql.so')) {
21 $gotdatabase = 'mysql';
23 else if (extension_loaded('pgsql') or dl('pgsql.so')) {
27 print "Could not load the MySQL or the PostgreSQL driver! Please compile ".
28 "php with either --with-mysql or --with-pgsql, or install the mysql.so or pg.so module.\n";
32 global $wgCommandLineMode;
33 $wgCommandLineMode = true;
38 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
39 copyfileto( $sdir, $name, $ddir, $name, $perms );
42 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
43 global $wgInstallOwner, $wgInstallGroup;
45 $d = "{$ddir}/{$dname}";
46 if ( copy( "{$sdir}/{$sname}", $d ) ) {
47 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
48 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
50 # print "Copied \"{$sname}\" to \"{$d}\".\n";
52 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
57 function copydirectory( $source, $dest ) {
58 $handle = opendir( $source );
59 while ( false !== ( $f = readdir( $handle ) ) ) {
60 $fullname = "$source/$f";
61 if ( $f{0} != '.' && is_file( $fullname ) ) {
62 copyfile( $source, $f, $dest );
67 function readconsole( $prompt = '' ) {
68 static $isatty = null, $fp = null;
69 if ( is_null( $fp ) ) {
70 $fp = fopen( 'php://stdin', 'r' );
72 if ( is_null( $isatty ) ) {
73 if ( !function_exists( 'posix_isatty' ) || posix_isatty( $fp ) ) {
80 if ( $isatty && function_exists( 'readline' ) ) {
81 return readline( $prompt );
89 $st = fgets($fp, 1024);
90 if ($st === false) return false;
97 # Read and execute SQL commands from a file
99 function dbsource( $fname, $db = false ) {
101 // Try $wgDatabase, which is used in the install and update scripts
103 if ( isset( $wgDatabase ) ) {
106 // No? Well, we must be outside of those scripts, so use the standard method
107 $db =& wfGetDB( DB_MASTER );
110 $error = $db->sourceFile( $fname );
111 if ( $error !== true ) {
117 # Obsolete, use Database::fieldExists()
118 function field_exists( $table, $field ) {
119 $fname = 'Update script: field_exists';
120 $db =& wfGetDB( DB_SLAVE );
121 $res = $db->query( "DESCRIBE $table", $fname );
124 while ( $row = $db->fetchObject( $res ) ) {
125 if ( $row->Field == $field ) {
133 # Obsolete Database::tableExists()
134 function table_exists( $db ) {
136 $res = mysql_list_tables( $wgDBname );
138 echo "** " . mysql_error() . "\n";
141 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
142 if( mysql_tablename( $res, $i ) == $db ) return true;
147 # Obsolete, use Database:fieldInfo()
148 function field_info( $table, $field ) {
149 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
150 $n = mysql_num_fields( $res );
151 for( $i = 0; $i < $n; $i++ ) {
152 $meta = mysql_fetch_field( $res, $i );
153 if( $field == $meta->name ) {