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. 5.0.0 or higher is required. ABORTING.\n";
13 if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
14 echo "PHP 5.0.0 or higher is required. ABORTING.\n";
18 global $wgCommandLineMode;
19 $wgCommandLineMode = true;
24 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
25 copyfileto( $sdir, $name, $ddir, $name, $perms );
28 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
29 global $wgInstallOwner, $wgInstallGroup;
31 $d = "{$ddir}/{$dname}";
32 if ( copy( "{$sdir}/{$sname}", $d ) ) {
33 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
34 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
36 # print "Copied \"{$sname}\" to \"{$d}\".\n";
38 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
43 function copydirectory( $source, $dest ) {
44 $handle = opendir( $source );
45 while ( false !== ( $f = readdir( $handle ) ) ) {
46 $fullname = "$source/$f";
47 if ( $f{0} != '.' && is_file( $fullname ) ) {
48 copyfile( $source, $f, $dest );
53 function readconsole( $prompt = '' ) {
54 static $isatty = null;
55 if ( is_null( $isatty ) ) {
56 if ( !function_exists( 'posix_isatty' ) || posix_isatty( STDIN ) ) {
63 if ( $isatty && function_exists( 'readline' ) ) {
64 return readline( $prompt );
69 if ( feof( STDIN ) ) {
72 $st = fgets(STDIN, 1024);
73 if ($st === false) return false;
80 # Read and execute SQL commands from a file
82 function dbsource( $fname, $db = false ) {
84 // Try $wgDatabase, which is used in the install and update scripts
86 if ( isset( $wgDatabase ) ) {
89 // No? Well, we must be outside of those scripts, so use the standard method
90 $db =& wfGetDB( DB_MASTER );
93 $error = $db->sourceFile( $fname );
94 if ( $error !== true ) {
100 # Obsolete, use Database::fieldExists()
101 function field_exists( $table, $field ) {
102 $fname = 'Update script: field_exists';
103 $db =& wfGetDB( DB_SLAVE );
104 $res = $db->query( "DESCRIBE $table", $fname );
107 while ( $row = $db->fetchObject( $res ) ) {
108 if ( $row->Field == $field ) {
116 # Obsolete Database::tableExists()
117 function table_exists( $db ) {
119 $res = mysql_list_tables( $wgDBname );
121 echo "** " . mysql_error() . "\n";
124 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
125 if( mysql_tablename( $res, $i ) == $db ) return true;
130 # Obsolete, use Database:fieldInfo()
131 function field_info( $table, $field ) {
132 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
133 $n = mysql_num_fields( $res );
134 for( $i = 0; $i < $n; $i++ ) {
135 $meta = mysql_fetch_field( $res, $i );
136 if( $field == $meta->name ) {