Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
UserBlockTarget | |
100.00% |
15 / 15 |
|
100.00% |
9 / 9 |
10 | |
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% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getLegacyUnion | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Block; |
4 | |
5 | use MediaWiki\Page\PageReference; |
6 | use MediaWiki\Page\PageReferenceValue; |
7 | use MediaWiki\User\UserIdentity; |
8 | use StatusValue; |
9 | |
10 | /** |
11 | * A block target for a registered user |
12 | * |
13 | * @since 1.44 |
14 | */ |
15 | class UserBlockTarget extends BlockTarget implements BlockTargetWithUserPage { |
16 | private UserIdentity $userIdentity; |
17 | |
18 | public function __construct( UserIdentity $userIdentity ) { |
19 | parent::__construct( $userIdentity->getWikiId() ); |
20 | $this->userIdentity = $userIdentity; |
21 | } |
22 | |
23 | public function toString(): string { |
24 | return $this->userIdentity->getName(); |
25 | } |
26 | |
27 | public function getType(): int { |
28 | return Block::TYPE_USER; |
29 | } |
30 | |
31 | /** @inheritDoc */ |
32 | public function getSpecificity() { |
33 | return 1; |
34 | } |
35 | |
36 | public function getLogPage(): PageReference { |
37 | return $this->getUserPage(); |
38 | } |
39 | |
40 | public function getUserPage(): PageReference { |
41 | return new PageReferenceValue( NS_USER, $this->userIdentity->getName(), $this->wikiId ); |
42 | } |
43 | |
44 | public function getUserIdentity(): UserIdentity { |
45 | return $this->userIdentity; |
46 | } |
47 | |
48 | public function validateForCreation(): StatusValue { |
49 | if ( !$this->userIdentity->isRegistered() ) { |
50 | return StatusValue::newFatal( |
51 | 'nosuchusershort', |
52 | wfEscapeWikiText( $this->userIdentity->getName() ) |
53 | ); |
54 | } |
55 | return StatusValue::newGood(); |
56 | } |
57 | |
58 | /** @inheritDoc */ |
59 | protected function getLegacyUnion() { |
60 | return $this->getUserIdentity(); |
61 | } |
62 | } |