3 * Class for temporary blocks created on enforcement.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Block
;
28 * System blocks are temporary blocks that are created on enforcement (e.g.
29 * from IP blacklists) and are not saved to the database. The target of a
30 * system block is an IP address. System blocks do not give rise to
31 * autoblocks and are not tracked with cookies.
35 class SystemBlock
extends AbstractBlock
{
36 /** @var string|null */
37 private $systemBlockType;
40 * Create a new block with specified parameters on a user, IP or IP range.
42 * @param array $options Parameters of the block:
43 * systemBlock string Indicate that this block is automatically
44 * created by MediaWiki rather than being stored
45 * in the database. Value is a string to return
46 * from self::getSystemBlockType().
48 public function __construct( array $options = [] ) {
49 parent
::__construct( $options );
52 'systemBlock' => null,
55 $options +
= $defaults;
57 $this->systemBlockType
= $options['systemBlock'];
61 * Get the system block type, if any. A SystemBlock can have the following types:
62 * - 'proxy': the IP is blacklisted in $wgProxyList
63 * - 'dnsbl': the IP is associated with a blacklisted domain in $wgDnsBlacklistUrls
64 * - 'wgSoftBlockRanges': the IP is covered by $wgSoftBlockRanges
65 * - 'global-block': for backwards compatability with the UserIsBlockedGlobally hook
70 public function getSystemBlockType() {
71 return $this->systemBlockType
;
77 public function getPermissionsError( IContextSource
$context ) {
78 $params = $this->getBlockErrorParams( $context );
79 // TODO: Clean up error messages params so we don't have to do this
80 $params[ 4 ] = $this->getSystemBlockType();
82 $msg = 'systemblockedtext';
84 array_unshift( $params, $msg );
92 public function appliesToPasswordReset() {
93 switch ( $this->getSystemBlockType() ) {
96 return $this->isCreateAccountBlocked();
100 case 'wgSoftBlockRanges':