global $wgLang;
foreach ( $this->getTrace() as $frame ) {
- if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) {
+ if ( isset( $frame['class'] ) && $frame['class'] === LocalisationCache::class ) {
return false;
}
}
* @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 = strtr( $res, [
+ '{{SITENAME}}' => $wgSitename,
+ ] );
+ }
+ return $res;
}
/**
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() );
} 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;