Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
29 / 29 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
BlockAutopromote | |
100.00% |
29 / 29 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
revert | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getMessage | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\Consequences\Consequence; |
4 | |
5 | use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore; |
6 | use MediaWiki\Extension\AbuseFilter\Consequences\Parameters; |
7 | use MediaWiki\Extension\AbuseFilter\GlobalNameUtils; |
8 | use MediaWiki\User\UserIdentity; |
9 | use MediaWiki\User\UserIdentityUtils; |
10 | use MessageLocalizer; |
11 | |
12 | /** |
13 | * Consequence that blocks/delays autopromotion of a registered user. |
14 | */ |
15 | class BlockAutopromote extends Consequence implements HookAborterConsequence, ReversibleConsequence { |
16 | /** @var int */ |
17 | private $duration; |
18 | /** @var BlockAutopromoteStore */ |
19 | private $blockAutopromoteStore; |
20 | /** @var MessageLocalizer */ |
21 | private $messageLocalizer; |
22 | /** @var UserIdentityUtils */ |
23 | private $userIdentityUtils; |
24 | |
25 | /** |
26 | * @param Parameters $params |
27 | * @param int $duration |
28 | * @param BlockAutopromoteStore $blockAutopromoteStore |
29 | * @param MessageLocalizer $messageLocalizer |
30 | * @param UserIdentityUtils $userIdentityUtils |
31 | */ |
32 | public function __construct( |
33 | Parameters $params, |
34 | int $duration, |
35 | BlockAutopromoteStore $blockAutopromoteStore, |
36 | MessageLocalizer $messageLocalizer, |
37 | UserIdentityUtils $userIdentityUtils |
38 | ) { |
39 | parent::__construct( $params ); |
40 | $this->duration = $duration; |
41 | $this->blockAutopromoteStore = $blockAutopromoteStore; |
42 | $this->messageLocalizer = $messageLocalizer; |
43 | $this->userIdentityUtils = $userIdentityUtils; |
44 | } |
45 | |
46 | /** |
47 | * @inheritDoc |
48 | */ |
49 | public function execute(): bool { |
50 | $target = $this->parameters->getUser(); |
51 | if ( !$this->userIdentityUtils->isNamed( $target ) ) { |
52 | return false; |
53 | } |
54 | |
55 | return $this->blockAutopromoteStore->blockAutoPromote( |
56 | $target, |
57 | $this->messageLocalizer->msg( |
58 | 'abusefilter-blockautopromotereason', |
59 | $this->parameters->getFilter()->getName(), |
60 | $this->parameters->getFilter()->getID() |
61 | )->inContentLanguage()->text(), |
62 | $this->duration |
63 | ); |
64 | } |
65 | |
66 | /** |
67 | * @inheritDoc |
68 | */ |
69 | public function revert( UserIdentity $performer, string $reason ): bool { |
70 | return $this->blockAutopromoteStore->unblockAutopromote( |
71 | $this->parameters->getUser(), |
72 | $performer, |
73 | $reason |
74 | ); |
75 | } |
76 | |
77 | /** |
78 | * @inheritDoc |
79 | */ |
80 | public function getMessage(): array { |
81 | $filter = $this->parameters->getFilter(); |
82 | return [ |
83 | 'abusefilter-autopromote-blocked', |
84 | $filter->getName(), |
85 | GlobalNameUtils::buildGlobalName( $filter->getID(), $this->parameters->getIsGlobalFilter() ), |
86 | $this->duration |
87 | ]; |
88 | } |
89 | } |