r93789 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93788‎ | r93789 | r93790 >
Date:22:01, 2 August 2011
Author:demon
Status:ok (Comments)
Tags:
Comment:
(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 (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/eval.php (modified) (history)
  • /trunk/phase3/maintenance/importDump.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTest.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importDump.php
@@ -229,7 +229,7 @@
230230
231231 function importFromStdin() {
232232 $file = fopen( 'php://stdin', 'rt' );
233 - if( posix_isatty( $file ) ) {
 233+ if( self::posix_isatty( $file ) ) {
234234 $this->maybeHelp( true );
235235 }
236236 return $this->importFromHandle( $file );
Index: trunk/phase3/maintenance/eval.php
@@ -58,7 +58,7 @@
5959 }
6060
6161 if ( function_exists( 'readline_add_history' )
62 - && posix_isatty( 0 /*STDIN*/ ) )
 62+ && Maintenance::posix_isatty( 0 /*STDIN*/ ) )
6363 {
6464 $useReadline = true;
6565 } else {
Index: trunk/phase3/maintenance/Maintenance.php
@@ -32,15 +32,6 @@
3333 wfPHPVersionError( 'cli' );
3434 }
3535
36 -// Wrapper for posix_isatty()
37 -if ( !function_exists( 'posix_isatty' ) ) {
38 - # We default as considering stdin a tty (for nice readline methods)
39 - # but treating stout as not a tty to avoid color codes
40 - function posix_isatty( $fd ) {
41 - return !$fd;
42 - }
43 -}
44 -
4536 /**
4637 * Abstract maintenance class for quickly writing and churning out
4738 * maintenance scripts with minimal effort. All that _must_ be defined
@@ -1195,6 +1186,22 @@
11961187 }
11971188
11981189 /**
 1190+ * Wrapper for posix_isatty()
 1191+ * We default as considering stdin a tty (for nice readline methods)
 1192+ * but treating stout as not a tty to avoid color codes
 1193+ *
 1194+ * @param $fd int File descriptor
 1195+ * @return bool
 1196+ */
 1197+ public static function posix_isatty( $fd ) {
 1198+ if ( !MWInit::functionExists( 'posix_isatty' ) ) {
 1199+ return !$fd;
 1200+ } else {
 1201+ return posix_isatty( $fd );
 1202+ }
 1203+}
 1204+
 1205+ /**
11991206 * Prompt the console for input
12001207 * @param $prompt String what to begin the line with, like '> '
12011208 * @return String response
@@ -1202,7 +1209,7 @@
12031210 public static function readconsole( $prompt = '> ' ) {
12041211 static $isatty = null;
12051212 if ( is_null( $isatty ) ) {
1206 - $isatty = posix_isatty( 0 /*STDIN*/ );
 1213+ $isatty = self::posix_isatty( 0 /*STDIN*/ );
12071214 }
12081215
12091216 if ( $isatty && function_exists( 'readline' ) ) {
Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -33,6 +33,8 @@
3434 * (bug 25355) Parser generates edit section links for special pages.
3535 * (bug 27894) Move 'editondblclick' event listener down from body to
3636 div#bodyContent.
 37+* (bug 30172) The check for posix_isatty() in maintenance scripts did not detect
 38+ when the function exists but is disabled. Introduced Maintenance::posix_isatty()
3739
3840 === API changes in 1.19 ===
3941 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/tests/parser/parserTest.inc
@@ -78,7 +78,7 @@
7979 */
8080 public function __construct( $options = array() ) {
8181 # Only colorize output if stdout is a terminal.
82 - $this->color = !wfIsWindows() && posix_isatty( 1 );
 82+ $this->color = !wfIsWindows() && Maintenance::posix_isatty( 1 );
8383
8484 if ( isset( $options['color'] ) ) {
8585 switch( $options['color'] ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r107899MFT r93789reedy17:02, 3 January 2012

Comments

#Comment by P858snake (talk | contribs)   06:44, 3 August 2011

Tag for 1.18?

#Comment by Dantman (talk | contribs)   06:46, 3 August 2011

This seams to be affecting people simply trying to install 1.17, so yeah backporting to 1.18 at minimum sounds like a good idea.

Status & tagging log