51 private $userIdentityLookup;
54 private $userNameUtils;
74 $this->options = $options;
75 $this->userIdentityLookup = $userIdentityLookup;
76 $this->userNameUtils = $userNameUtils;
95 if ( IPUtils::isValid( $target->getName() ) ) {
100 } elseif ( $target ===
null ) {
101 return [
null, null ];
104 $target = trim( $target );
106 if ( IPUtils::isValid( $target ) ) {
108 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $target ) ),
112 } elseif ( IPUtils::isValidRange( $target ) ) {
119 if ( str_contains( $target,
'/' ) ) {
121 $target = explode(
'/', $target )[0];
124 if ( preg_match(
'/^#\d+$/', $target ) ) {
129 $userFromDB = $this->userIdentityLookup->getUserIdentityByName( $target );
130 if ( $userFromDB instanceof UserIdentity ) {
140 $canonicalName = $this->userNameUtils->getCanonical( $target );
141 if ( $canonicalName ) {
143 new UserIdentityValue( 0, $canonicalName ),
148 return [
null, null ];
159 [ $target, $type ] = $this->parseBlockTarget( $value );
161 $status = Status::newGood( $target );
165 if ( !$target->isRegistered() ) {
174 [ $ip, $range ] = explode(
'/', $target, 2 );
176 if ( IPUtils::isIPv4( $ip ) ) {
177 $status->merge( $this->validateIPv4Range( (
int)$range ) );
178 } elseif ( IPUtils::isIPv6( $ip ) ) {
179 $status->merge( $this->validateIPv6Range( (
int)$range ) );
182 $status->fatal(
'badipaddress' );
191 $status->fatal(
'badipaddress' );
205 private function validateIPv4Range(
int $range ): Status {
206 $status = Status::newGood();
207 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
209 if ( $blockCIDRLimit[
'IPv4'] == 32 ) {
211 $status->fatal(
'range_block_disabled' );
212 } elseif ( $range > 32 ) {
214 $status->fatal(
'ip_range_invalid' );
215 } elseif ( $range < $blockCIDRLimit[
'IPv4'] ) {
216 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv4'] );
229 private function validateIPv6Range(
int $range ): Status {
230 $status = Status::newGood();
231 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
233 if ( $blockCIDRLimit[
'IPv6'] == 128 ) {
235 $status->fatal(
'range_block_disabled' );
236 } elseif ( $range > 128 ) {
238 $status->fatal(
'ip_range_invalid' );
239 } elseif ( $range < $blockCIDRLimit[
'IPv6'] ) {
240 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv6'] );
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined('MW_SETUP_CALLBACK'))
A class containing constants representing the names of configuration variables.
const BlockCIDRLimit
Name constant for the BlockCIDRLimit setting, for use with Config::get()