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 die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
12 if( version_compare( phpversion(), '4.3.2' ) < 0 ) {
13 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";
16 if (!extension_loaded('mysql')) {
17 if (!dl('mysql.so')) {
18 print 'Could not load MySQL driver! Please compile '.
19 "php --with-mysql or install the mysql.so module.\n";
24 global $wgCommandLineMode;
25 $wgCommandLineMode = true;
30 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
31 copyfileto( $sdir, $name, $ddir, $name, $perms );
34 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
35 global $wgInstallOwner, $wgInstallGroup;
37 $d = "{$ddir}/{$dname}";
38 if ( copy( "{$sdir}/{$sname}", $d ) ) {
39 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
40 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
42 # print "Copied \"{$sname}\" to \"{$d}\".\n";
44 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
49 function copydirectory( $source, $dest ) {
50 $handle = opendir( $source );
51 while ( false !== ( $f = readdir( $handle ) ) ) {
52 $fullname = "$source/$f";
53 if ( $f{0} != '.' && is_file( $fullname ) ) {
54 copyfile( $source, $f, $dest );
59 function readconsole( $prompt = '' ) {
60 if ( function_exists( 'readline' ) ) {
61 return readline( $prompt );
64 $fp = fopen( 'php://stdin', 'r' );
65 $resp = trim( fgets( $fp, 1024 ) );
71 function replacevars( $ins ) {
73 'wgDBserver', 'wgDBname', 'wgDBintlname', 'wgDBuser',
74 'wgDBpassword', 'wgDBsqluser', 'wgDBsqlpassword',
75 'wgDBadminuser', 'wgDBadminpassword', 'wgDBprefix'
78 foreach ( $varnames as $var ) {
80 $ins = str_replace( '{$' . $var . '}', $$var, $ins );
81 $ins = str_replace( '/*$' . $var . '*/`', '`' . $$var, $ins );
82 $ins = str_replace( '/*$' . $var . '*/', $$var, $ins );
88 # Read and execute SQL commands from a file
90 function dbsource( $fname, $database = false ) {
91 $fp = fopen( $fname, 'r' );
92 if ( false === $fp ) {
93 print "Could not open \"{$fname}\".\n";
100 while ( ! feof( $fp ) ) {
101 $line = trim( fgets( $fp, 1024 ) );
102 $sl = strlen( $line ) - 1;
104 if ( $sl < 0 ) { continue; }
105 if ( '-' == $line{0} && '-' == $line{1} ) { continue; }
107 if ( ';' == $line{$sl} ) {
109 $line = substr( $line, 0, $sl );
112 if ( '' != $cmd ) { $cmd .= ' '; }
116 $cmd = replacevars( $cmd );
118 $res = $database->query( $cmd );
120 $res = mysql_query( $cmd );
122 if ( false === $res ) {
123 $err = mysql_error();
124 print "Query \"{$cmd}\" failed with error code \"$err\".\n";
135 # Obsolete, use Database::fieldExists()
136 function field_exists( $table, $field ) {
137 $fname = 'Update script: field_exists';
138 $db =& wfGetDB( DB_SLAVE );
139 $res = $db->query( "DESCRIBE $table", $fname );
142 while ( $row = $db->fetchObject( $res ) ) {
143 if ( $row->Field == $field ) {
151 # Obsolete Database::tableExists()
152 function table_exists( $db ) {
154 $res = mysql_list_tables( $wgDBname );
156 echo "** " . mysql_error() . "\n";
159 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
160 if( mysql_tablename( $res, $i ) == $db ) return true;
165 # Obsolete, use Database:fieldInfo()
166 function field_info( $table, $field ) {
167 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
168 $n = mysql_num_fields( $res );
169 for( $i = 0; $i < $n; $i++ ) {
170 $meta = mysql_fetch_field( $res, $i );
171 if( $field == $meta->name ) {