* (bug 12184) Exceptions now sent to stderr instead of stdout for command-line
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 6 Dec 2007 21:07:49 +0000 (21:07 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 6 Dec 2007 21:07:49 +0000 (21:07 +0000)
  scripts, making for cleaner reporting during batch jobs. PHP errors will also
  be redirected in most cases on PHP 5.2.4 and later, switching 'display_errors'
  to 'stderr' at runtime.

RELEASE-NOTES
includes/Exception.php
maintenance/backup.inc
maintenance/commandLine.inc
maintenance/dumpTextPass.php

index be0b761..fd92d07 100644 (file)
@@ -219,6 +219,11 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 11993) Remove contentsub "revision history"
 * (bug 11952) Ensure we quote_ident() all schema names as needed
    inside of the DatabasePostgres.php file.
+* (bug 12184) Exceptions now sent to stderr instead of stdout for command-line
+  scripts, making for cleaner reporting during batch jobs. PHP errors will also
+  be redirected in most cases on PHP 5.2.4 and later, switching 'display_errors'
+  to 'stderr' at runtime.
+
 
 == Parser changes in 1.12 ==
 
index 06cadc0..1ae28de 100644 (file)
@@ -94,7 +94,7 @@ class MWException extends Exception
 
        /** Print the exception report using text */
        function reportText() {
-               echo $this->getText();
+               fwrite( STDERR, $this->getText() );
        }
 
        /* Output a report about the exception and takes care of formatting.
@@ -200,7 +200,7 @@ function wfReportException( Exception $e ) {
                         $e2->__toString() . "\n";
 
                         if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {
-                                echo $message;
+                                fwrite( STDERR, $message );
                         } else {
                                 echo nl2br( htmlspecialchars( $message ) ). "\n";
                         }
index ee44954..94fb48c 100644 (file)
@@ -170,7 +170,8 @@ class BackupDumper {
        function dump( $history, $text = MW_EXPORT_TEXT ) {
                # Notice messages will foul up your XML output even if they're
                # relatively harmless.
-               ini_set( 'display_errors', false );
+               if( ini_get( 'display_errors' ) )
+                       ini_set( 'display_errors', 'stderr' );
 
                $this->initProgress( $history );
 
index 4466344..f7bb53f 100644 (file)
@@ -216,6 +216,20 @@ if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
 
 ini_set( 'memory_limit', -1 );
 
+if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
+       // Send PHP warnings and errors to stderr instead of stdout.
+       // This aids in diagnosing problems, while keeping messages
+       // out of redirected output.
+       if( ini_get( 'display_errors' ) ) {
+               ini_set( 'display_errors', 'stderr' );
+       }
+       
+       // Don't touch the setting on earlier versions of PHP,
+       // as setting it would disable output if you'd wanted it.
+       
+       // Note that exceptions are also sent to stderr when
+       // command-line mode is on, regardless of PHP version.
+}
 $wgShowSQLErrors = true;
 
 require_once( "$IP/includes/Setup.php" );
index 827c493..703fa1e 100644 (file)
@@ -118,7 +118,8 @@ class TextPassDumper extends BackupDumper {
 
                # Notice messages will foul up your XML output even if they're
                # relatively harmless.
-//             ini_set( 'display_errors', false );
+               if( ini_get( 'display_errors' ) )
+                       ini_set( 'display_errors', 'stderr' );
 
                $this->initProgress( $this->history );