Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / exception / UserBlockedError.php
blobf5cd7499975a145de2927ba4e2295161ae338ead
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\Block\Block;
22 use MediaWiki\Context\RequestContext;
23 use MediaWiki\Language\RawMessage;
24 use MediaWiki\MediaWikiServices;
25 use MediaWiki\User\UserIdentity;
27 /**
28 * Show an error when the user tries to do something whilst blocked.
30 * @newable
31 * @since 1.18
32 * @ingroup Exception
34 class UserBlockedError extends ErrorPageError {
35 /**
36 * @stable to call
37 * @param Block $block
38 * @param UserIdentity|null $user
39 * @param mixed $language Unused since 1.42
40 * @param string|null $ip
42 public function __construct(
43 Block $block,
44 ?UserIdentity $user = null,
45 $language = null,
46 $ip = null
47 ) {
48 $context = RequestContext::getMain();
49 if ( $user === null || $ip === null ) {
50 // If any of these are not passed in, use the global context
51 $user = $context->getUser();
52 $ip = $context->getRequest()->getIP();
55 // @todo This should be passed in via the constructor
56 $messages = MediaWikiServices::getInstance()->getFormatterFactory()
57 ->getBlockErrorFormatter( $context )
58 ->getMessages( $block, $user, $ip );
60 if ( count( $messages ) === 1 ) {
61 $message = $messages[0];
62 } else {
63 $message = new RawMessage( '* $' . implode( "\n* \$", range( 1, count( $messages ) ) ) );
64 $message->params( $messages )->parse();
67 parent::__construct( 'blockedtitle', $message );