Debian Codegraph @

includes/block/SystemBlock.php

raw symbols SCIP
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 MediaWiki\User\UserIdentity;
26
27 /**
28 * System blocks are temporary blocks that are created on enforcement (e.g.
29 * from IP lists) 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, with options supported by
43 * `AbstractBlock::__construct`, and also:
44 * - systemBlock: (string) Indicate that this block is automatically created by
45 * MediaWiki rather than being stored in the database. Value is a string to
46 * return 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 listed in $wgProxyList
63 * - 'dnsbl': the IP is associated with a listed domain in $wgDnsBlacklistUrls
64 * - 'wgSoftBlockRanges': the IP is covered by $wgSoftBlockRanges
65 * - 'global-block': for backwards compatibility 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 getIdentifier( $wikiId = self::LOCAL ) {
78 return $this->getSystemBlockType();
79 }
80
81 /**
82 * @inheritDoc
83 */
84 public function appliesToPasswordReset() {
85 switch ( $this->getSystemBlockType() ) {
86 case null:
87 case 'global-block':
88 return $this->isCreateAccountBlocked();
89 case 'proxy':
90 return true;
91 case 'dnsbl':
92 case 'wgSoftBlockRanges':
93 return false;
94 default:
95 return true;
96 }
97 }
98
99 /**
100 * @inheritDoc
101 */
102 public function getBy( $wikiId = self::LOCAL ): int {
103 $this->assertWiki( $wikiId );
104 return 0;
105 }
106
107 /**
108 * @inheritDoc
109 */
110 public function getByName() {
111 return '';
112 }
113
114 /**
115 * @inheritDoc
116 */
117 public function getBlocker(): ?UserIdentity {
118 return null;
119 }
120 }