Move $wgUseNormalUser setting to constructors.
[lhc/web/wiklou.git] / install-utils.inc
index a989257..473cdf5 100644 (file)
@@ -1,5 +1,12 @@
 <?php
 
+/**
+ * This file contains functions used by the install script (config/index.php)
+ * and maintenance scripts. It is not loaded in normal web requests.
+ *
+ * @file
+ */
+
 function install_version_checks() {
        # We dare not turn output buffer _off_ since this will break completely
        # if PHP is globally configured to run through a gzip filter.
@@ -33,35 +40,6 @@ function install_version_checks() {
        @set_time_limit( 0 );
 }
 
-function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
-       copyfileto( $sdir, $name, $ddir, $name, $perms );
-}
-
-function copyfileto( $sdir, $sname, $ddir, $dname, $perms = 0664 ) {
-       global $wgInstallOwner, $wgInstallGroup;
-
-       $d = "{$ddir}/{$dname}";
-       if ( copy( "{$sdir}/{$sname}", $d ) ) {
-               if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
-               if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
-               chmod( $d, $perms );
-               # print "Copied \"{$sname}\" to \"{$d}\".\n";
-       } else {
-               print "Failed to copy file \"{$sname}\" to \"{$ddir}/{$dname}\".\n";
-               exit();
-       }
-}
-
-function copydirectory( $source, $dest ) {
-       $handle = opendir( $source );
-       while ( false !== ( $f = readdir( $handle ) ) ) {
-               $fullname = "$source/$f";
-               if ( $f{0} != '.' && is_file( $fullname ) ) {
-                       copyfile( $source, $f, $dest );
-               }
-       }
-}
-
 function readconsole( $prompt = '' ) {
        static $isatty = null;
        if ( is_null( $isatty ) ) {
@@ -76,22 +54,68 @@ function readconsole( $prompt = '' ) {
                return readline( $prompt );
        } else {
                if ( $isatty ) {
-                       print $prompt;
-               }
-               if ( feof( STDIN ) ) {
-                       return false;
+                       $st = readlineEmulation( $prompt );
+               } else {
+                       if ( feof( STDIN ) ) {
+                               $st = false;
+                       } else {
+                               $st = fgets(STDIN, 1024);
+                       }
                }
-               $st = fgets(STDIN, 1024);
                if ($st === false) return false;
                $resp = trim( $st );
                return $resp;
        }
 }
 
+function findExecutable( $name ) {
+       $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
+       foreach( $paths as $path ) {
+               $full = $path . DIRECTORY_SEPARATOR . $name;
+               if( file_exists( $full ) ) {
+                       if( wfIsWindows() || is_executable( $full ) ) {
+                               return $full;
+                       }
+               }
+       }
+       return false;
+}
+
+function readlineEmulation( $prompt ) {
+       $bash = "bash";
+       if( !wfIsWindows() && findExecutable( $bash ) ) {
+               $retval = false;
+               $encPrompt = wfEscapeShellArg( $prompt );
+               $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
+               $encCommand = wfEscapeShellArg( $command );
+               $line = wfShellExec( "$bash -c $encCommand", $retval );
+               
+               if( $retval == 0 ) {
+                       return $line;
+               } elseif( $retval == 127 ) {
+                       // Couldn't execute bash even though we thought we saw it.
+                       // Shell probably spit out an error message, sorry :(
+                       // Fall through to fgets()...
+               } else {
+                       // EOF/ctrl+D
+                       return false;
+               }
+       }
+       
+       // Fallback... we'll have no editing controls, EWWW
+       if ( feof( STDIN ) ) {
+               return false;
+       }
+       print $prompt;
+       return fgets(STDIN, 1024);
+}
+
+
 #
 # Read and execute SQL commands from a file
 #
 function dbsource( $fname, $db = false ) {
+       wfDeprecated( __METHOD__ );
        if ( !$db ) {
                // Try $wgDatabase, which is used in the install and update scripts
                global $wgDatabase;
@@ -112,7 +136,7 @@ function dbsource( $fname, $db = false ) {
 /**
  * Get the value of session.save_path
  *
- * Per http://uk.php.net/manual/en/ref.session.php#ini.session.save-path,
+ * Per http://www.php.net/manual/en/ref.session.php#ini.session.save-path,
  * this might have some additional preceding parts which need to be
  * ditched
  *
@@ -127,7 +151,7 @@ function mw_get_session_save_path() {
 /**
  * Is dl() available to us?
  *
- * According to http://uk.php.net/manual/en/function.dl.php, dl()
+ * According to http://www.php.net/manual/en/function.dl.php, dl()
  * is *not* available when `enable_dl` is off, or under `safe_mode`
  *
  * @return bool
@@ -135,6 +159,6 @@ function mw_get_session_save_path() {
 function mw_have_dl() {
        return function_exists( 'dl' )
                && is_callable( 'dl' )
-               && ini_get( 'enable_dl' )
-               && !ini_get( 'safe_mode' );
+               && wfIniGetBool( 'enable_dl' )
+               && !wfIniGetBool( 'safe_mode' );
 }
\ No newline at end of file