| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Block; |
| 4 |
|
| 5 |
use Psr\Log\LoggerInterface; |
| 6 |
use Wikimedia\IPUtils; |
| 7 |
use Wikimedia\Message\ITextFormatter; |
| 8 |
use Wikimedia\Message\MessageValue; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class AutoblockExemptionList { |
| 15 |
private LoggerInterface $logger; |
| 16 |
|
| 17 |
private ITextFormatter $textFormatter; |
| 18 |
|
| 19 |
public function __construct( |
| 20 |
LoggerInterface $logger, |
| 21 |
ITextFormatter $textFormatter |
| 22 |
) { |
| 23 |
$this->logger = $logger; |
| 24 |
$this->textFormatter = $textFormatter; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function isExempt( $ip ) { |
| 34 |
$list = $this->textFormatter->format( |
| 35 |
MessageValue::new( 'block-autoblock-exemptionlist' ) |
| 36 |
); |
| 37 |
$lines = explode( "\n", $list ); |
| 38 |
$this->logger->debug( "Checking the autoblock exemption list.." ); |
| 39 |
foreach ( $lines as $line ) { |
| 40 |
|
| 41 |
if ( !str_starts_with( $line, '*' ) ) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
$wlEntry = substr( $line, 1 ); |
| 46 |
$wlEntry = trim( $wlEntry ); |
| 47 |
|
| 48 |
$this->logger->debug( "Checking $ip against $wlEntry..." ); |
| 49 |
|
| 50 |
|
| 51 |
if ( IPUtils::isInRange( $ip, $wlEntry ) ) { |
| 52 |
$this->logger->debug( " IP $ip matches $wlEntry, not autoblocking" ); |
| 53 |
return true; |
| 54 |
} else { |
| 55 |
$this->logger->debug( " No match" ); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
} |