http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93789
Revision: 93789 Author: demon Date: 2011-08-02 22:01:58 +0000 (Tue, 02 Aug 2011) Log Message: ----------- (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. Modified Paths: -------------- trunk/phase3/RELEASE-NOTES-1.19 trunk/phase3/maintenance/Maintenance.php trunk/phase3/maintenance/eval.php trunk/phase3/maintenance/importDump.php trunk/phase3/tests/parser/parserTest.inc Modified: trunk/phase3/RELEASE-NOTES-1.19 =================================================================== --- trunk/phase3/RELEASE-NOTES-1.19 2011-08-02 21:09:22 UTC (rev 93788) +++ trunk/phase3/RELEASE-NOTES-1.19 2011-08-02 22:01:58 UTC (rev 93789) @@ -33,6 +33,8 @@ * (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. Modified: trunk/phase3/maintenance/Maintenance.php =================================================================== --- trunk/phase3/maintenance/Maintenance.php 2011-08-02 21:09:22 UTC (rev 93788) +++ trunk/phase3/maintenance/Maintenance.php 2011-08-02 22:01:58 UTC (rev 93789) @@ -32,15 +32,6 @@ 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 @@ -1195,6 +1186,22 @@ } /** + * 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 '> ' * @return String response @@ -1202,7 +1209,7 @@ 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' ) ) { Modified: trunk/phase3/maintenance/eval.php =================================================================== --- trunk/phase3/maintenance/eval.php 2011-08-02 21:09:22 UTC (rev 93788) +++ trunk/phase3/maintenance/eval.php 2011-08-02 22:01:58 UTC (rev 93789) @@ -58,7 +58,7 @@ } if ( function_exists( 'readline_add_history' ) - && posix_isatty( 0 /*STDIN*/ ) ) + && Maintenance::posix_isatty( 0 /*STDIN*/ ) ) { $useReadline = true; } else { Modified: trunk/phase3/maintenance/importDump.php =================================================================== --- trunk/phase3/maintenance/importDump.php 2011-08-02 21:09:22 UTC (rev 93788) +++ trunk/phase3/maintenance/importDump.php 2011-08-02 22:01:58 UTC (rev 93789) @@ -229,7 +229,7 @@ function importFromStdin() { $file = fopen( 'php://stdin', 'rt' ); - if( posix_isatty( $file ) ) { + if( self::posix_isatty( $file ) ) { $this->maybeHelp( true ); } return $this->importFromHandle( $file ); Modified: trunk/phase3/tests/parser/parserTest.inc =================================================================== --- trunk/phase3/tests/parser/parserTest.inc 2011-08-02 21:09:22 UTC (rev 93788) +++ trunk/phase3/tests/parser/parserTest.inc 2011-08-02 22:01:58 UTC (rev 93789) @@ -78,7 +78,7 @@ */ 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'] ) { _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs