MediaWiki master
AutoblockExemptionList.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Block;
4
5use Psr\Log\LoggerInterface;
6use Wikimedia\IPUtils;
9
15 private LoggerInterface $logger;
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
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 // List items only
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 // Is the IP in this range?
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}
Provides access to the wiki's autoblock exemption list.
isExempt( $ip)
Checks whether a given IP is on the autoblock exemption list.
__construct(LoggerInterface $logger, ITextFormatter $textFormatter)
Value object representing a message for i18n.
if(!file_exists( $CREDITS)) $lines