Address fixme on r101644 (bug 32325, bug 32263), originally for bug 31822. PHP 5...
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 15 Nov 2011 15:04:36 +0000 (15:04 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 15 Nov 2011 15:04:36 +0000 (15:04 +0000)
People didn't seem to like the idea of bumping the minimum version to 5.2.7 since some distros like being behind the times.

maintenance/Maintenance.php

index 454891f..c807c08 100644 (file)
@@ -309,10 +309,11 @@ abstract class Maintenance {
                }
                if ( $channel === null ) {
                        $this->cleanupChanneled();
-
-                       $f = fopen( 'php://stdout', 'a' );
-                       fwrite( $f, $out );
-                       fclose( $f );
+                       if( php_sapi_name() == 'cli' ) {
+                               fwrite( STDOUT, $out );
+                       } else {
+                               print( $out );
+                       }
                }
                else {
                        $out = preg_replace( '/\n\z/', '', $out );
@@ -331,9 +332,7 @@ abstract class Maintenance {
                if ( php_sapi_name() == 'cli' ) {
                        fwrite( STDERR, $err . "\n" );
                } else {
-                       $f = fopen( 'php://stderr', 'a' );
-                       fwrite( $f, $err . "\n" );
-                       fclose( $f );
+                       print $err;
                }
                $die = intval( $die );
                if ( $die > 0 ) {
@@ -349,9 +348,11 @@ abstract class Maintenance {
         */
        public function cleanupChanneled() {
                if ( !$this->atLineStart ) {
-                       $handle = fopen( 'php://stdout', 'w' );
-                       fwrite( $handle, "\n" );
-                       fclose( $handle );
+                       if( php_sapi_name() == 'cli' ) {
+                               fwrite( STDOUT, "\n" );
+                       } else {
+                               print "\n";
+                       }
                        $this->atLineStart = true;
                }
        }
@@ -370,25 +371,34 @@ abstract class Maintenance {
                        return;
                }
 
-               $handle = fopen( 'php://stdout', 'a' );
+               $cli = php_sapi_name() == 'cli';
 
                // End the current line if necessary
                if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
-                       fwrite( $handle, "\n" );
+                       if( $cli ) {
+                               fwrite( STDOUT, "\n" );
+                       } else {
+                               print "\n";
+                       }
                }
 
-               fwrite( $handle, $msg );
+               if( $cli ) {
+                       fwrite( STDOUT, $msg );
+               } else {
+                       print $msg;
+               }
 
                $this->atLineStart = false;
                if ( $channel === null ) {
                        // For unchanneled messages, output trailing newline immediately
-                       fwrite( $handle, "\n" );
+                       if( $handle ) {
+                               fwrite( STDOUT, "\n" );
+                       } else {
+                               print "\n";
+                       }
                        $this->atLineStart = true;
                }
                $this->lastChannel = $channel;
-
-               // Cleanup handle
-               fclose( $handle );
        }
 
        /**