From 8ee834c376baddce4793f549ff008b6f045c7ccd Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 7 Jul 2016 16:58:52 -0400 Subject: [PATCH] AFPUserVisibleException should log in English, not the user's language The user's language should only be used when the exception is actually displayed to the user. This will also avoid "User::loadFromSession called before the end of Setup.php" warnings when the syntax error is encountered during filter execution for account autocreation, where we don't display it to the user. Bug: T124367 Change-Id: Ic17f56aecbe575ef15c6970c4298f889249e1904 --- AbuseFilter.parser.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/AbuseFilter.parser.php b/AbuseFilter.parser.php index f5c4f1f80..110c9b6af 100644 --- a/AbuseFilter.parser.php +++ b/AbuseFilter.parser.php @@ -536,12 +536,26 @@ class AFPException extends MWException { // Exceptions that we might conceivably want to report to ordinary users // (i.e. exceptions that don't represent bugs in the extension itself) class AFPUserVisibleException extends AFPException { + public $mExceptionId; + public $mPosition; + public $mParams; + /** * @param string $exception_id * @param int $position * @param array $params */ function __construct( $exception_id, $position, $params ) { + $this->mExceptionID = $exception_id; + $this->mPosition = $position; + $this->mParams = $params; + + // Exception message text for logs should be in English. + $msg = $this->getMessageObj()->inLanguage( 'en' )->useDatabase( false )->text(); + parent::__construct( $msg ); + } + + public function getMessageObj() { // Give grep a chance to find the usages: // abusefilter-exception-unexpectedatend, abusefilter-exception-expectednotfound // abusefilter-exception-unrecognisedkeyword, abusefilter-exception-unexpectedtoken @@ -551,15 +565,10 @@ class AFPUserVisibleException extends AFPException { // abusefilter-exception-notenoughargs, abusefilter-exception-regexfailure // abusefilter-exception-overridebuiltin, abusefilter-exception-outofbounds // abusefilter-exception-notlist - $msg = wfMessage( - 'abusefilter-exception-' . $exception_id, - array_merge( array( $position ), $params ) - )->text(); - parent::__construct( $msg ); - - $this->mExceptionID = $exception_id; - $this->mPosition = $position; - $this->mParams = $params; + return wfMessage( + 'abusefilter-exception-' . $this->mExceptionID, + array_merge( array( $this->mPosition ), $this->mParams ) + ); } } @@ -646,7 +655,7 @@ class AbuseFilterParser { } catch ( AFPUserVisibleException $excep ) { $this->mAllowShort = $origAS; - return array( $excep->getMessage(), $excep->mPosition ); + return array( $excep->getMessageObj()->text(), $excep->mPosition ); } $this->mAllowShort = $origAS;