Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/338911 )

Change subject: Make it possible to not propagate errors to PHP
......................................................................

Make it possible to not propagate errors to PHP

Add a $wgPropagateErrors configuration variable which can be used
to prevent passing handled errors to PHP (and thus logging them twice).

Bug: T45086
Change-Id: I64ab09762a04de2007b7d7864e3c504a1d6f8aee
---
M includes/DefaultSettings.php
M includes/exception/MWExceptionHandler.php
2 files changed, 12 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/11/338911/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 791d024..6575ea3 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6223,6 +6223,12 @@
 $wgLogExceptionBacktrace = true;
 
 /**
+ * If true, the MediaWiki error handler passes errors/warnings to the default 
error handler
+ * after logging them. The setting is ignored when the track_errors php.ini 
flag is true.
+ */
+$wgPropagateErrors = true;
+
+/**
  * Expose backend server host names through the API and various HTML comments
  */
 $wgShowHostnames = false;
diff --git a/includes/exception/MWExceptionHandler.php 
b/includes/exception/MWExceptionHandler.php
index eb4c95e..3996239 100644
--- a/includes/exception/MWExceptionHandler.php
+++ b/includes/exception/MWExceptionHandler.php
@@ -164,6 +164,8 @@
        public static function handleError(
                $level, $message, $file = null, $line = null
        ) {
+               global $wgPropagateErrors;
+
                if ( in_array( $level, self::$fatalErrorTypes ) ) {
                        return call_user_func_array(
                                'MWExceptionHandler::handleFatalError', 
func_get_args()
@@ -207,9 +209,10 @@
                $e = new ErrorException( "PHP $levelName: $message", 0, $level, 
$file, $line );
                self::logError( $e, 'error', $severity );
 
-               // This handler is for logging only. Return false will instruct 
PHP
-               // to continue regular handling.
-               return false;
+               // If $wgPropagateErrors is true return false so PHP shows/logs 
the error normally.
+               // Ignore $wgPropagateErrors if the error should break 
execution, or track_errors is set
+               // (which means someone is counting on regular PHP error 
handling behavior).
+               return !( $wgPropagateErrors || $level == E_RECOVERABLE_ERROR 
|| ini_get( 'track_errors' ) );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/338911
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I64ab09762a04de2007b7d7864e3c504a1d6f8aee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to