| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\Consequences\Consequence; |
| 4 |
|
| 5 |
use MediaWiki\Block\BlockUserFactory; |
| 6 |
use MediaWiki\Extension\AbuseFilter\Consequences\Parameters; |
| 7 |
use MediaWiki\Extension\AbuseFilter\FilterUser; |
| 8 |
use MediaWiki\Extension\AbuseFilter\GlobalNameUtils; |
| 9 |
use MessageLocalizer; |
| 10 |
use Psr\Log\LoggerInterface; |
| 11 |
use Wikimedia\IPUtils; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class RangeBlock extends BlockingConsequence { |
| 17 |
|
| 18 |
private $rangeBlockSize; |
| 19 |
|
| 20 |
private $blockCIDRLimit; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function __construct( |
| 33 |
Parameters $parameters, |
| 34 |
string $expiry, |
| 35 |
BlockUserFactory $blockUserFactory, |
| 36 |
FilterUser $filterUser, |
| 37 |
MessageLocalizer $messageLocalizer, |
| 38 |
LoggerInterface $logger, |
| 39 |
array $rangeBlockSize, |
| 40 |
array $blockCIDRLimit |
| 41 |
) { |
| 42 |
parent::__construct( $parameters, $expiry, $blockUserFactory, $filterUser, $messageLocalizer, $logger ); |
| 43 |
$this->rangeBlockSize = $rangeBlockSize; |
| 44 |
$this->blockCIDRLimit = $blockCIDRLimit; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function execute(): bool { |
| 51 |
$requestIP = $this->parameters->getActionSpecifier()->getIP(); |
| 52 |
$type = IPUtils::isIPv6( $requestIP ) ? 'IPv6' : 'IPv4'; |
| 53 |
$CIDRsize = max( $this->rangeBlockSize[$type], $this->blockCIDRLimit[$type] ); |
| 54 |
$blockCIDR = $requestIP . '/' . $CIDRsize; |
| 55 |
|
| 56 |
$target = IPUtils::sanitizeRange( $blockCIDR ); |
| 57 |
$status = $this->doBlockInternal( |
| 58 |
$this->parameters->getFilter()->getName(), |
| 59 |
$this->parameters->getFilter()->getID(), |
| 60 |
$target, |
| 61 |
$this->expiry, |
| 62 |
$autoblock = false, |
| 63 |
$preventTalk = false |
| 64 |
); |
| 65 |
return $status->isOK(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function getMessage(): array { |
| 72 |
$filter = $this->parameters->getFilter(); |
| 73 |
return [ |
| 74 |
'abusefilter-blocked-display', |
| 75 |
$filter->getName(), |
| 76 |
GlobalNameUtils::buildGlobalName( $filter->getID(), $this->parameters->getIsGlobalFilter() ) |
| 77 |
]; |
| 78 |
} |
| 79 |
} |