Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
UserBlockedError
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
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
21use MediaWiki\Block\Block;
22use MediaWiki\Context\RequestContext;
23use MediaWiki\Language\RawMessage;
24use MediaWiki\MediaWikiServices;
25use MediaWiki\User\UserIdentity;
26
27/**
28 * Show an error when the user tries to do something whilst blocked.
29 *
30 * @newable
31 * @since 1.18
32 * @ingroup Exception
33 */
34class 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
41     */
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();
53        }
54
55        // @todo This should be passed in via the constructor
56        $messages = MediaWikiServices::getInstance()->getFormatterFactory()
57            ->getBlockErrorFormatter( $context )
58            ->getMessages( $block, $user, $ip );
59
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();
65        }
66
67        parent::__construct( 'blockedtitle', $message );
68    }
69}