Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ErrorPageError | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getMessageObject | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
report | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 |
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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\Message\Message; |
22 | use Wikimedia\Message\MessageSpecifier; |
23 | |
24 | /** |
25 | * An error page which can definitely be safely rendered using the OutputPage. |
26 | * |
27 | * @newable |
28 | * @stable to extend |
29 | * |
30 | * @since 1.7 |
31 | * @ingroup Exception |
32 | */ |
33 | class ErrorPageError extends MWException implements ILocalizedException { |
34 | public const SEND_OUTPUT = 0; |
35 | public const STAGE_OUTPUT = 1; |
36 | |
37 | /** @var string|MessageSpecifier */ |
38 | public $title; |
39 | /** @var string|MessageSpecifier */ |
40 | public $msg; |
41 | public array $params; |
42 | |
43 | /** |
44 | * Note: these arguments are keys into wfMessage(), not text! |
45 | * |
46 | * @stable to call |
47 | * |
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() |
51 | */ |
52 | public function __construct( $title, $msg, $params = [] ) { |
53 | $this->title = $title; |
54 | $this->msg = $msg; |
55 | $this->params = $params; |
56 | |
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() ); |
64 | } |
65 | |
66 | /** |
67 | * Return a Message object for this exception |
68 | * @since 1.29 |
69 | * @return Message |
70 | */ |
71 | public function getMessageObject() { |
72 | if ( $this->msg instanceof Message ) { |
73 | return clone $this->msg; |
74 | } |
75 | return wfMessage( $this->msg, $this->params ); |
76 | } |
77 | |
78 | /** |
79 | * @stable to override |
80 | * @param int $action |
81 | * |
82 | * @throws FatalError |
83 | * @throws MWException |
84 | */ |
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(); |
97 | } |
98 | } |
99 | } |
100 | } |