Replace deprecated IP class with IPUtils

Bug: T242556
Change-Id: If8e9034885726b673d1500fa8b538b5302e66165
This commit is contained in:
Ammar Abdulhamid 2020-01-24 18:26:03 +01:00
parent a6098bb465
commit 641aeebbcf
5 changed files with 15 additions and 10 deletions

View file

@ -2,6 +2,7 @@
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Wikimedia\IPUtils;
use Wikimedia\Rdbms\Database;
class AFComputedVariable {
@ -89,7 +90,7 @@ class AFComputedVariable {
if ( $user instanceof User ) {
$ret = $user;
} elseif ( IP::isIPAddress( $username ) ) {
} elseif ( IPUtils::isIPAddress( $username ) ) {
$ret = new User;
$ret->setName( $username );
} else {

View file

@ -6,6 +6,7 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\RevisionRecord;
use Wikimedia\IPUtils;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IMaintainableDatabase;
@ -792,7 +793,7 @@ class AbuseFilterHooks {
$username = $nt->getText();
if ( MediaWikiServices::getInstance()->getPermissionManager()
->userHasRight( $sp->getUser(), 'abusefilter-log' )
&& !IP::isValidRange( $username )
&& !IPUtils::isValidRange( $username )
) {
$linkRenderer = $sp->getLinkRenderer();
$tools['abuselog'] = $linkRenderer->makeLink(

View file

@ -4,6 +4,7 @@ use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
use Wikimedia\IPUtils;
use Wikimedia\Rdbms\IDatabase;
/**
@ -863,7 +864,7 @@ class AbuseFilterRunner {
$identifier = $this->user->getId();
break;
case 'range':
$identifier = substr( IP::toHex( $request->getIP() ), 0, 4 );
$identifier = substr( IPUtils::toHex( $request->getIP() ), 0, 4 );
break;
case 'creationdate':
$reg = (int)$this->user->getRegistration();
@ -913,7 +914,7 @@ class AbuseFilterRunner {
global $wgAbuseFilterRangeBlockSize, $wgBlockCIDRLimit;
$ip = RequestContext::getMain()->getRequest()->getIP();
$type = IP::isIPv6( $ip ) ? 'IPv6' : 'IPv4';
$type = IPUtils::isIPv6( $ip ) ? 'IPv6' : 'IPv4';
$CIDRsize = max( $wgAbuseFilterRangeBlockSize[$type], $wgBlockCIDRLimit[$type] );
$blockCIDR = $ip . '/' . $CIDRsize;
@ -922,7 +923,7 @@ class AbuseFilterRunner {
'desc' => $ruleDescription,
'number' => $ruleNumber
],
IP::sanitizeRange( $blockCIDR ),
IPUtils::sanitizeRange( $blockCIDR ),
'1 week',
false
);
@ -1084,7 +1085,7 @@ class AbuseFilterRunner {
? 'indefinite'
: $expiry;
$flags = [ 'nocreate' ];
if ( !$block->isAutoblocking() && !IP::isIPAddress( $target ) ) {
if ( !$block->isAutoblocking() && !IPUtils::isIPAddress( $target ) ) {
// Conditionally added same as SpecialBlock
$flags[] = 'noautoblock';
}

View file

@ -24,6 +24,7 @@
*/
use MediaWiki\Storage\RevisionRecord;
use Wikimedia\IPUtils;
/**
* Query module to list abuse log entries.
@ -120,9 +121,9 @@ class ApiQueryAbuseLog extends ApiQueryBase {
// Username normalisation
$params['user'] = $u->getName();
$userId = $u->getId();
} elseif ( IP::isIPAddress( $params['user'] ) ) {
} elseif ( IPUtils::isIPAddress( $params['user'] ) ) {
// It's an IP, sanitize it
$params['user'] = IP::sanitizeIP( $params['user'] );
$params['user'] = IPUtils::sanitizeIP( $params['user'] );
$userId = 0;
}

View file

@ -3,6 +3,7 @@
use Psr\Log\LoggerInterface;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Equivset\Equivset;
use Wikimedia\IPUtils;
class AbuseFilterParser extends AFPTransitionBase {
/**
@ -1374,7 +1375,7 @@ class AbuseFilterParser extends AFPTransitionBase {
$ip = $args[0]->toString();
$range = $args[1]->toString();
if ( !IP::isValidRange( $range ) ) {
if ( !IPUtils::isValidRange( $range ) ) {
throw new AFPUserVisibleException(
'invalidiprange',
$this->mCur->pos,
@ -1382,7 +1383,7 @@ class AbuseFilterParser extends AFPTransitionBase {
);
}
$result = IP::isInRange( $ip, $range );
$result = IPUtils::isInRange( $ip, $range );
return new AFPData( AFPData::DBOOL, $result );
}