From: jenkins-bot Date: Thu, 13 Sep 2018 03:34:52 +0000 (+0000) Subject: Merge "Fix html for exceptions during message parsing." X-Git-Tag: 1.34.0-rc.0~4102 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=32d29b4a681048009d9ce2f986a6ad737b07cc94;hp=8de3eb4c3eab680aa5d2d087380b334b4d627016 Merge "Fix html <title> for exceptions during message parsing." --- diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index b3e9422b8d..652a87dcfc 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -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() ); diff --git a/includes/exception/MWExceptionRenderer.php b/includes/exception/MWExceptionRenderer.php index 49cf71e624..1f1cabeae1 100644 --- a/includes/exception/MWExceptionRenderer.php +++ b/includes/exception/MWExceptionRenderer.php @@ -197,12 +197,17 @@ class MWExceptionRenderer { * @return string Message with arguments replaced */ private static function msg( $key, $fallback /*[, params...] */ ) { + global $wgSitename; $args = array_slice( func_get_args(), 2 ); try { - return wfMessage( $key, $args )->text(); + $res = wfMessage( $key, $args )->text(); } catch ( Exception $e ) { - return wfMsgReplaceArgs( $fallback, $args ); + $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; } /**