3 function install_version_checks() {
4 # Turn off output buffering if it's on
7 if( !function_exists( "version_compare" ) ) {
8 # version_compare was introduced in 4.1.0
9 die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
11 if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
12 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";
15 if (!extension_loaded('mysql')) {
16 if (!dl('mysql.so')) {
17 print "Could not load MySQL driver! Please compile ".
18 "php --with-mysql or install the mysql.so module.\n";
23 global $wgCommandLineMode;
24 $wgCommandLineMode = true;
29 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
30 copyfileto( $sdir, $name, $ddir, $name, $perms );
33 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
34 global $wgInstallOwner, $wgInstallGroup;
36 $d = "{$ddir}/{$dname}";
37 if ( copy( "{$sdir}/{$sname}", $d ) ) {
38 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
39 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
41 # print "Copied \"{$sname}\" to \"{$d}\".\n";
43 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
48 function copydirectory( $source, $dest ) {
49 $handle = opendir( $source );
50 while ( false !== ( $f = readdir( $handle ) ) ) {
51 $fullname = "$source/$f";
52 if ( $f{0} !="." && is_file( $fullname ) ) {
53 copyfile( $source, $f, $dest );
58 function readconsole() {
59 $fp = fopen( "php://stdin", "r" );
60 $resp = trim( fgets( $fp, 1024 ) );
66 function replacevars( $ins ) {
68 "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
69 "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
70 "wgDBadminuser", "wgDBadminpassword"
73 foreach ( $varnames as $var ) {
75 $ins = str_replace( '{$' . $var . '}', $$var, $ins );
81 # Read and execute SQL commands from a file
83 function dbsource( $fname, $database = false ) {
84 $fp = fopen( $fname, "r" );
85 if ( false === $fp ) {
86 print "Could not open \"{$fname}\".\n";
93 while ( ! feof( $fp ) ) {
94 $line = trim( fgets( $fp, 1024 ) );
95 $sl = strlen( $line ) - 1;
97 if ( $sl < 0 ) { continue; }
98 if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
100 if ( ";" == $line{$sl} ) {
102 $line = substr( $line, 0, $sl );
105 if ( "" != $cmd ) { $cmd .= " "; }
109 $cmd = replacevars( $cmd );
111 $res = $database->query( $cmd );
113 $res = mysql_query( $cmd );
115 if ( false === $res ) {
116 print "Query \"{$cmd}\" failed.\n";
127 # Obsolete, use Database::fieldExists()
128 function field_exists( $table, $field ) {
129 $fname = "Update script: field_exists";
130 $res = wfQuery( "DESCRIBE $table", $fname );
133 while ( $row = wfFetchObject( $res ) ) {
134 if ( $row->Field == $field ) {
142 # Obsolete Database::tableExists()
143 function table_exists( $db ) {
145 $res = mysql_list_tables( $wgDBname );
147 echo "** " . mysql_error() . "\n";
150 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
151 if( mysql_tablename( $res, $i ) == $db ) return true;
156 # Obsolete, use Database:fieldInfo()
157 function field_info( $table, $field ) {
158 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
159 $n = mysql_num_fields( $res );
160 for( $i = 0; $i < $n; $i++ ) {
161 $meta = mysql_fetch_field( $res, $i );
162 if( $field == $meta->name ) {