52 private $userIdentityLookup;
55 private $userNameUtils;
75 $this->options = $options;
76 $this->userIdentityLookup = $userIdentityLookup;
77 $this->userNameUtils = $userNameUtils;
101 if ( IPUtils::isValid( $target->getName() ) ) {
106 } elseif ( $target ===
null ) {
107 return [
null, null ];
110 $target = trim( $target );
112 if ( IPUtils::isValid( $target ) ) {
114 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $target ) ),
118 } elseif ( IPUtils::isValidRange( $target ) ) {
125 if ( str_contains( $target,
'/' ) ) {
127 $target = explode(
'/', $target )[0];
130 if ( preg_match(
'/^#\d+$/', $target ) ) {
135 $userFromDB = $this->userIdentityLookup->getUserIdentityByName( $target );
136 if ( $userFromDB instanceof UserIdentity ) {
146 $canonicalName = $this->userNameUtils->getCanonical( $target );
147 if ( $canonicalName ) {
149 new UserIdentityValue( 0, $canonicalName ),
154 return [
null, null ];
166 if ( $row->bt_auto ) {
168 } elseif ( isset( $row->bt_user ) ) {
169 if ( isset( $row->bt_user_text ) ) {
172 $user = $this->userIdentityLookup->getUserIdentityByUserId( $row->bt_user );
175 } elseif ( $row->bt_address ===
null ) {
176 return [
null, null ];
177 } elseif ( IPUtils::isValid( $row->bt_address ) ) {
179 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $row->bt_address ) ),
182 } elseif ( IPUtils::isValidRange( $row->bt_address ) ) {
186 return [
null, null ];
198 [ $target, $type ] = $this->parseBlockTarget( $value );
200 $status = Status::newGood( $target );
204 if ( !$target->isRegistered() ) {
213 [ $ip, $range ] = explode(
'/', $target, 2 );
215 if ( IPUtils::isIPv4( $ip ) ) {
216 $status->merge( $this->validateIPv4Range( (
int)$range ) );
217 } elseif ( IPUtils::isIPv6( $ip ) ) {
218 $status->merge( $this->validateIPv6Range( (
int)$range ) );
221 $status->fatal(
'badipaddress' );
230 $status->fatal(
'badipaddress' );
244 private function validateIPv4Range(
int $range ): Status {
245 $status = Status::newGood();
246 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
248 if ( $blockCIDRLimit[
'IPv4'] == 32 ) {
250 $status->fatal(
'range_block_disabled' );
251 } elseif ( $range > 32 ) {
253 $status->fatal(
'ip_range_invalid' );
254 } elseif ( $range < $blockCIDRLimit[
'IPv4'] ) {
255 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv4'] );
268 private function validateIPv6Range(
int $range ): Status {
269 $status = Status::newGood();
270 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
272 if ( $blockCIDRLimit[
'IPv6'] == 128 ) {
274 $status->fatal(
'range_block_disabled' );
275 } elseif ( $range > 128 ) {
277 $status->fatal(
'ip_range_invalid' );
278 } elseif ( $range < $blockCIDRLimit[
'IPv6'] ) {
279 $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()