Added alias of jQuery to $j - this is only to get site/user scripts that were using...
[lhc/web/wiklou.git] / maintenance / install-utils.inc
index 70bcf51..e37aeb9 100644 (file)
@@ -12,30 +12,20 @@ function install_version_checks() {
        # if PHP is globally configured to run through a gzip filter.
        @ob_implicit_flush( true );
 
-       if( !function_exists( 'version_compare' ) ) {
+       if ( !function_exists( 'version_compare' ) ) {
                # version_compare was introduced in 4.1.0
-               echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.0.0 or higher is required. ABORTING.\n";
+               echo "Your PHP version is much too old; 4.0.x will _not_ work. 5.1.0 or higher is required. ABORTING.\n";
                die( 1 );
        }
-       if( version_compare( phpversion(), '5.0.0' ) < 0 ) {
-               echo "PHP 5.0.0 or higher is required. If PHP 5 is available only when \n".
-   "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n".
+       if ( version_compare( phpversion(), '5.1.0' ) < 0 ) {
+               echo "PHP 5.1.0 or higher is required. If PHP 5 is available only when \n" .
+   "PHP files have a .php5 extension, please navigate to <a href=\"index.php5\">index.php5</a> \n" .
    "to continue installation. ABORTING.\n";
                die( 1 );
        }
 
-       // Test for PHP bug which breaks PHP 5.0.x on 64-bit...
-       // As of 1.8 this breaks lots of common operations instead
-       // of just some rare ones like export.
-       $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
-       if( !isset( $borked[-1] ) ) {
-               echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
-                       "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
-               die( 1 );
-       }
-
        $test = new PhpXmlBugTester();
-       if( !$test->ok ) {
+       if ( !$test->ok ) {
                echo "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
                        "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
                        "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
@@ -44,17 +34,15 @@ function install_version_checks() {
        }
 
        $test = new PhpRefCallBugTester;
-       $ok = false;
-       call_user_func_array( array( $test, 'test' ), array( &$ok ) );
-       if ( !$ok ) {
-               echo "PHP 5.2.11, 5.2.12, and 5.3.1 (your version: " . phpversion() . ") are not compatible with\n" .
-               "MediaWiki due to a bug involving reference parameters to __call. Upgrade to\n" .
-               "PHP 5.3.2 (5.2.13 for 5.2 users), or downgrade to PHP 5.3.0 (5.2.10 for 5.2\n" .
-               "users) to fix this. ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
+       $test->execute();
+       if ( !$test->ok ) {
+               echo "PHP 5.3.1 is not compatible with MediaWiki due to a bug involving\n" .
+                       "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
+                       "downgrade to PHP 5.3.0 to fix this.\n" .
+                       "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n";
                die( 1 );
        }
 
-
        global $wgCommandLineMode;
        $wgCommandLineMode = true;
        umask( 000 );
@@ -75,27 +63,50 @@ class PhpXmlBugTester {
 
                $parser = xml_parser_create();
                xml_set_character_data_handler( $parser, array( $this, 'chardata' ) );
-               $parsedOk = xml_parse($parser, $xml, true);
-               $this->ok = $parsedOk && ($this->parsedData == $charData);
+               $parsedOk = xml_parse( $parser, $xml, true );
+               $this->ok = $parsedOk && ( $this->parsedData == $charData );
        }
-       public function chardata($parser, $data) {
+       public function chardata( $parser, $data ) {
                $this->parsedData .= $data;
        }
 }
 
 /**
- * Test for PHP bug #50394
+ * Test for PHP bug #50394 (PHP 5.3.x conversion to null only, not 5.2.x)
  */
 class PhpRefCallBugTester {
+       public $ok = false;
+
        function __call( $name, $args ) {
-               $args[0] = true;
+               $old = error_reporting( E_ALL & ~E_WARNING );
+               call_user_func_array( array( $this, 'checkForBrokenRef' ), $args );
+               error_reporting( $old );
+       }
+
+       function checkForBrokenRef( &$var ) {
+               if ( $var ) {
+                       $this->ok = true;
+               }
+       }
+
+       function execute() {
+               $var = true;
+               call_user_func_array( array( $this, 'foo' ), array( &$var ) );
+       }
+}
+
+if ( !function_exists( 'posix_isatty' ) ) {
+       # We default as considering stdin a tty (for nice readline methods)
+       # but treating stout as not a tty to avoid color codes
+       function posix_isatty( $fd ) {
+               return !$fd;
        }
 }
 
 function readconsole( $prompt = '' ) {
        static $isatty = null;
        if ( is_null( $isatty ) ) {
-               if ( !function_exists( 'posix_isatty' ) || posix_isatty( 0 /*STDIN*/ ) ) {
+               if ( posix_isatty( 0 /*STDIN*/ ) ) {
                        $isatty = true;
                } else {
                        $isatty = false;
@@ -111,10 +122,10 @@ function readconsole( $prompt = '' ) {
                        if ( feof( STDIN ) ) {
                                $st = false;
                        } else {
-                               $st = fgets(STDIN, 1024);
+                               $st = fgets( STDIN, 1024 );
                        }
                }
-               if ($st === false) return false;
+               if ( $st === false ) return false;
                $resp = trim( $st );
                return $resp;
        }
@@ -122,10 +133,10 @@ function readconsole( $prompt = '' ) {
 
 function findExecutable( $name ) {
        $paths = explode( PATH_SEPARATOR, getenv( "PATH" ) );
-       foreach( $paths as $path ) {
+       foreach ( $paths as $path ) {
                $full = $path . DIRECTORY_SEPARATOR . $name;
-               if( file_exists( $full ) ) {
-                       if( wfIsWindows() || is_executable( $full ) ) {
+               if ( file_exists( $full ) ) {
+                       if ( wfIsWindows() || is_executable( $full ) ) {
                                return $full;
                        }
                }
@@ -135,16 +146,16 @@ function findExecutable( $name ) {
 
 function readlineEmulation( $prompt ) {
        $bash = "bash";
-       if( !wfIsWindows() && findExecutable( $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 ) {
+               if ( $retval == 0 ) {
                        return $line;
-               } elseif( $retval == 127 ) {
+               } 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()...
@@ -159,7 +170,7 @@ function readlineEmulation( $prompt ) {
                return false;
        }
        print $prompt;
-       return fgets(STDIN, 1024);
+       return fgets( STDIN, 1024 );
 }
 
 
@@ -169,22 +180,20 @@ function readlineEmulation( $prompt ) {
 function dbsource( $fname, $db = false ) {
        wfDeprecated( __METHOD__ );
        if ( !$db ) {
-               // Try $wgDatabase, which is used in the install and update scripts
-               global $wgDatabase;
-               if ( isset( $wgDatabase ) ) {
-                       $db = $wgDatabase;
-               } else {
-                       // No? Well, we must be outside of those scripts, so use the standard method
-                       $db = wfGetDB( DB_MASTER );
-               }
+               $db = wfGetDB( DB_MASTER );
        }
        $error = $db->sourceFile( $fname );
        if ( $error !== true ) {
                print $error;
-               exit(1);
+               exit( 1 );
        }
 }
 
+function archive( $name ) {
+       wfDeprecated( __METHOD__ );
+       return DatabaseBase::patchPath( $name );
+}
+
 /**
  * Get the value of session.save_path
  *