3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\Message\Message
;
22 use Wikimedia\Message\MessageSpecifier
;
25 * An error page which can definitely be safely rendered using the OutputPage.
33 class ErrorPageError
extends MWException
implements ILocalizedException
{
34 public const SEND_OUTPUT
= 0;
35 public const STAGE_OUTPUT
= 1;
37 /** @var string|MessageSpecifier */
39 /** @var string|MessageSpecifier */
44 * Note: these arguments are keys into wfMessage(), not text!
48 * @param string|MessageSpecifier $title Message key (string) for page title, or a MessageSpecifier
49 * @param string|MessageSpecifier $msg Message key (string) for error text, or a MessageSpecifier
50 * @param array $params Array with parameters to wfMessage()
52 public function __construct( $title, $msg, $params = [] ) {
53 $this->title
= $title;
55 $this->params
= $params;
57 // T46111: Messages in the log files should be in English and not
58 // customized by the local wiki. So get the default English version for
59 // passing to the parent constructor. Our overridden report() below
60 // makes sure that the page shown to the user is not forced to English.
61 $enMsg = $this->getMessageObject();
62 $enMsg->inLanguage( 'en' )->useDatabase( false );
63 parent
::__construct( $enMsg->text() );
67 * Return a Message object for this exception
71 public function getMessageObject() {
72 if ( $this->msg
instanceof Message
) {
73 return clone $this->msg
;
75 return wfMessage( $this->msg
, $this->params
);
85 public function report( $action = self
::SEND_OUTPUT
) {
86 if ( self
::isCommandLine() ||
defined( 'MW_API' ) ) {
87 MWExceptionRenderer
::output( $this, MWExceptionRenderer
::AS_PRETTY
);
90 $wgOut->showErrorPage( $this->title
, $this->msg
, $this->params
);
91 // Allow skipping of the final output step, so that web-based page views
92 // from MediaWiki.php, can inspect the staged OutputPage state, and perform
93 // graceful shutdown via prepareForOutput() first, just like for regular
94 // output when there isn't an error page.
95 if ( $action === self
::SEND_OUTPUT
) {