tidy-resistant placeholder
[lhc/web/wiklou.git] / install-utils.inc
index 55e712c..34dd701 100644 (file)
@@ -1,6 +1,9 @@
 <?php
 
 function install_version_checks() {
+       # Turn off output buffering if it's on
+       @ob_end_flush();
+       
        if( !function_exists( "version_compare" ) ) {
                # version_compare was introduced in 4.1.0
                die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
@@ -52,14 +55,18 @@ function copydirectory( $source, $dest ) {
        }
 }
 
-function readconsole() {
-       $fp = fopen( "php://stdin", "r" );
-       $resp = trim( fgets( $fp, 1024 ) );
-       fclose( $fp );
-       return $resp;
+function readconsole( $prompt = "" ) {
+       if ( function_exists( "readline" ) ) {
+               return readline( $prompt );
+       } else {
+               print $prompt;
+               $fp = fopen( "php://stdin", "r" );
+               $resp = trim( fgets( $fp, 1024 ) );
+               fclose( $fp );
+               return $resp;
+       }
 }
 
-
 function replacevars( $ins ) {
        $varnames = array(
                "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
@@ -110,7 +117,8 @@ function dbsource( $fname, $database = false ) {
                                $res = mysql_query( $cmd );
 
                        if ( false === $res ) {
-                               print "Query \"{$cmd}\" failed.\n";
+                               $err = mysql_error();
+                               print "Query \"{$cmd}\" failed with error code \"$err\".\n";
                                exit();
                        }
 
@@ -124,10 +132,11 @@ function dbsource( $fname, $database = false ) {
 # Obsolete, use Database::fieldExists()
 function field_exists( $table, $field ) {
        $fname = "Update script: field_exists";
-       $res = wfQuery( "DESCRIBE $table", $fname );
+       $db =& wfGetDB( DB_SLAVE );
+       $res = $db->query( "DESCRIBE $table", $fname );
        $found = false;
        
-       while ( $row = wfFetchObject( $res ) ) {
+       while ( $row = $db->fetchObject( $res ) ) {
                if ( $row->Field == $field ) {
                        $found = true;
                        break;