(bug 30172) posix_isatty() fallback does not work when the function has been disabled...
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 2 Aug 2011 22:01:58 +0000 (22:01 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 2 Aug 2011 22:01:58 +0000 (22:01 +0000)
RELEASE-NOTES-1.19
maintenance/Maintenance.php
maintenance/eval.php
maintenance/importDump.php
tests/parser/parserTest.inc

index beb19a2..1d0f828 100644 (file)
@@ -33,6 +33,8 @@ production.
 * (bug 25355) Parser generates edit section links for special pages.
 * (bug 27894) Move 'editondblclick' event listener down from body to
   div#bodyContent.
+* (bug 30172) The check for posix_isatty() in maintenance scripts did not detect
+  when the function exists but is disabled. Introduced Maintenance::posix_isatty()
 
 === API changes in 1.19 ===
 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
index fad4efb..7986100 100644 (file)
@@ -32,15 +32,6 @@ if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.2
        wfPHPVersionError( 'cli' );
 }
 
-// Wrapper for posix_isatty()
-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;
-       }
-}
-
 /**
  * Abstract maintenance class for quickly writing and churning out
  * maintenance scripts with minimal effort. All that _must_ be defined
@@ -1194,6 +1185,22 @@ abstract class Maintenance {
                return $title;
        }
 
+       /**
+        * Wrapper for posix_isatty()
+        * We default as considering stdin a tty (for nice readline methods)
+        * but treating stout as not a tty to avoid color codes
+        *
+        * @param $fd int File descriptor
+        * @return bool
+        */
+       public static function posix_isatty( $fd ) {
+               if ( !MWInit::functionExists( 'posix_isatty' ) ) {
+                       return !$fd;
+               } else {
+                       return posix_isatty( $fd );
+               }
+}
+
        /**
         * Prompt the console for input
         * @param $prompt String what to begin the line with, like '> '
@@ -1202,7 +1209,7 @@ abstract class Maintenance {
        public static function readconsole( $prompt = '> ' ) {
                static $isatty = null;
                if ( is_null( $isatty ) ) {
-                       $isatty = posix_isatty( 0 /*STDIN*/ );
+                       $isatty = self::posix_isatty( 0 /*STDIN*/ );
                }
 
                if ( $isatty && function_exists( 'readline' ) ) {
index 33c9a5d..1502ad3 100644 (file)
@@ -58,7 +58,7 @@ if ( isset( $options['d'] ) ) {
 }
 
 if ( function_exists( 'readline_add_history' )
-       && posix_isatty( 0 /*STDIN*/ ) )
+       && Maintenance::posix_isatty( 0 /*STDIN*/ ) )
 {
        $useReadline = true;
 } else {
index 2390ba5..3243b56 100644 (file)
@@ -229,7 +229,7 @@ TEXT;
 
        function importFromStdin() {
                $file = fopen( 'php://stdin', 'rt' );
-               if( posix_isatty( $file ) ) {
+               if( self::posix_isatty( $file ) ) {
                        $this->maybeHelp( true );
                }
                return $this->importFromHandle( $file );
index 6d465bf..9b8dcaa 100644 (file)
@@ -78,7 +78,7 @@ class ParserTest {
         */
        public function __construct( $options = array() ) {
                # Only colorize output if stdout is a terminal.
-               $this->color = !wfIsWindows() && posix_isatty( 1 );
+               $this->color = !wfIsWindows() && Maintenance::posix_isatty( 1 );
 
                if ( isset( $options['color'] ) ) {
                        switch( $options['color'] ) {