Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / exception / ErrorPageError.php
blob82d9897fc5eab2b6ba1e85f85b6d91d36efb0807
1 <?php
2 /**
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
18 * @file
21 use MediaWiki\Message\Message;
22 use Wikimedia\Message\MessageSpecifier;
24 /**
25 * An error page which can definitely be safely rendered using the OutputPage.
27 * @newable
28 * @stable to extend
30 * @since 1.7
31 * @ingroup Exception
33 class ErrorPageError extends MWException implements ILocalizedException {
34 public const SEND_OUTPUT = 0;
35 public const STAGE_OUTPUT = 1;
37 /** @var string|MessageSpecifier */
38 public $title;
39 /** @var string|MessageSpecifier */
40 public $msg;
41 public array $params;
43 /**
44 * Note: these arguments are keys into wfMessage(), not text!
46 * @stable to call
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;
54 $this->msg = $msg;
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() );
66 /**
67 * Return a Message object for this exception
68 * @since 1.29
69 * @return Message
71 public function getMessageObject() {
72 if ( $this->msg instanceof Message ) {
73 return clone $this->msg;
75 return wfMessage( $this->msg, $this->params );
78 /**
79 * @stable to override
80 * @param int $action
82 * @throws FatalError
83 * @throws MWException
85 public function report( $action = self::SEND_OUTPUT ) {
86 if ( self::isCommandLine() || defined( 'MW_API' ) ) {
87 MWExceptionRenderer::output( $this, MWExceptionRenderer::AS_PRETTY );
88 } else {
89 global $wgOut;
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 ) {
96 $wgOut->output();