66 $wikiId = Block::LOCAL
69 $this->options = $options;
70 $this->userIdentityLookup = $userIdentityLookup;
71 $this->userNameUtils = $userNameUtils;
72 $this->wikiId = $wikiId;
96 if ( IPUtils::isValid( $target->getName() ) ) {
101 } elseif ( $target ===
null ) {
102 return [
null, null ];
105 $target = trim( $target );
107 if ( IPUtils::isValid( $target ) ) {
109 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $target ), $this->wikiId ),
113 } elseif ( IPUtils::isValidRange( $target ) ) {
118 if ( preg_match(
'/^#\d+$/', $target ) ) {
123 $userFromDB = $this->userIdentityLookup->getUserIdentityByName( $target );
124 if ( $userFromDB instanceof UserIdentity ) {
134 $canonicalName = $this->userNameUtils->getCanonical( $target );
135 if ( $canonicalName !==
false ) {
137 new UserIdentityValue( 0, $canonicalName ),
142 return [
null, null ];
154 if ( $row->bt_auto ) {
156 } elseif ( isset( $row->bt_user ) ) {
157 if ( isset( $row->bt_user_text ) ) {
158 $user =
new UserIdentityValue( $row->bt_user, $row->bt_user_text, $this->wikiId );
160 $user = $this->userIdentityLookup->getUserIdentityByUserId( $row->bt_user );
163 } elseif ( $row->bt_address ===
null ) {
164 return [
null, null ];
165 } elseif ( IPUtils::isValid( $row->bt_address ) ) {
167 UserIdentityValue::newAnonymous( IPUtils::sanitizeIP( $row->bt_address ), $this->wikiId ),
170 } elseif ( IPUtils::isValidRange( $row->bt_address ) ) {
174 return [
null, null ];
186 [ $target, $type ] = $this->parseBlockTarget( $value );
188 $status = Status::newGood( $target );
192 if ( !$target->isRegistered() ) {
201 [ $ip, $range ] = explode(
'/', $target, 2 );
203 if ( IPUtils::isIPv4( $ip ) ) {
204 $status->merge( $this->validateIPv4Range( (
int)$range ) );
205 } elseif ( IPUtils::isIPv6( $ip ) ) {
206 $status->merge( $this->validateIPv6Range( (
int)$range ) );
209 $status->fatal(
'badipaddress' );
218 $status->fatal(
'badipaddress' );
232 private function validateIPv4Range(
int $range ): Status {
233 $status = Status::newGood();
234 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
236 if ( $blockCIDRLimit[
'IPv4'] == 32 ) {
238 $status->fatal(
'range_block_disabled' );
239 } elseif ( $range > 32 ) {
241 $status->fatal(
'ip_range_invalid' );
242 } elseif ( $range < $blockCIDRLimit[
'IPv4'] ) {
243 $status->fatal(
'ip_range_toolarge', $blockCIDRLimit[
'IPv4'] );
256 private function validateIPv6Range(
int $range ): Status {
257 $status = Status::newGood();
258 $blockCIDRLimit = $this->options->get( MainConfigNames::BlockCIDRLimit );
260 if ( $blockCIDRLimit[
'IPv6'] == 128 ) {
262 $status->fatal(
'range_block_disabled' );
263 } elseif ( $range > 128 ) {
265 $status->fatal(
'ip_range_invalid' );
266 } elseif ( $range < $blockCIDRLimit[
'IPv6'] ) {
267 $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()