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
21 use MediaWiki\Block\Block
;
22 use MediaWiki\Context\RequestContext
;
23 use MediaWiki\Language\RawMessage
;
24 use MediaWiki\MediaWikiServices
;
25 use MediaWiki\User\UserIdentity
;
28 * Show an error when the user tries to do something whilst blocked.
34 class UserBlockedError
extends ErrorPageError
{
38 * @param UserIdentity|null $user
39 * @param mixed $language Unused since 1.42
40 * @param string|null $ip
42 public function __construct(
44 ?UserIdentity
$user = null,
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];
63 $message = new RawMessage( '* $' . implode( "\n* \$", range( 1, count( $messages ) ) ) );
64 $message->params( $messages )->parse();
67 parent
::__construct( 'blockedtitle', $message );