52 private $userIdentityLookup;
55 private $userNameUtils;
77 $wikiId = Block::LOCAL
80 $this->options = $options;
81 $this->userIdentityLookup = $userIdentityLookup;
82 $this->userNameUtils = $userNameUtils;
83 $this->wikiId = $wikiId;
107 if ( IPUtils::isValid( $target->getName() ) ) {
112 } elseif ( $target ===
null ) {
113 return [
null, null ];
116 $target = trim( $target );
118 if ( IPUtils::isValid( $target ) ) {
120 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $target ), $this->wikiId ),
124 } elseif ( IPUtils::isValidRange( $target ) ) {
129 if ( preg_match(
'/^#\d+$/', $target ) ) {
134 $userFromDB = $this->userIdentityLookup->getUserIdentityByName( $target );
135 if ( $userFromDB instanceof UserIdentity ) {
145 $canonicalName = $this->userNameUtils->getCanonical( $target );
146 if ( $canonicalName ) {
148 new UserIdentityValue( 0, $canonicalName ),
153 return [
null, null ];
165 if ( $row->bt_auto ) {
167 } elseif ( isset( $row->bt_user ) ) {
168 if ( isset( $row->bt_user_text ) ) {
169 $user =
new UserIdentityValue( $row->bt_user, $row->bt_user_text, $this->wikiId );
171 $user = $this->userIdentityLookup->getUserIdentityByUserId( $row->bt_user );
174 } elseif ( $row->bt_address ===
null ) {
175 return [
null, null ];
176 } elseif ( IPUtils::isValid( $row->bt_address ) ) {
178 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $row->bt_address ), $this->wikiId ),
181 } elseif ( IPUtils::isValidRange( $row->bt_address ) ) {
185 return [
null, null ];
197 [ $target, $type ] = $this->parseBlockTarget( $value );
199 $status = Status::newGood( $target );
203 if ( !$target->isRegistered() ) {
212 [ $ip, $range ] = explode(
'/', $target, 2 );
214 if ( IPUtils::isIPv4( $ip ) ) {
215 $status->merge( $this->validateIPv4Range( (
int)$range ) );
216 } elseif ( IPUtils::isIPv6( $ip ) ) {
217 $status->merge( $this->validateIPv6Range( (
int)$range ) );
220 $status->fatal(
'badipaddress' );
229 $status->fatal(
'badipaddress' );
243 private function validateIPv4Range(
int $range ): Status {
244 $status = Status::newGood();
245 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
247 if ( $blockCIDRLimit[
'IPv4'] == 32 ) {
249 $status->fatal(
'range_block_disabled' );
250 } elseif ( $range > 32 ) {
252 $status->fatal(
'ip_range_invalid' );
253 } elseif ( $range < $blockCIDRLimit[
'IPv4'] ) {
254 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv4'] );
267 private function validateIPv6Range(
int $range ): Status {
268 $status = Status::newGood();
269 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
271 if ( $blockCIDRLimit[
'IPv6'] == 128 ) {
273 $status->fatal(
'range_block_disabled' );
274 } elseif ( $range > 128 ) {
276 $status->fatal(
'ip_range_invalid' );
277 } elseif ( $range < $blockCIDRLimit[
'IPv6'] ) {
278 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv6'] );
wfEscapeWikiText( $input)
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()