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. 4.3.2 or higher is required. ABORTING.\n";
13 if( version_compare( phpversion(), '4.3.2' ) < 0 ) {
14 echo "PHP 4.3.2 or higher is required. ABORTING.\n";
18 if (!extension_loaded('mysql')) {
19 if (!dl('mysql.so')) {
20 print 'Could not load MySQL driver! Please compile '.
21 "php --with-mysql or install the mysql.so module.\n";
26 global $wgCommandLineMode;
27 $wgCommandLineMode = true;
32 function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
33 copyfileto( $sdir, $name, $ddir, $name, $perms );
36 function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
37 global $wgInstallOwner, $wgInstallGroup;
39 $d = "{$ddir}/{$dname}";
40 if ( copy( "{$sdir}/{$sname}", $d ) ) {
41 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
42 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
44 # print "Copied \"{$sname}\" to \"{$d}\".\n";
46 print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
51 function copydirectory( $source, $dest ) {
52 $handle = opendir( $source );
53 while ( false !== ( $f = readdir( $handle ) ) ) {
54 $fullname = "$source/$f";
55 if ( $f{0} != '.' && is_file( $fullname ) ) {
56 copyfile( $source, $f, $dest );
61 function readconsole( $prompt = '' ) {
62 static $isatty = null, $fp = null;
63 if ( is_null( $fp ) ) {
64 $fp = fopen( 'php://stdin', 'r' );
66 if ( is_null( $isatty ) ) {
67 if ( !function_exists( 'posix_isatty' ) || posix_isatty( $fp ) ) {
74 if ( $isatty && function_exists( 'readline' ) ) {
75 return readline( $prompt );
83 $st = fgets($fp, 1024);
84 if ($st === false) return false;
90 function replacevars( $ins ) {
92 'wgDBserver', 'wgDBname', 'wgDBintlname', 'wgDBuser',
93 'wgDBpassword', 'wgDBsqluser', 'wgDBsqlpassword',
94 'wgDBadminuser', 'wgDBadminpassword', 'wgDBprefix'
97 foreach ( $varnames as $var ) {
98 if( isset( $GLOBALS[$var] ) ) {
99 $val = addslashes( $GLOBALS[$var] );
100 $ins = str_replace( '{$' . $var . '}', $val, $ins );
101 $ins = str_replace( '/*$' . $var . '*/`', '`' . $val, $ins );
102 $ins = str_replace( '/*$' . $var . '*/', $val, $ins );
109 # Read and execute SQL commands from a file
111 function dbsource( $fname, $database = false ) {
112 $fp = fopen( $fname, 'r' );
113 if ( false === $fp ) {
114 print "Could not open \"{$fname}\".\n";
121 while ( ! feof( $fp ) ) {
122 $line = trim( fgets( $fp, 1024 ) );
123 $sl = strlen( $line ) - 1;
125 if ( $sl < 0 ) { continue; }
126 if ( '-' == $line{0} && '-' == $line{1} ) { continue; }
128 if ( ';' == $line{$sl} && ($sl < 2 || ';' != $line{$sl - 1})) {
130 $line = substr( $line, 0, $sl );
133 if ( '' != $cmd ) { $cmd .= ' '; }
137 $cmd = str_replace(';;', ";", $cmd);
138 $cmd = replacevars( $cmd );
140 $res = $database->query( $cmd, 'dbsource', true );
142 $res = mysql_query( $cmd );
144 if ( false === $res ) {
145 $err = mysql_error();
146 print "Query \"{$cmd}\" failed with error code \"$err\".\n";
157 # Obsolete, use Database::fieldExists()
158 function field_exists( $table, $field ) {
159 $fname = 'Update script: field_exists';
160 $db =& wfGetDB( DB_SLAVE );
161 $res = $db->query( "DESCRIBE $table", $fname );
164 while ( $row = $db->fetchObject( $res ) ) {
165 if ( $row->Field == $field ) {
173 # Obsolete Database::tableExists()
174 function table_exists( $db ) {
176 $res = mysql_list_tables( $wgDBname );
178 echo "** " . mysql_error() . "\n";
181 for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
182 if( mysql_tablename( $res, $i ) == $db ) return true;
187 # Obsolete, use Database:fieldInfo()
188 function field_info( $table, $field ) {
189 $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
190 $n = mysql_num_fields( $res );
191 for( $i = 0; $i < $n; $i++ ) {
192 $meta = mysql_fetch_field( $res, $i );
193 if( $field == $meta->name ) {