| 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 |
|
| 14 |
|
| 15 |
class BlockAutopromote extends Consequence implements HookAborterConsequence, ReversibleConsequence { |
| 16 |
|
| 17 |
private $duration; |
| 18 |
|
| 19 |
private $blockAutopromoteStore; |
| 20 |
|
| 21 |
private $messageLocalizer; |
| 22 |
|
| 23 |
private $userIdentityUtils; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
} |