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 | /** |
22 | * An error page which can definitely be safely rendered using the OutputPage. |
23 | * |
24 | * @newable |
25 | * @stable to extend |
26 | * |
27 | * @since 1.7 |
28 | * @ingroup Exception |
29 | */ |
30 | class ErrorPageError extends MWException implements ILocalizedException { |
31 | public const SEND_OUTPUT = 0; |
32 | public const STAGE_OUTPUT = 1; |
33 | public $title, $msg, $params; |
34 | |
35 | /** |
36 | * Note: these arguments are keys into wfMessage(), not text! |
37 | * |
38 | * @stable to call |
39 | * |
40 | * @param string|MessageSpecifier $title Message key (string) for page title, or a MessageSpecifier |
41 | * @param string|MessageSpecifier $msg Message key (string) for error text, or a MessageSpecifier |
42 | * @param array $params Array with parameters to wfMessage() |
43 | */ |
44 | public function __construct( $title, $msg, $params = [] ) { |
45 | $this->title = $title; |
46 | $this->msg = $msg; |
47 | $this->params = $params; |
48 | |
49 | // T46111: Messages in the log files should be in English and not |
50 | // customized by the local wiki. So get the default English version for |
51 | // passing to the parent constructor. Our overridden report() below |
52 | // makes sure that the page shown to the user is not forced to English. |
53 | $enMsg = $this->getMessageObject(); |
54 | $enMsg->inLanguage( 'en' )->useDatabase( false ); |
55 | parent::__construct( $enMsg->text() ); |
56 | } |
57 | |
58 | /** |
59 | * Return a Message object for this exception |
60 | * @since 1.29 |
61 | * @return Message |
62 | */ |
63 | public function getMessageObject() { |
64 | if ( $this->msg instanceof Message ) { |
65 | return clone $this->msg; |
66 | } |
67 | return wfMessage( $this->msg, $this->params ); |
68 | } |
69 | |
70 | /** |
71 | * @stable to override |
72 | * @param int $action |
73 | * |
74 | * @throws FatalError |
75 | * @throws MWException |
76 | */ |
77 | public function report( $action = self::SEND_OUTPUT ) { |
78 | if ( self::isCommandLine() || defined( 'MW_API' ) ) { |
79 | MWExceptionRenderer::output( $this, MWExceptionRenderer::AS_PRETTY ); |
80 | } else { |
81 | global $wgOut; |
82 | $wgOut->showErrorPage( $this->title, $this->msg, $this->params ); |
83 | // Allow skipping of the final output step, so that web-based page views |
84 | // from MediaWiki.php, can inspect the staged OutputPage state, and perform |
85 | // graceful shutdown via prepareForOutput() first, just like for regular |
86 | // output when there isn't an error page. |
87 | if ( $action === self::SEND_OUTPUT ) { |
88 | $wgOut->output(); |
89 | } |
90 | } |
91 | } |
92 | } |