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";
18 if (!extension_loaded('mysql')) {
19 if (!dl('mysql.so')) {
20 print 'Could not load MySQL driver! Please compile '.
21 "php --with-mysql or install the mysql.so module.\n";
26 global $wgCommandLineMode;
27 $wgCommandLineMode = true;
32 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
33 copyfileto( $sdir, $name, $ddir, $name, $perms );
36 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
37 global $wgInstallOwner, $wgInstallGroup;
39 $d = "{$ddir}/{$dname}";
40 if ( copy( "{$sdir}/{$sname}", $d ) ) {
41 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
42 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
44 # print "Copied \"{$sname}\" to \"{$d}\".\n";
46 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
51 function copydirectory( $source, $dest ) {
52 $handle = opendir( $source );
53 while ( false !== ( $f = readdir( $handle ) ) ) {
54 $fullname = "$source/$f";
55 if ( $f{0} != '.' && is_file( $fullname ) ) {
56 copyfile( $source, $f, $dest );
61 function readconsole( $prompt = '' ) {
62 static $isatty = null, $fp = null;
63 if ( is_null( $fp ) ) {
64 $fp = fopen( 'php://stdin', 'r' );
66 if ( is_null( $isatty ) ) {
67 if ( !function_exists( 'posix_isatty' ) || posix_isatty( $fp ) ) {
74 if ( $isatty && function_exists( 'readline' ) ) {
75 return readline( $prompt );
83 $st = fgets($fp, 1024);
84 if ($st === false) return false;
91 # Read and execute SQL commands from a file
93 function dbsource( $fname, $db = false ) {
95 // Try $wgDatabase, which is used in the install and update scripts
97 if ( isset( $wgDatabase ) ) {
100 // No? Well, we must be outside of those scripts, so use the standard method
101 $db =& wfGetDB( DB_MASTER );
104 $error = $db->sourceFile( $fname );
105 if ( $error !== true ) {
111 # Obsolete, use Database::fieldExists()
112 function field_exists( $table, $field ) {
113 $fname = 'Update script: field_exists';
114 $db =& wfGetDB( DB_SLAVE );
115 $res = $db->query( "DESCRIBE $table", $fname );
118 while ( $row = $db->fetchObject( $res ) ) {
119 if ( $row->Field == $field ) {
127 # Obsolete Database::tableExists()
128 function table_exists( $db ) {
130 $res = mysql_list_tables( $wgDBname );
132 echo "** " . mysql_error() . "\n";
135 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
136 if( mysql_tablename( $res, $i ) == $db ) return true;
141 # Obsolete, use Database:fieldInfo()
142 function field_info( $table, $field ) {
143 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
144 $n = mysql_num_fields( $res );
145 for( $i = 0; $i < $n; $i++ ) {
146 $meta = mysql_fetch_field( $res, $i );
147 if( $field == $meta->name ) {