3 function install_version_checks() {
4 if( !function_exists( "version_compare" ) ) {
5 # version_compare was introduced in 4.1.0
6 die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
8 if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
9 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";
11 if( !ini_get( "register_globals" ) ) {
12 echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\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 global $wgInstallOwner, $wgInstallGroup;
32 $d = "{$ddir}/{$name}";
33 if ( copy( "{$sdir}/{$name}", $d ) ) {
34 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
35 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
37 # print "Copied \"{$name}\" to \"{$ddir}\".\n";
39 print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
44 function copydirectory( $source, $dest ) {
45 $handle = opendir( $source );
46 while ( false !== ( $f = readdir( $handle ) ) ) {
47 $fullname = "$source/$f";
48 if ( $f{0} !="." && is_file( $fullname ) ) {
49 copyfile( $source, $f, $dest );
54 function readconsole() {
55 $fp = fopen( "php://stdin", "r" );
56 $resp = trim( fgets( $fp, 1024 ) );
62 function replacevars( $ins ) {
64 "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
65 "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
66 "wgDBadminuser", "wgDBadminpassword"
69 foreach ( $varnames as $var ) {
71 $ins = str_replace( '{$' . $var . '}', $$var, $ins );
77 # Read and execute SQL commands from a file
79 function dbsource( $fname, $conn = false ) {
80 $fp = fopen( $fname, "r" );
81 if ( false === $fp ) {
82 print "Could not open \"{$fname}\".\n";
89 while ( ! feof( $fp ) ) {
90 $line = trim( fgets( $fp, 1024 ) );
91 $sl = strlen( $line ) - 1;
93 if ( $sl < 0 ) { continue; }
94 if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
96 if ( ";" == $line{$sl} ) {
98 $line = substr( $line, 0, $sl );
101 if ( "" != $cmd ) { $cmd .= " "; }
105 $cmd = replacevars( $cmd );
107 $res = mysql_query( $cmd, $conn );
109 $res = mysql_query( $cmd );
111 if ( false === $res ) {
112 print "Query \"{$cmd}\" failed.\n";
124 function field_exists( $table, $field ) {
125 $fname = "Update script: field_exists";
126 $res = wfQuery( "DESCRIBE $table", $fname );
129 while ( $row = wfFetchObject( $res ) ) {
130 if ( $row->Field == $field ) {
139 function table_exists( $db ) {
141 $res = mysql_list_tables( $wgDBname );
143 echo "** " . mysql_error() . "\n";
146 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
147 if( mysql_tablename( $res, $i ) == $db ) return true;
152 function field_info( $table, $field ) {
153 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
154 $n = mysql_num_fields( $res );
155 for( $i = 0; $i < $n; $i++ ) {
156 $meta = mysql_fetch_field( $res, $i );
157 if( $field == $meta->name ) {