Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.31% |
12 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
UserBlockedError | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
4 |
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 | namespace MediaWiki\Exception; |
22 | |
23 | use MediaWiki\Block\Block; |
24 | use MediaWiki\Context\RequestContext; |
25 | use MediaWiki\Language\RawMessage; |
26 | use MediaWiki\MediaWikiServices; |
27 | use MediaWiki\User\UserIdentity; |
28 | |
29 | /** |
30 | * Show an error when the user tries to do something whilst blocked. |
31 | * |
32 | * @newable |
33 | * @since 1.18 |
34 | * @ingroup Exception |
35 | */ |
36 | class UserBlockedError extends ErrorPageError { |
37 | /** |
38 | * @stable to call |
39 | * @param Block $block |
40 | * @param UserIdentity|null $user |
41 | * @param mixed $language Unused since 1.42 |
42 | * @param string|null $ip |
43 | */ |
44 | public function __construct( |
45 | Block $block, |
46 | ?UserIdentity $user = null, |
47 | $language = null, |
48 | $ip = null |
49 | ) { |
50 | $context = RequestContext::getMain(); |
51 | if ( $user === null || $ip === null ) { |
52 | // If any of these are not passed in, use the global context |
53 | $user = $context->getUser(); |
54 | $ip = $context->getRequest()->getIP(); |
55 | } |
56 | |
57 | // @todo This should be passed in via the constructor |
58 | $messages = MediaWikiServices::getInstance()->getFormatterFactory() |
59 | ->getBlockErrorFormatter( $context ) |
60 | ->getMessages( $block, $user, $ip ); |
61 | |
62 | if ( count( $messages ) === 1 ) { |
63 | $message = $messages[0]; |
64 | } else { |
65 | $message = new RawMessage( '* $' . implode( "\n* \$", range( 1, count( $messages ) ) ) ); |
66 | $message->params( $messages )->parse(); |
67 | } |
68 | |
69 | parent::__construct( 'blockedtitle', $message ); |
70 | } |
71 | } |
72 | |
73 | /** @deprecated class alias since 1.44 */ |
74 | class_alias( UserBlockedError::class, 'UserBlockedError' ); |