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 ( strpos( $target,
'/' ) !==
false ) {
121 $target = explode(
'/', $target )[0];
124 if ( preg_match(
'/^#\d+$/', $target ) ) {
129 $userFromDB = $this->userIdentityLookup->getUserIdentityByName( $target );
130 if ( $userFromDB instanceof UserIdentity ) {
138 $canonicalName = $this->userNameUtils->getCanonical( $target );
139 if ( $canonicalName ) {
141 new UserIdentityValue( 0, $canonicalName ),
146 return [
null, null ];
157 list( $target,
$type ) = $this->parseBlockTarget( $value );
159 $status = Status::newGood( $target );
163 if ( !$target->isRegistered() ) {
172 list( $ip, $range ) = explode(
'/', $target, 2 );
174 if ( IPUtils::isIPv4( $ip ) ) {
175 $status->merge( $this->validateIPv4Range( (
int)$range ) );
176 } elseif ( IPUtils::isIPv6( $ip ) ) {
177 $status->merge( $this->validateIPv6Range( (
int)$range ) );
180 $status->fatal(
'badipaddress' );
189 $status->fatal(
'badipaddress' );
203 private function validateIPv4Range(
int $range ):
Status {
204 $status =
Status::newGood();
205 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
207 if ( $blockCIDRLimit[
'IPv4'] == 32 ) {
209 $status->
fatal(
'range_block_disabled' );
210 } elseif ( $range > 32 ) {
212 $status->fatal(
'ip_range_invalid' );
213 } elseif ( $range < $blockCIDRLimit[
'IPv4'] ) {
214 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv4'] );
227 private function validateIPv6Range(
int $range ):
Status {
228 $status =
Status::newGood();
229 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
231 if ( $blockCIDRLimit[
'IPv6'] == 128 ) {
233 $status->
fatal(
'range_block_disabled' );
234 } elseif ( $range > 128 ) {
236 $status->fatal(
'ip_range_invalid' );
237 } elseif ( $range < $blockCIDRLimit[
'IPv6'] ) {
238 $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'))
The persistent session ID (if any) loaded at startup.
A class containing constants representing the names of configuration variables.
const BlockCIDRLimit
Name constant for the BlockCIDRLimit setting, for use with Config::get()
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Generic operation result class Has warning/error list, boolean status and arbitrary value.