Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / block / SystemBlock.php
1 <?php
2 /**
3 * Class for temporary blocks created on enforcement.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Block;
24
25 use IContextSource;
26
27 /**
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.
32 *
33 * @since 1.34
34 */
35 class SystemBlock extends AbstractBlock {
36 /** @var string|null */
37 private $systemBlockType;
38
39 /**
40 * Create a new block with specified parameters on a user, IP or IP range.
41 *
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().
47 */
48 public function __construct( array $options = [] ) {
49 parent::__construct( $options );
50
51 $defaults = [
52 'systemBlock' => null,
53 ];
54
55 $options += $defaults;
56
57 $this->systemBlockType = $options['systemBlock'];
58 }
59
60 /**
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
66 *
67 * @since 1.29
68 * @return string|null
69 */
70 public function getSystemBlockType() {
71 return $this->systemBlockType;
72 }
73
74 /**
75 * @inheritDoc
76 */
77 public function getPermissionsError( IContextSource $context ) {
78 $params = $this->getBlockErrorParams( $context );
79
80 // TODO: Clean up error messages params so we don't have to do this (T227174)
81 $params[ 4 ] = $this->getSystemBlockType();
82
83 $msg = 'systemblockedtext';
84
85 array_unshift( $params, $msg );
86
87 return $params;
88 }
89
90 /**
91 * @inheritDoc
92 */
93 public function appliesToPasswordReset() {
94 switch ( $this->getSystemBlockType() ) {
95 case null:
96 case 'global-block':
97 return $this->isCreateAccountBlocked();
98 case 'proxy':
99 return true;
100 case 'dnsbl':
101 case 'wgSoftBlockRanges':
102 return false;
103 default:
104 return true;
105 }
106 }
107
108 }