00001 <?php 00002 00003 function install_version_checks() { 00004 # Turn off output buffering if it's on 00005 @ob_end_flush(); 00006 00007 if( !function_exists( "version_compare" ) ) { 00008 # version_compare was introduced in 4.1.0 00009 die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" ); 00010 } 00011 if( version_compare( phpversion(), "4.3.2" ) < 0 ) { 00012 echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n"; 00013 } 00014 00015 if (!extension_loaded('mysql')) { 00016 if (!dl('mysql.so')) { 00017 print "Could not load MySQL driver! Please compile ". 00018 "php --with-mysql or install the mysql.so module.\n"; 00019 exit; 00020 } 00021 } 00022 00023 global $wgCommandLineMode; 00024 $wgCommandLineMode = true; 00025 umask( 000 ); 00026 set_time_limit( 0 ); 00027 } 00028 00029 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) { 00030 copyfileto( $sdir, $name, $ddir, $name, $perms ); 00031 } 00032 00033 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) { 00034 global $wgInstallOwner, $wgInstallGroup; 00035 00036 $d = "{$ddir}/{$dname}"; 00037 if ( copy( "{$sdir}/{$sname}", $d ) ) { 00038 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); } 00039 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); } 00040 chmod( $d, $perms ); 00041 # print "Copied \"{$sname}\" to \"{$d}\".\n"; 00042 } else { 00043 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n"; 00044 exit(); 00045 } 00046 } 00047 00048 function copydirectory( $source, $dest ) { 00049 $handle = opendir( $source ); 00050 while ( false !== ( $f = readdir( $handle ) ) ) { 00051 $fullname = "$source/$f"; 00052 if ( $f{0} !="." && is_file( $fullname ) ) { 00053 copyfile( $source, $f, $dest ); 00054 } 00055 } 00056 } 00057 00058 function readconsole( $prompt = "" ) { 00059 if ( function_exists( "readline" ) ) { 00060 return readline( $prompt ); 00061 } else { 00062 print $prompt; 00063 $fp = fopen( "php://stdin", "r" ); 00064 $resp = trim( fgets( $fp, 1024 ) ); 00065 fclose( $fp ); 00066 return $resp; 00067 } 00068 } 00069 00070 function replacevars( $ins ) { 00071 $varnames = array( 00072 "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser", 00073 "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword", 00074 "wgDBadminuser", "wgDBadminpassword" 00075 ); 00076 00077 foreach ( $varnames as $var ) { 00078 global $$var; 00079 $ins = str_replace( '{$' . $var . '}', $$var, $ins ); 00080 } 00081 return $ins; 00082 } 00083 00084 # 00085 # Read and execute SQL commands from a file 00086 # 00087 function dbsource( $fname, $database = false ) { 00088 $fp = fopen( $fname, "r" ); 00089 if ( false === $fp ) { 00090 print "Could not open \"{$fname}\".\n"; 00091 exit(); 00092 } 00093 00094 $cmd = ""; 00095 $done = false; 00096 00097 while ( ! feof( $fp ) ) { 00098 $line = trim( fgets( $fp, 1024 ) ); 00099 $sl = strlen( $line ) - 1; 00100 00101 if ( $sl < 0 ) { continue; } 00102 if ( "-" == $line{0} && "-" == $line{1} ) { continue; } 00103 00104 if ( ";" == $line{$sl} ) { 00105 $done = true; 00106 $line = substr( $line, 0, $sl ); 00107 } 00108 00109 if ( "" != $cmd ) { $cmd .= " "; } 00110 $cmd .= $line; 00111 00112 if ( $done ) { 00113 $cmd = replacevars( $cmd ); 00114 if( $database ) 00115 $res = $database->query( $cmd ); 00116 else 00117 $res = mysql_query( $cmd ); 00118 00119 if ( false === $res ) { 00120 $err = mysql_error(); 00121 print "Query \"{$cmd}\" failed with error code \"$err\".\n"; 00122 exit(); 00123 } 00124 00125 $cmd = ""; 00126 $done = false; 00127 } 00128 } 00129 fclose( $fp ); 00130 } 00131 00132 # Obsolete, use Database::fieldExists() 00133 function field_exists( $table, $field ) { 00134 $fname = "Update script: field_exists"; 00135 $res = wfQuery( "DESCRIBE $table", $fname ); 00136 $found = false; 00137 00138 while ( $row = wfFetchObject( $res ) ) { 00139 if ( $row->Field == $field ) { 00140 $found = true; 00141 break; 00142 } 00143 } 00144 return $found; 00145 } 00146 00147 # Obsolete Database::tableExists() 00148 function table_exists( $db ) { 00149 global $wgDBname; 00150 $res = mysql_list_tables( $wgDBname ); 00151 if( !$res ) { 00152 echo "** " . mysql_error() . "\n"; 00153 return false; 00154 } 00155 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) { 00156 if( mysql_tablename( $res, $i ) == $db ) return true; 00157 } 00158 return false; 00159 } 00160 00161 # Obsolete, use Database:fieldInfo() 00162 function field_info( $table, $field ) { 00163 $res = mysql_query( "SELECT * FROM $table LIMIT 1" ); 00164 $n = mysql_num_fields( $res ); 00165 for( $i = 0; $i < $n; $i++ ) { 00166 $meta = mysql_fetch_field( $res, $i ); 00167 if( $field == $meta->name ) { 00168 return $meta; 00169 } 00170 } 00171 return false; 00172 } 00173 00174 ?>