2016-09-14 03:57:54 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
2023-02-16 19:27:21 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2023-08-08 19:30:55 +00:00
|
|
|
use MediaWiki\Language\RawMessage;
|
2022-01-28 19:33:21 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2020-03-14 12:58:53 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-09-07 11:46:15 +00:00
|
|
|
use MediaWiki\Request\WebRequest;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\AtEase;
|
2017-02-24 16:17:16 +00:00
|
|
|
use Wikimedia\Rdbms\DBConnectionError;
|
|
|
|
|
use Wikimedia\Rdbms\DBExpectedError;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\DBReadOnlyError;
|
2021-01-06 05:23:15 +00:00
|
|
|
use Wikimedia\RequestTimeout\RequestTimeoutException;
|
2017-02-24 16:17:16 +00:00
|
|
|
|
2016-09-14 03:57:54 +00:00
|
|
|
/**
|
|
|
|
|
* Class to expose exceptions to the client (API bots, users, admins using CLI scripts)
|
|
|
|
|
* @since 1.28
|
|
|
|
|
*/
|
|
|
|
|
class MWExceptionRenderer {
|
2020-05-12 22:37:45 +00:00
|
|
|
public const AS_RAW = 1; // show as text
|
|
|
|
|
public const AS_PRETTY = 2; // show as HTML
|
2016-09-14 03:57:54 +00:00
|
|
|
|
2022-05-19 12:57:14 +00:00
|
|
|
/**
|
2023-08-08 19:30:55 +00:00
|
|
|
* Whether to print exception details.
|
2022-05-19 12:57:14 +00:00
|
|
|
*
|
|
|
|
|
* The default is configured by $wgShowExceptionDetails.
|
|
|
|
|
* May be changed at runtime via MWExceptionRenderer::setShowExceptionDetails().
|
|
|
|
|
*
|
|
|
|
|
* @see MainConfigNames::ShowExceptionDetails
|
|
|
|
|
*/
|
|
|
|
|
private static $showExceptionDetails = false;
|
2022-01-28 19:33:21 +00:00
|
|
|
|
2022-05-19 12:57:14 +00:00
|
|
|
/**
|
|
|
|
|
* @internal For use within core wiring only.
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function shouldShowExceptionDetails(): bool {
|
|
|
|
|
return self::$showExceptionDetails;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param bool $showDetails
|
|
|
|
|
* @internal For use by Setup.php and other internal use cases.
|
|
|
|
|
*/
|
|
|
|
|
public static function setShowExceptionDetails( bool $showDetails ): void {
|
|
|
|
|
self::$showExceptionDetails = $showDetails;
|
2022-01-28 19:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-14 03:57:54 +00:00
|
|
|
/**
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable $e Original exception
|
2017-08-20 11:20:59 +00:00
|
|
|
* @param int $mode MWExceptionExposer::AS_* constant
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable|null $eNew New throwable from attempting to show the first
|
2016-09-14 03:57:54 +00:00
|
|
|
*/
|
2019-12-29 19:44:43 +00:00
|
|
|
public static function output( Throwable $e, $mode, Throwable $eNew = null ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
$showExceptionDetails = self::shouldShowExceptionDetails();
|
2021-06-09 21:23:37 +00:00
|
|
|
if ( $e instanceof RequestTimeoutException && headers_sent() ) {
|
|
|
|
|
// Excimer's flag check happens on function return, so, a timeout
|
|
|
|
|
// can be thrown after exiting, say, `doPostOutputShutdown`, where
|
|
|
|
|
// headers are sent. In which case, it's probably fine not to
|
|
|
|
|
// report this in any user visible way. The general question of
|
|
|
|
|
// what to do about reporting an exception when headers have been
|
|
|
|
|
// sent is still unclear, but you probably don't want to
|
|
|
|
|
// `useOutputPage`.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 07:27:30 +00:00
|
|
|
if ( function_exists( 'apache_setenv' ) ) {
|
|
|
|
|
// The client should not be blocked on "post-send" updates. If apache decides that
|
|
|
|
|
// a response should be gzipped, it will wait for PHP to finish since it cannot gzip
|
|
|
|
|
// anything until it has the full response (even with "Transfer-Encoding: chunked").
|
|
|
|
|
AtEase\AtEase::suppressWarnings();
|
|
|
|
|
apache_setenv( 'no-gzip', '1' );
|
|
|
|
|
AtEase\AtEase::restoreWarnings();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 03:57:54 +00:00
|
|
|
if ( defined( 'MW_API' ) ) {
|
|
|
|
|
self::header( 'MediaWiki-API-Error: internal_api_error_' . get_class( $e ) );
|
2020-03-25 16:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( self::isCommandLine() ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
self::printError( self::getText( $e ) );
|
|
|
|
|
} elseif ( $mode === self::AS_PRETTY ) {
|
2017-04-16 19:26:13 +00:00
|
|
|
self::statusHeader( 500 );
|
2019-09-20 07:27:30 +00:00
|
|
|
ob_start();
|
2016-09-30 23:57:38 +00:00
|
|
|
if ( $e instanceof DBConnectionError ) {
|
|
|
|
|
self::reportOutageHTML( $e );
|
|
|
|
|
} else {
|
|
|
|
|
self::reportHTML( $e );
|
|
|
|
|
}
|
2019-09-20 07:27:30 +00:00
|
|
|
self::header( "Content-Length: " . ob_get_length() );
|
|
|
|
|
ob_end_flush();
|
2016-09-14 03:57:54 +00:00
|
|
|
} else {
|
2019-09-20 07:27:30 +00:00
|
|
|
ob_start();
|
2018-05-24 20:23:26 +00:00
|
|
|
self::statusHeader( 500 );
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
self::header( 'Content-Type: text/html; charset=UTF-8' );
|
2016-09-14 03:57:54 +00:00
|
|
|
if ( $eNew ) {
|
|
|
|
|
$message = "MediaWiki internal error.\n\n";
|
2022-01-28 19:33:21 +00:00
|
|
|
if ( $showExceptionDetails ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
$message .= 'Original exception: ' .
|
|
|
|
|
MWExceptionHandler::getLogMessage( $e ) .
|
|
|
|
|
"\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) .
|
|
|
|
|
"\n\nException caught inside exception handler: " .
|
|
|
|
|
MWExceptionHandler::getLogMessage( $eNew ) .
|
|
|
|
|
"\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
|
|
|
|
|
} else {
|
2016-11-21 21:40:18 +00:00
|
|
|
$message .= 'Original exception: ' .
|
|
|
|
|
MWExceptionHandler::getPublicLogMessage( $e );
|
|
|
|
|
$message .= "\n\nException caught inside exception handler.\n\n" .
|
2023-02-05 19:21:50 +00:00
|
|
|
self::getShowBacktraceError();
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
$message .= "\n";
|
2022-01-28 19:33:21 +00:00
|
|
|
} elseif ( $showExceptionDetails ) {
|
2019-03-29 20:12:24 +00:00
|
|
|
$message = MWExceptionHandler::getLogMessage( $e ) .
|
|
|
|
|
"\nBacktrace:\n" .
|
|
|
|
|
MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n";
|
2016-09-14 03:57:54 +00:00
|
|
|
} else {
|
2019-03-29 20:12:24 +00:00
|
|
|
$message = MWExceptionHandler::getPublicLogMessage( $e );
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
2019-09-20 07:27:30 +00:00
|
|
|
print nl2br( htmlspecialchars( $message ) ) . "\n";
|
|
|
|
|
self::header( "Content-Length: " . ob_get_length() );
|
|
|
|
|
ob_end_flush();
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable $e
|
|
|
|
|
* @return bool Should the throwable use $wgOut to output the error?
|
2016-09-14 03:57:54 +00:00
|
|
|
*/
|
2019-12-29 19:44:43 +00:00
|
|
|
private static function useOutputPage( Throwable $e ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
// Can the exception use the Message class/wfMessage to get i18n-ed messages?
|
2016-09-14 03:57:54 +00:00
|
|
|
foreach ( $e->getTrace() as $frame ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
if ( isset( $frame['class'] ) && $frame['class'] === LocalisationCache::class ) {
|
2016-09-14 09:28:18 +00:00
|
|
|
return false;
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 00:26:05 +00:00
|
|
|
// Don't even bother with OutputPage if there's no Title context set,
|
|
|
|
|
// (e.g. we're in RL code on load.php) - the Skin system (and probably
|
|
|
|
|
// most of MediaWiki) won't work.
|
2016-09-14 03:57:54 +00:00
|
|
|
return (
|
|
|
|
|
!empty( $GLOBALS['wgFullyInitialised'] ) &&
|
|
|
|
|
!empty( $GLOBALS['wgOut'] ) &&
|
2016-09-27 00:26:05 +00:00
|
|
|
RequestContext::getMain()->getTitle() &&
|
2020-03-25 16:52:48 +00:00
|
|
|
!defined( 'MEDIAWIKI_INSTALL' ) &&
|
|
|
|
|
// Don't send a skinned HTTP 500 page to API clients.
|
2023-03-05 19:49:12 +00:00
|
|
|
!defined( 'MW_API' ) &&
|
|
|
|
|
!defined( 'MW_REST_API' )
|
2016-09-14 03:57:54 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-29 19:44:43 +00:00
|
|
|
* Output the throwable report using HTML
|
2016-09-14 03:57:54 +00:00
|
|
|
*
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable $e
|
2016-09-14 03:57:54 +00:00
|
|
|
*/
|
2019-12-29 19:44:43 +00:00
|
|
|
private static function reportHTML( Throwable $e ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
if ( self::useOutputPage( $e ) ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
$out = RequestContext::getMain()->getOutput();
|
2023-08-08 19:30:55 +00:00
|
|
|
$out->prepareErrorPage();
|
|
|
|
|
$out->setPageTitleMsg( self::getExceptionTitle( $e ) );
|
2016-09-14 03:57:54 +00:00
|
|
|
|
2017-05-21 08:29:41 +00:00
|
|
|
// Show any custom GUI message before the details
|
2021-01-06 05:23:15 +00:00
|
|
|
$customMessage = self::getCustomMessage( $e );
|
|
|
|
|
if ( $customMessage !== null ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
$out->addHTML( Html::element( 'p', [], $customMessage ) );
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
2022-01-28 19:33:21 +00:00
|
|
|
$out->addHTML( self::getHTML( $e ) );
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
// Content-Type is set by OutputPage::output
|
2022-01-28 19:33:21 +00:00
|
|
|
$out->output();
|
2016-09-14 03:57:54 +00:00
|
|
|
} else {
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
self::header( 'Content-Type: text/html; charset=UTF-8' );
|
2016-09-14 03:57:54 +00:00
|
|
|
$pageTitle = self::msg( 'internalerror', 'Internal error' );
|
|
|
|
|
echo "<!DOCTYPE html>\n" .
|
|
|
|
|
'<html><head>' .
|
2022-01-09 17:30:20 +00:00
|
|
|
// Mimic OutputPage::setPageTitle behaviour
|
2016-09-14 03:57:54 +00:00
|
|
|
'<title>' .
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
htmlspecialchars( self::msg( 'pagetitle', '$1 - MediaWiki', $pageTitle ) ) .
|
2016-09-14 03:57:54 +00:00
|
|
|
'</title>' .
|
2024-06-09 11:21:45 +00:00
|
|
|
'<meta name="color-scheme" content="light dark" />' .
|
2016-09-14 03:57:54 +00:00
|
|
|
'<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
|
|
|
|
|
"</head><body>\n";
|
|
|
|
|
|
2017-05-21 08:29:41 +00:00
|
|
|
echo self::getHTML( $e );
|
2016-09-14 03:57:54 +00:00
|
|
|
|
|
|
|
|
echo "</body></html>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-05-19 12:57:14 +00:00
|
|
|
* Format an HTML message for the given exception object.
|
2016-09-14 03:57:54 +00:00
|
|
|
*
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable $e
|
2016-09-14 03:57:54 +00:00
|
|
|
* @return string Html to output
|
|
|
|
|
*/
|
2019-12-29 19:44:43 +00:00
|
|
|
public static function getHTML( Throwable $e ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
if ( self::shouldShowExceptionDetails() ) {
|
2022-01-27 23:46:49 +00:00
|
|
|
$html = Html::errorBox( "<p>" .
|
2016-09-14 03:57:54 +00:00
|
|
|
nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) .
|
|
|
|
|
'</p><p>Backtrace:</p><p>' .
|
|
|
|
|
nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $e ) ) ) .
|
2022-01-27 23:46:49 +00:00
|
|
|
"</p>\n",
|
|
|
|
|
'',
|
|
|
|
|
'mw-content-ltr'
|
|
|
|
|
);
|
2016-09-14 03:57:54 +00:00
|
|
|
} else {
|
|
|
|
|
$logId = WebRequest::getRequestId();
|
2022-01-27 23:46:49 +00:00
|
|
|
$html = Html::errorBox(
|
2017-10-18 05:28:43 +00:00
|
|
|
htmlspecialchars(
|
|
|
|
|
'[' . $logId . '] ' .
|
|
|
|
|
gmdate( 'Y-m-d H:i:s' ) . ": " .
|
|
|
|
|
self::msg( "internalerror-fatal-exception",
|
|
|
|
|
"Fatal exception of type $1",
|
|
|
|
|
get_class( $e ),
|
|
|
|
|
$logId,
|
|
|
|
|
MWExceptionHandler::getURL()
|
2022-01-27 23:46:49 +00:00
|
|
|
) ),
|
|
|
|
|
'',
|
|
|
|
|
'mw-content-ltr'
|
2023-02-05 19:21:50 +00:00
|
|
|
) . "<!-- " . wordwrap( self::getShowBacktraceError(), 50 ) . " -->";
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
2016-09-14 09:28:18 +00:00
|
|
|
|
|
|
|
|
return $html;
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-08 19:30:55 +00:00
|
|
|
* Get a message string from i18n
|
2016-09-14 03:57:54 +00:00
|
|
|
*
|
|
|
|
|
* @param string $key Message name
|
|
|
|
|
* @param string $fallback Default message if the message cache can't be
|
|
|
|
|
* called by the exception
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
* @param mixed ...$params To pass to wfMessage()
|
2016-09-14 03:57:54 +00:00
|
|
|
* @return string Message with arguments replaced
|
|
|
|
|
*/
|
2023-08-08 19:30:55 +00:00
|
|
|
public static function msg( $key, $fallback, ...$params ) {
|
|
|
|
|
// NOTE: Keep logic in sync with MWException::msg
|
|
|
|
|
$res = self::msgObj( $key, $fallback, ...$params )->text();
|
|
|
|
|
return strtr( $res, [
|
|
|
|
|
'{{SITENAME}}' => 'MediaWiki',
|
|
|
|
|
] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get a Message object from i18n.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key Message name
|
|
|
|
|
* @param string $fallback Default message if the message cache can't be
|
|
|
|
|
* called by the exception
|
|
|
|
|
* @param mixed ...$params To pass to wfMessage()
|
|
|
|
|
* @return Message|RawMessage
|
|
|
|
|
*/
|
|
|
|
|
private static function msgObj( string $key, string $fallback, ...$params ): Message {
|
2022-01-28 19:33:21 +00:00
|
|
|
// NOTE: Keep logic in sync with MWException::msg.
|
2016-09-14 03:57:54 +00:00
|
|
|
try {
|
2023-08-08 19:30:55 +00:00
|
|
|
$res = wfMessage( $key, ...$params );
|
2016-09-14 03:57:54 +00:00
|
|
|
} catch ( Exception $e ) {
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
// Fallback to static message text and generic sitename.
|
|
|
|
|
// Avoid live config as this must work before Setup/MediaWikiServices finish.
|
2023-08-08 19:30:55 +00:00
|
|
|
$res = new RawMessage( $fallback, $params );
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
2016-11-22 22:35:02 +00:00
|
|
|
// We are in an error state, best to minimize how much work we do.
|
|
|
|
|
$res->useDatabase( false );
|
|
|
|
|
$isSafeToLoad = RequestContext::getMain()->getUser()->isSafeToLoad();
|
|
|
|
|
if ( !$isSafeToLoad ) {
|
|
|
|
|
$res->inContentLanguage();
|
|
|
|
|
}
|
2017-10-18 06:27:12 +00:00
|
|
|
return $res;
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable $e
|
2016-09-14 03:57:54 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2019-12-29 19:44:43 +00:00
|
|
|
private static function getText( Throwable $e ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
// XXX: do we need a parameter to control inclusion of exception details?
|
|
|
|
|
if ( self::shouldShowExceptionDetails() ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
return MWExceptionHandler::getLogMessage( $e ) .
|
|
|
|
|
"\nBacktrace:\n" .
|
|
|
|
|
MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n";
|
|
|
|
|
} else {
|
2023-02-05 19:21:50 +00:00
|
|
|
return self::getShowBacktraceError() . "\n";
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 21:32:30 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-02-05 19:21:50 +00:00
|
|
|
private static function getShowBacktraceError() {
|
2018-07-17 16:51:36 +00:00
|
|
|
$var = '$wgShowExceptionDetails = true;';
|
|
|
|
|
return "Set $var at the bottom of LocalSettings.php to show detailed debugging information.";
|
2016-11-21 21:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-06 05:23:15 +00:00
|
|
|
/**
|
|
|
|
|
* Get the page title to be used for a given exception.
|
|
|
|
|
*
|
|
|
|
|
* @param Throwable $e
|
2023-08-08 19:30:55 +00:00
|
|
|
* @return Message
|
2021-01-06 05:23:15 +00:00
|
|
|
*/
|
2023-08-08 19:30:55 +00:00
|
|
|
private static function getExceptionTitle( Throwable $e ): Message {
|
2023-12-14 16:48:29 +00:00
|
|
|
if ( $e instanceof DBReadOnlyError ) {
|
2023-08-08 19:30:55 +00:00
|
|
|
return self::msgObj( 'readonly', 'Database is locked' );
|
2021-01-06 05:23:15 +00:00
|
|
|
} elseif ( $e instanceof DBExpectedError ) {
|
2023-08-08 19:30:55 +00:00
|
|
|
return self::msgObj( 'databaseerror', 'Database error' );
|
2021-01-06 05:23:15 +00:00
|
|
|
} elseif ( $e instanceof RequestTimeoutException ) {
|
2023-08-08 19:30:55 +00:00
|
|
|
return self::msgObj( 'timeouterror', 'Request timeout' );
|
2021-01-06 05:23:15 +00:00
|
|
|
} else {
|
2023-08-08 19:30:55 +00:00
|
|
|
return self::msgObj( 'internalerror', 'Internal error' );
|
2021-01-06 05:23:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract an additional user-visible message from an exception, or null if
|
|
|
|
|
* it has none.
|
|
|
|
|
*
|
|
|
|
|
* @param Throwable $e
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
private static function getCustomMessage( Throwable $e ) {
|
|
|
|
|
try {
|
|
|
|
|
if ( $e instanceof MessageSpecifier ) {
|
|
|
|
|
$msg = Message::newFromSpecifier( $e );
|
|
|
|
|
} elseif ( $e instanceof RequestTimeoutException ) {
|
|
|
|
|
$msg = wfMessage( 'timeouterror-text', $e->getLimit() );
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$text = $msg->text();
|
|
|
|
|
} catch ( Exception $e2 ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 03:57:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private static function isCommandLine() {
|
2023-12-14 17:29:35 +00:00
|
|
|
return MW_ENTRY_POINT === 'cli';
|
2016-09-14 03:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $header
|
|
|
|
|
*/
|
|
|
|
|
private static function header( $header ) {
|
|
|
|
|
if ( !headers_sent() ) {
|
|
|
|
|
header( $header );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-20 11:20:59 +00:00
|
|
|
* @param int $code
|
2016-09-14 03:57:54 +00:00
|
|
|
*/
|
|
|
|
|
private static function statusHeader( $code ) {
|
|
|
|
|
if ( !headers_sent() ) {
|
|
|
|
|
HttpStatus::header( $code );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print a message, if possible to STDERR.
|
|
|
|
|
* Use this in command line mode only (see isCommandLine)
|
|
|
|
|
*
|
2019-02-17 11:36:13 +00:00
|
|
|
* @suppress SecurityCheck-XSS
|
2016-09-14 03:57:54 +00:00
|
|
|
* @param string $message Failure text
|
|
|
|
|
*/
|
|
|
|
|
private static function printError( $message ) {
|
|
|
|
|
// NOTE: STDERR may not be available, especially if php-cgi is used from the
|
2018-10-04 07:06:00 +00:00
|
|
|
// command line (T17602). Try to produce meaningful output anyway. Using
|
2016-09-14 03:57:54 +00:00
|
|
|
// echo may corrupt output to STDOUT though.
|
2023-12-14 16:28:48 +00:00
|
|
|
if ( !defined( 'MW_PHPUNIT_TEST' ) && defined( 'STDERR' ) ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
fwrite( STDERR, $message );
|
|
|
|
|
} else {
|
|
|
|
|
echo $message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-29 19:44:43 +00:00
|
|
|
* @param Throwable $e
|
2016-09-14 03:57:54 +00:00
|
|
|
*/
|
2019-12-29 19:44:43 +00:00
|
|
|
private static function reportOutageHTML( Throwable $e ) {
|
2022-01-28 19:33:21 +00:00
|
|
|
$mainConfig = MediaWikiServices::getInstance()->getMainConfig();
|
2022-08-17 19:27:48 +00:00
|
|
|
$showExceptionDetails = $mainConfig->get( MainConfigNames::ShowExceptionDetails );
|
|
|
|
|
$showHostnames = $mainConfig->get( MainConfigNames::ShowHostnames );
|
2016-09-14 03:57:54 +00:00
|
|
|
$sorry = htmlspecialchars( self::msg(
|
|
|
|
|
'dberr-problems',
|
|
|
|
|
'Sorry! This site is experiencing technical difficulties.'
|
|
|
|
|
) );
|
|
|
|
|
$again = htmlspecialchars( self::msg(
|
|
|
|
|
'dberr-again',
|
|
|
|
|
'Try waiting a few minutes and reloading.'
|
|
|
|
|
) );
|
|
|
|
|
|
2022-01-28 19:33:21 +00:00
|
|
|
if ( $showHostnames ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
$info = str_replace(
|
|
|
|
|
'$1',
|
2017-07-03 07:13:09 +00:00
|
|
|
Html::element( 'span', [ 'dir' => 'ltr' ], $e->getMessage() ),
|
2016-09-14 03:57:54 +00:00
|
|
|
htmlspecialchars( self::msg( 'dberr-info', '($1)' ) )
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$info = htmlspecialchars( self::msg(
|
|
|
|
|
'dberr-info-hidden',
|
|
|
|
|
'(Cannot access the database)'
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-14 12:58:53 +00:00
|
|
|
MediaWikiServices::getInstance()->getMessageCache()->disable(); // no DB access
|
2018-05-24 20:23:26 +00:00
|
|
|
$html = "<!DOCTYPE html>\n" .
|
|
|
|
|
'<html><head>' .
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
'<title>MediaWiki</title>' .
|
2024-06-09 11:21:45 +00:00
|
|
|
'<meta name="color-scheme" content="light dark" />' .
|
2018-05-24 20:23:26 +00:00
|
|
|
'<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
|
|
|
|
|
"</head><body><h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
|
2016-09-14 03:57:54 +00:00
|
|
|
|
2022-01-28 19:33:21 +00:00
|
|
|
if ( $showExceptionDetails ) {
|
2016-09-14 03:57:54 +00:00
|
|
|
$html .= '<p>Backtrace:</p><pre>' .
|
|
|
|
|
htmlspecialchars( $e->getTraceAsString() ) . '</pre>';
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 20:23:26 +00:00
|
|
|
$html .= '</body></html>';
|
exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.
These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.
== Remove use of $wgSitename ==
In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.
Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.
Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".
Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.
== Remove use of $wgMimeType ==
In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.
This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.
Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.
Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-12 23:05:34 +00:00
|
|
|
self::header( 'Content-Type: text/html; charset=UTF-8' );
|
2016-09-14 03:57:54 +00:00
|
|
|
echo $html;
|
|
|
|
|
}
|
|
|
|
|
}
|