From 59cfbd0cf9a6506bea8078d1a406d75e95b95e4a Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 2 Aug 2011 22:01:58 +0000 Subject: [PATCH] (bug 30172) posix_isatty() fallback does not work when the function has been disabled (but exists). While we're at it, make things work for HipHop too. --- RELEASE-NOTES-1.19 | 2 ++ maintenance/Maintenance.php | 27 +++++++++++++++++---------- maintenance/eval.php | 2 +- maintenance/importDump.php | 2 +- tests/parser/parserTest.inc | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index beb19a2135..1d0f8289df 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -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. diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index fad4efb0da..798610056d 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -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' ) ) { diff --git a/maintenance/eval.php b/maintenance/eval.php index 33c9a5d72f..1502ad3ec5 100644 --- a/maintenance/eval.php +++ b/maintenance/eval.php @@ -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 { diff --git a/maintenance/importDump.php b/maintenance/importDump.php index 2390ba5418..3243b5696d 100644 --- a/maintenance/importDump.php +++ b/maintenance/importDump.php @@ -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 ); diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 6d465bf5fd..9b8dcaa485 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -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'] ) { -- 2.20.1