Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
AnonIpBlockTarget | |
100.00% |
13 / 13 |
|
100.00% |
11 / 11 |
11 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSpecificity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLogPage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserPage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserIdentity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateForCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toHex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toHexRange | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLegacyUnion | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Block; |
4 | |
5 | use MediaWiki\DAO\WikiAwareEntity; |
6 | use MediaWiki\Page\PageReference; |
7 | use MediaWiki\Page\PageReferenceValue; |
8 | use MediaWiki\User\UserIdentity; |
9 | use MediaWiki\User\UserIdentityValue; |
10 | use StatusValue; |
11 | use Wikimedia\IPUtils; |
12 | |
13 | /** |
14 | * A block target for a single IP address with an associated user page |
15 | * |
16 | * @since 1.44 |
17 | */ |
18 | class AnonIpBlockTarget extends BlockTarget implements BlockTargetWithUserPage, BlockTargetWithIp { |
19 | private string $addr; |
20 | |
21 | public function __construct( string $addr, string|false $wikiId = WikiAwareEntity::LOCAL ) { |
22 | parent::__construct( $wikiId ); |
23 | $this->addr = $addr; |
24 | } |
25 | |
26 | public function toString(): string { |
27 | return $this->addr; |
28 | } |
29 | |
30 | public function getType(): int { |
31 | return Block::TYPE_IP; |
32 | } |
33 | |
34 | /** @inheritDoc */ |
35 | public function getSpecificity() { |
36 | return 2; |
37 | } |
38 | |
39 | public function getLogPage(): PageReference { |
40 | return $this->getUserPage(); |
41 | } |
42 | |
43 | public function getUserPage(): PageReference { |
44 | return new PageReferenceValue( NS_USER, $this->addr, $this->wikiId ); |
45 | } |
46 | |
47 | public function getUserIdentity(): UserIdentity { |
48 | return new UserIdentityValue( 0, $this->addr, $this->wikiId ); |
49 | } |
50 | |
51 | public function validateForCreation(): StatusValue { |
52 | return StatusValue::newGood(); |
53 | } |
54 | |
55 | /** |
56 | * Get the IP address in hexadecimal form |
57 | * |
58 | * @return string |
59 | */ |
60 | public function toHex(): string { |
61 | return IPUtils::toHex( $this->addr ); |
62 | } |
63 | |
64 | /** |
65 | * Get the IP address as a hex "range" tuple, with the start and end equal |
66 | * |
67 | * @return string[] |
68 | */ |
69 | public function toHexRange(): array { |
70 | $hex = $this->toHex(); |
71 | return [ $hex, $hex ]; |
72 | } |
73 | |
74 | /** @inheritDoc */ |
75 | protected function getLegacyUnion() { |
76 | return $this->getUserIdentity(); |
77 | } |
78 | } |