X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fexception%2FMWException.php;h=652a87dcfcd303473c732efc23c09066c743cf9d;hb=b7625d63a6f1f8867c911dbd6e93eebdaca3312f;hp=6d95919a87cbf0ecd52b15a0edcdba952cca9218;hpb=6f680554ceb988f3895184167d5006d722a0afb3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 6d95919a87..652a87dcfc 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -55,7 +55,7 @@ class MWException extends Exception { global $wgLang; foreach ( $this->getTrace() as $frame ) { - if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) { + if ( isset( $frame['class'] ) && $frame['class'] === LocalisationCache::class ) { return false; } } @@ -73,15 +73,23 @@ class MWException extends Exception { * @return string Message with arguments replaced */ public function msg( $key, $fallback /*[, params...] */ ) { + global $wgSitename; $args = array_slice( func_get_args(), 2 ); + $res = false; if ( $this->useMessageCache() ) { try { - return wfMessage( $key, $args )->text(); + $res = wfMessage( $key, $args )->text(); } catch ( Exception $e ) { } } - return wfMsgReplaceArgs( $fallback, $args ); + if ( $res === false ) { + $res = wfMsgReplaceArgs( $fallback, $args ); + // If an exception happens inside message rendering, + // {{SITENAME}} sometimes won't be replaced. + $res = preg_replace( '/\{\{SITENAME\}\}/', $wgSitename, $res ); + } + return $res; } /** @@ -154,6 +162,16 @@ class MWException extends Exception { global $wgOut, $wgSitename; if ( $this->useOutputPage() ) { $wgOut->prepareErrorPage( $this->getPageTitle() ); + // Manually set the html title, since sometimes + // {{SITENAME}} does not get replaced for exceptions + // happening inside message rendering. + $wgOut->setHTMLTitle( + $this->msg( + 'pagetitle', + "$1 - $wgSitename", + $this->getPageTitle() + ) + ); $wgOut->addHTML( $this->getHTML() ); @@ -189,7 +207,7 @@ class MWException extends Exception { } elseif ( self::isCommandLine() ) { $message = $this->getText(); // T17602: STDERR may not be available - if ( defined( 'STDERR' ) ) { + if ( !defined( 'MW_PHPUNIT_TEST' ) && defined( 'STDERR' ) ) { fwrite( STDERR, $message ); } else { echo $message;