Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
BlockTarget | |
0.00% |
0 / 7 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWikiId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
equals | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
toString | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getLogPage | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getSpecificity | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getLegacyTuple | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateForCreation | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getLegacyUnion | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Block; |
4 | |
5 | use MediaWiki\DAO\WikiAwareEntity; |
6 | use MediaWiki\DAO\WikiAwareEntityTrait; |
7 | use MediaWiki\Page\PageReference; |
8 | use MediaWiki\User\UserIdentity; |
9 | use StatusValue; |
10 | use Stringable; |
11 | |
12 | /** |
13 | * Base class for block targets |
14 | * |
15 | * @since 1.44 |
16 | */ |
17 | abstract class BlockTarget implements WikiAwareEntity, Stringable { |
18 | use WikiAwareEntityTrait; |
19 | |
20 | /** @var string|false */ |
21 | protected $wikiId; |
22 | |
23 | /** |
24 | * @param string|false $wikiId UserIdentity and Block extend WikiAwareEntity |
25 | * and so we must ask for a wiki ID as well, to forward it through, even |
26 | * though we don't use it. |
27 | */ |
28 | protected function __construct( $wikiId ) { |
29 | $this->wikiId = $wikiId; |
30 | } |
31 | |
32 | public function getWikiId() { |
33 | return $this->wikiId; |
34 | } |
35 | |
36 | public function __toString() { |
37 | return $this->toString(); |
38 | } |
39 | |
40 | /** |
41 | * Compare this object with another one |
42 | * |
43 | * @param BlockTarget|null $other |
44 | * @return bool |
45 | */ |
46 | public function equals( ?BlockTarget $other ) { |
47 | return $other !== null |
48 | && static::class === get_class( $other ) |
49 | && $this->toString() === $other->toString(); |
50 | } |
51 | |
52 | /** |
53 | * Get the username, the IP address, range, or autoblock ID prefixed with |
54 | * a "#". Such a string will round-trip through BlockTarget::newFromString(), |
55 | * giving back the same target. |
56 | * |
57 | * @return string |
58 | */ |
59 | abstract public function toString(): string; |
60 | |
61 | /** |
62 | * Get one of the Block::TYPE_xxx constants associated with this target |
63 | * @return int |
64 | */ |
65 | abstract public function getType(): int; |
66 | |
67 | /** |
68 | * Get the title to be used when logging an action on this block. For an |
69 | * autoblock, the title is technically invalid, with a hash character in |
70 | * the DB key. For a range block, the title is valid but is not a user |
71 | * page for a specific user. |
72 | * |
73 | * See also getUserPage(), which exists only for subclasses which relate to |
74 | * a specific user with a talk page. |
75 | * |
76 | * @return PageReference |
77 | */ |
78 | abstract public function getLogPage(): PageReference; |
79 | |
80 | /** |
81 | * Get the score of this block for purposes of choosing a more specific |
82 | * block, where lower is more specific. |
83 | * |
84 | * - 1: user block |
85 | * - 2: single IP block |
86 | * - 2-3: range block scaled according to the size of the range |
87 | * |
88 | * @return float|int |
89 | */ |
90 | abstract public function getSpecificity(); |
91 | |
92 | /** |
93 | * Get the target and type tuple conventionally returned by |
94 | * BlockUtils::parseBlockTarget() |
95 | * |
96 | * @return array |
97 | */ |
98 | public function getLegacyTuple(): array { |
99 | return [ $this->getLegacyUnion(), $this->getType() ]; |
100 | } |
101 | |
102 | /** |
103 | * Check the target data against more stringent requirements imposed when |
104 | * a block is created from user input. This is in addition to the loose |
105 | * validation done by BlockTargetFactory::newFromString(). |
106 | * |
107 | * @return StatusValue |
108 | */ |
109 | abstract public function validateForCreation(): StatusValue; |
110 | |
111 | /** |
112 | * Get the first part of the legacy tuple. |
113 | * |
114 | * @return UserIdentity|string |
115 | */ |
116 | abstract protected function getLegacyUnion(); |
117 | } |