Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
This commit is contained in:
parent
610954eda6
commit
99007e96c7
43 changed files with 166 additions and 124 deletions
|
|
@ -1924,9 +1924,9 @@ $rc: RecentChange object that triggered url generation
|
|||
'IsFileCacheable': Override the result of Article::isFileCacheable() (if true)
|
||||
&$article: article (object) being checked
|
||||
|
||||
'IsTrustedProxy': Override the result of IP::isTrustedProxy()
|
||||
'IsTrustedProxy': Override the result of ProxyLookup::isTrustedProxy()
|
||||
&$ip: IP being check
|
||||
&$result: Change this value to override the result of IP::isTrustedProxy()
|
||||
&$result: Change this value to override the result of ProxyLookup::isTrustedProxy()
|
||||
|
||||
'IsUploadAllowedFromUrl': Override the result of UploadFromUrl::isAllowedUrl()
|
||||
$url: URL used to upload from
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* This class checks if user can get extra rights
|
||||
|
|
@ -198,7 +199,7 @@ class Autopromote {
|
|||
case APCOND_ISIP:
|
||||
return $cond[1] == $user->getRequest()->getIP();
|
||||
case APCOND_IPINRANGE:
|
||||
return IP::isInRange( $user->getRequest()->getIP(), $cond[1] );
|
||||
return IPUtils::isInRange( $user->getRequest()->getIP(), $cond[1] );
|
||||
case APCOND_BLOCKED:
|
||||
return $user->getBlock() && $user->getBlock()->isSitewide();
|
||||
case APCOND_ISBOT:
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\Rdbms\LikeMatch;
|
||||
|
||||
/**
|
||||
|
|
@ -122,22 +124,22 @@ class LinkFilter {
|
|||
// IPv6? RFC 3986 syntax.
|
||||
if ( preg_match( '/^\[([0-9a-f:*]+)\]$/', rawurldecode( $host ), $m ) ) {
|
||||
$ip = $m[1];
|
||||
if ( IP::isValid( $ip ) ) {
|
||||
return 'V6.' . implode( '.', explode( ':', IP::sanitizeIP( $ip ) ) ) . '.';
|
||||
if ( IPUtils::isValid( $ip ) ) {
|
||||
return 'V6.' . implode( '.', explode( ':', IPUtils::sanitizeIP( $ip ) ) ) . '.';
|
||||
}
|
||||
if ( substr( $ip, -2 ) === ':*' ) {
|
||||
$cutIp = substr( $ip, 0, -2 );
|
||||
if ( IP::isValid( "{$cutIp}::" ) ) {
|
||||
if ( IPUtils::isValid( "{$cutIp}::" ) ) {
|
||||
// Wildcard IP doesn't contain "::", so multiple parts can be wild
|
||||
$ct = count( explode( ':', $ip ) ) - 1;
|
||||
return 'V6.' .
|
||||
implode( '.', array_slice( explode( ':', IP::sanitizeIP( "{$cutIp}::" ) ), 0, $ct ) ) .
|
||||
implode( '.', array_slice( explode( ':', IPUtils::sanitizeIP( "{$cutIp}::" ) ), 0, $ct ) ) .
|
||||
'.*.';
|
||||
}
|
||||
if ( IP::isValid( "{$cutIp}:1" ) ) {
|
||||
if ( IPUtils::isValid( "{$cutIp}:1" ) ) {
|
||||
// Wildcard IP does contain "::", so only the last part is wild
|
||||
return 'V6.' .
|
||||
substr( implode( '.', explode( ':', IP::sanitizeIP( "{$cutIp}:1" ) ) ), 0, -1 ) .
|
||||
substr( implode( '.', explode( ':', IPUtils::sanitizeIP( "{$cutIp}:1" ) ) ), 0, -1 ) .
|
||||
'*.';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Some internal bits split of from Skin.php. These functions are used
|
||||
|
|
@ -910,7 +911,7 @@ class Linker {
|
|||
if ( ExternalUserNames::isExternal( $userName ) ) {
|
||||
$classes .= ' mw-extuserlink';
|
||||
} elseif ( $altUserName === false ) {
|
||||
$altUserName = IP::prettifyIP( $userName );
|
||||
$altUserName = IPUtils::prettifyIP( $userName );
|
||||
}
|
||||
$classes .= ' mw-anonuserlink'; // Separate link class for anons (T45179)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ use DBAccessObjectUtils;
|
|||
use Hooks;
|
||||
use IDBAccessObject;
|
||||
use InvalidArgumentException;
|
||||
use IP;
|
||||
use LogicException;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Storage\BlobAccessException;
|
||||
|
|
@ -61,6 +60,7 @@ use Traversable;
|
|||
use User;
|
||||
use WANObjectCache;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\Rdbms\Database;
|
||||
use Wikimedia\Rdbms\DBConnRef;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -709,11 +709,11 @@ class RevisionStore
|
|||
RevisionRecord $rev,
|
||||
$revisionId
|
||||
) {
|
||||
if ( $user->getId() === 0 && IP::isValid( $user->getName() ) ) {
|
||||
if ( $user->getId() === 0 && IPUtils::isValid( $user->getName() ) ) {
|
||||
$ipcRow = [
|
||||
'ipc_rev_id' => $revisionId,
|
||||
'ipc_rev_timestamp' => $dbw->timestamp( $rev->getTimestamp() ),
|
||||
'ipc_hex' => IP::toHex( $user->getName() ),
|
||||
'ipc_hex' => IPUtils::toHex( $user->getName() ),
|
||||
];
|
||||
$dbw->insert( 'ip_changes', $ipcRow, __METHOD__ );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use MediaWiki\Session\Session;
|
|||
use MediaWiki\Session\SessionId;
|
||||
use MediaWiki\Session\SessionManager;
|
||||
use Wikimedia\AtEase\AtEase;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
// The point of this class is to be a wrapper around super globals
|
||||
// phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
|
||||
|
|
@ -245,7 +246,7 @@ class WebRequest {
|
|||
continue;
|
||||
}
|
||||
|
||||
$parts = IP::splitHostAndPort( $_SERVER[$varName] );
|
||||
$parts = IPUtils::splitHostAndPort( $_SERVER[$varName] );
|
||||
if ( !$parts ) {
|
||||
// Invalid, do not use
|
||||
continue;
|
||||
|
|
@ -267,7 +268,7 @@ class WebRequest {
|
|||
break;
|
||||
}
|
||||
|
||||
return $proto . '://' . IP::combineHostAndPort( $host, $port, $stdPort );
|
||||
return $proto . '://' . IPUtils::combineHostAndPort( $host, $port, $stdPort );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1218,7 +1219,7 @@ class WebRequest {
|
|||
$ipchain = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
return IP::canonicalize( $ipchain );
|
||||
return IPUtils::canonicalize( $ipchain );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1259,19 +1260,19 @@ class WebRequest {
|
|||
# IP addresses over proxy servers controlled by this site (more sensible).
|
||||
# Note that some XFF values might be "unknown" with Squid/Varnish.
|
||||
foreach ( $ipchain as $i => $curIP ) {
|
||||
$curIP = IP::sanitizeIP( IP::canonicalize( $curIP ) );
|
||||
$curIP = IPUtils::sanitizeIP( IPUtils::canonicalize( $curIP ) );
|
||||
if ( !$curIP || !isset( $ipchain[$i + 1] ) || $ipchain[$i + 1] === 'unknown'
|
||||
|| !$proxyLookup->isTrustedProxy( $curIP )
|
||||
) {
|
||||
break; // IP is not valid/trusted or does not point to anything
|
||||
}
|
||||
if (
|
||||
IP::isPublic( $ipchain[$i + 1] ) ||
|
||||
IPUtils::isPublic( $ipchain[$i + 1] ) ||
|
||||
$wgUsePrivateIPs ||
|
||||
$proxyLookup->isConfiguredProxy( $curIP ) // T50919; treat IP as sane
|
||||
) {
|
||||
// Follow the next IP according to the proxy
|
||||
$nextIP = IP::canonicalize( $ipchain[$i + 1] );
|
||||
$nextIP = IPUtils::canonicalize( $ipchain[$i + 1] );
|
||||
if ( !$nextIP && $isConfigured ) {
|
||||
// We have not yet made it past CDN/proxy servers of this site,
|
||||
// so either they are misconfigured or there is some IP spoofing.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
use Wikimedia\Rdbms\IResultWrapper;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Query module to enumerate all user blocks
|
||||
|
|
@ -115,26 +116,26 @@ class ApiQueryBlocks extends ApiQueryBase {
|
|||
}
|
||||
if ( isset( $params['ip'] ) ) {
|
||||
$blockCIDRLimit = $this->getConfig()->get( 'BlockCIDRLimit' );
|
||||
if ( IP::isIPv4( $params['ip'] ) ) {
|
||||
if ( IPUtils::isIPv4( $params['ip'] ) ) {
|
||||
$type = 'IPv4';
|
||||
$cidrLimit = $blockCIDRLimit['IPv4'];
|
||||
$prefixLen = 0;
|
||||
} elseif ( IP::isIPv6( $params['ip'] ) ) {
|
||||
} elseif ( IPUtils::isIPv6( $params['ip'] ) ) {
|
||||
$type = 'IPv6';
|
||||
$cidrLimit = $blockCIDRLimit['IPv6'];
|
||||
$prefixLen = 3; // IP::toHex output is prefixed with "v6-"
|
||||
$prefixLen = 3; // IPUtils::toHex output is prefixed with "v6-"
|
||||
} else {
|
||||
$this->dieWithError( 'apierror-badip', 'param_ip' );
|
||||
}
|
||||
|
||||
# Check range validity, if it's a CIDR
|
||||
list( $ip, $range ) = IP::parseCIDR( $params['ip'] );
|
||||
list( $ip, $range ) = IPUtils::parseCIDR( $params['ip'] );
|
||||
if ( $ip !== false && $range !== false && $range < $cidrLimit ) {
|
||||
$this->dieWithError( [ 'apierror-cidrtoobroad', $type, $cidrLimit ] );
|
||||
}
|
||||
|
||||
# Let IP::parseRange handle calculating $upper, instead of duplicating the logic here.
|
||||
list( $lower, $upper ) = IP::parseRange( $params['ip'] );
|
||||
# Let IPUtils::parseRange handle calculating $upper, instead of duplicating the logic here.
|
||||
list( $lower, $upper ) = IPUtils::parseRange( $params['ip'] );
|
||||
|
||||
# Extract the common prefix to any rangeblock affecting this IP/CIDR
|
||||
$prefix = substr( $lower, 0, $prefixLen + floor( $cidrLimit / 4 ) );
|
||||
|
|
@ -225,8 +226,8 @@ class ApiQueryBlocks extends ApiQueryBase {
|
|||
$block['reason'] = $commentStore->getComment( 'ipb_reason', $row )->text;
|
||||
}
|
||||
if ( $fld_range && !$row->ipb_auto ) {
|
||||
$block['rangestart'] = IP::formatHex( $row->ipb_range_start );
|
||||
$block['rangeend'] = IP::formatHex( $row->ipb_range_end );
|
||||
$block['rangestart'] = IPUtils::formatHex( $row->ipb_range_start );
|
||||
$block['rangeend'] = IPUtils::formatHex( $row->ipb_range_end );
|
||||
}
|
||||
if ( $fld_flags ) {
|
||||
// For clarity, these flags use the same names as their action=block counterparts
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace MediaWiki\Auth;
|
|||
|
||||
use SpecialPage;
|
||||
use User;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* A primary authentication provider that uses the temporary password field in
|
||||
|
|
@ -280,7 +281,7 @@ class TemporaryPasswordPrimaryAuthenticationProvider
|
|||
if ( !$req->caller ) {
|
||||
return \StatusValue::newFatal( 'passwordreset-nocaller' );
|
||||
}
|
||||
if ( !\IP::isValid( $req->caller ) ) {
|
||||
if ( !IPUtils::isValid( $req->caller ) ) {
|
||||
$caller = User::newFromName( $req->caller );
|
||||
if ( !$caller ) {
|
||||
return \StatusValue::newFatal( 'passwordreset-nosuchcaller', $req->caller );
|
||||
|
|
@ -470,7 +471,7 @@ class TemporaryPasswordPrimaryAuthenticationProvider
|
|||
return \Status::newFatal( 'noname' );
|
||||
}
|
||||
$userLanguage = $user->getOption( 'language' );
|
||||
$callerIsAnon = \IP::isValid( $req->caller );
|
||||
$callerIsAnon = IPUtils::isValid( $req->caller );
|
||||
$callerName = $callerIsAnon ? $req->caller : User::newFromName( $req->caller )->getName();
|
||||
$passwordMessage = wfMessage( 'passwordreset-emailelement', $user->getName(),
|
||||
$req->password )->inLanguage( $userLanguage );
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ namespace MediaWiki\Block;
|
|||
use CommentStoreComment;
|
||||
use IContextSource;
|
||||
use InvalidArgumentException;
|
||||
use IP;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Message;
|
||||
use RequestContext;
|
||||
use Title;
|
||||
use User;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* @since 1.34 Factored out from DatabaseBlock (previously Block).
|
||||
|
|
@ -378,7 +378,7 @@ abstract class AbstractBlock {
|
|||
public static function parseTarget( $target ) {
|
||||
# We may have been through this before
|
||||
if ( $target instanceof User ) {
|
||||
if ( IP::isValid( $target->getName() ) ) {
|
||||
if ( IPUtils::isValid( $target->getName() ) ) {
|
||||
return [ $target, self::TYPE_IP ];
|
||||
} else {
|
||||
return [ $target, self::TYPE_USER ];
|
||||
|
|
@ -389,17 +389,17 @@ abstract class AbstractBlock {
|
|||
|
||||
$target = trim( $target );
|
||||
|
||||
if ( IP::isValid( $target ) ) {
|
||||
if ( IPUtils::isValid( $target ) ) {
|
||||
# We can still create a User if it's an IP address, but we need to turn
|
||||
# off validation checking (which would exclude IP addresses)
|
||||
return [
|
||||
User::newFromName( IP::sanitizeIP( $target ), false ),
|
||||
User::newFromName( IPUtils::sanitizeIP( $target ), false ),
|
||||
self::TYPE_IP
|
||||
];
|
||||
|
||||
} elseif ( IP::isValidRange( $target ) ) {
|
||||
} elseif ( IPUtils::isValidRange( $target ) ) {
|
||||
# Can't create a User from an IP range
|
||||
return [ IP::sanitizeRange( $target ), self::TYPE_RANGE ];
|
||||
return [ IPUtils::sanitizeRange( $target ), self::TYPE_RANGE ];
|
||||
}
|
||||
|
||||
# Consider the possibility that this is not a username at all
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ namespace MediaWiki\Block;
|
|||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Hooks;
|
||||
use IP;
|
||||
use LogicException;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
|
|
@ -35,6 +34,7 @@ use User;
|
|||
use WebRequest;
|
||||
use WebResponse;
|
||||
use Wikimedia\IPSet;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* A service class for checking blocks.
|
||||
|
|
@ -215,7 +215,7 @@ class BlockManager {
|
|||
}
|
||||
|
||||
// Soft blocking
|
||||
if ( $isAnon && IP::isInRanges( $ip, $this->options->get( 'SoftBlockRanges' ) ) ) {
|
||||
if ( $isAnon && IPUtils::isInRanges( $ip, $this->options->get( 'SoftBlockRanges' ) ) ) {
|
||||
$blocks[] = new SystemBlock( [
|
||||
'address' => $ip,
|
||||
'reason' => new Message( 'softblockrangesreason', [ $ip ] ),
|
||||
|
|
@ -377,7 +377,7 @@ class BlockManager {
|
|||
private function inDnsBlacklist( $ip, array $bases ) {
|
||||
$found = false;
|
||||
// @todo FIXME: IPv6 ??? (https://bugs.php.net/bug.php?id=33170)
|
||||
if ( IP::isIPv4( $ip ) ) {
|
||||
if ( IPUtils::isIPv4( $ip ) ) {
|
||||
// Reverse IP, T23255
|
||||
$ipReversed = implode( '.', array_reverse( explode( '.', $ip ) ) );
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ use CommentStore;
|
|||
use DeferredUpdates;
|
||||
use Hooks;
|
||||
use Html;
|
||||
use IP;
|
||||
use MediaWiki\Block\Restriction\NamespaceRestriction;
|
||||
use MediaWiki\Block\Restriction\PageRestriction;
|
||||
use MediaWiki\Block\Restriction\Restriction;
|
||||
|
|
@ -39,6 +38,7 @@ use stdClass;
|
|||
use Title;
|
||||
use User;
|
||||
use WebResponse;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\Rdbms\Database;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
|
|
@ -276,12 +276,12 @@ class DatabaseBlock extends AbstractBlock {
|
|||
|
||||
case self::TYPE_IP:
|
||||
$conds['ipb_address'][] = (string)$target;
|
||||
$conds[] = self::getRangeCond( IP::toHex( $target ) );
|
||||
$conds[] = self::getRangeCond( IPUtils::toHex( $target ) );
|
||||
$conds = $db->makeList( $conds, LIST_OR );
|
||||
break;
|
||||
|
||||
case self::TYPE_RANGE:
|
||||
list( $start, $end ) = IP::parseRange( $target );
|
||||
list( $start, $end ) = IPUtils::parseRange( $target );
|
||||
$conds['ipb_address'][] = (string)$target;
|
||||
$conds[] = self::getRangeCond( $start, $end );
|
||||
$conds = $db->makeList( $conds, LIST_OR );
|
||||
|
|
@ -360,8 +360,8 @@ class DatabaseBlock extends AbstractBlock {
|
|||
# This is the number of bits that are allowed to vary in the block, give
|
||||
# or take some floating point errors
|
||||
$target = $block->getTarget();
|
||||
$max = IP::isIPv6( $target ) ? 128 : 32;
|
||||
list( $network, $bits ) = IP::parseCIDR( $target );
|
||||
$max = IPUtils::isIPv6( $target ) ? 128 : 32;
|
||||
list( $network, $bits ) = IPUtils::parseCIDR( $target );
|
||||
$size = $max - $bits;
|
||||
|
||||
# Rank a range block covering a single IP equally with a single-IP block
|
||||
|
|
@ -803,7 +803,7 @@ class DatabaseBlock extends AbstractBlock {
|
|||
wfDebug( "Checking $ip against $wlEntry..." );
|
||||
|
||||
# Is the IP in this range?
|
||||
if ( IP::isInRange( $ip, $wlEntry ) ) {
|
||||
if ( IPUtils::isInRange( $ip, $wlEntry ) ) {
|
||||
wfDebug( " IP $ip matches $wlEntry, not autoblocking\n" );
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -970,9 +970,9 @@ class DatabaseBlock extends AbstractBlock {
|
|||
case self::TYPE_USER:
|
||||
return '';
|
||||
case self::TYPE_IP:
|
||||
return IP::toHex( $this->target );
|
||||
return IPUtils::toHex( $this->target );
|
||||
case self::TYPE_RANGE:
|
||||
list( $start, /*...*/ ) = IP::parseRange( $this->target );
|
||||
list( $start, /*...*/ ) = IPUtils::parseRange( $this->target );
|
||||
return $start;
|
||||
default:
|
||||
throw new MWException( "Block with invalid type" );
|
||||
|
|
@ -989,9 +989,9 @@ class DatabaseBlock extends AbstractBlock {
|
|||
case self::TYPE_USER:
|
||||
return '';
|
||||
case self::TYPE_IP:
|
||||
return IP::toHex( $this->target );
|
||||
return IPUtils::toHex( $this->target );
|
||||
case self::TYPE_RANGE:
|
||||
list( /*...*/, $end ) = IP::parseRange( $this->target );
|
||||
list( /*...*/, $end ) = IPUtils::parseRange( $this->target );
|
||||
return $end;
|
||||
default:
|
||||
throw new MWException( "Block with invalid type" );
|
||||
|
|
@ -1215,7 +1215,7 @@ class DatabaseBlock extends AbstractBlock {
|
|||
# checking for blocks on well-formatted IP addresses (IPv4 and IPv6).
|
||||
# Do not treat private IP spaces as special as it may be desirable for wikis
|
||||
# to block those IP ranges in order to stop misbehaving proxies that spoof XFF.
|
||||
if ( !IP::isValid( $ipaddr ) ) {
|
||||
if ( !IPUtils::isValid( $ipaddr ) ) {
|
||||
continue;
|
||||
}
|
||||
# Don't check trusted IPs (includes local CDNs which will be in every request)
|
||||
|
|
@ -1225,7 +1225,7 @@ class DatabaseBlock extends AbstractBlock {
|
|||
# Check both the original IP (to check against single blocks), as well as build
|
||||
# the clause to check for rangeblocks for the given IP.
|
||||
$conds['ipb_address'][] = $ipaddr;
|
||||
$conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
|
||||
$conds[] = self::getRangeCond( IPUtils::toHex( $ipaddr ) );
|
||||
}
|
||||
|
||||
if ( $conds === [] ) {
|
||||
|
|
@ -1322,7 +1322,7 @@ class DatabaseBlock extends AbstractBlock {
|
|||
}
|
||||
|
||||
foreach ( $ipChain as $checkip ) {
|
||||
$checkipHex = IP::toHex( $checkip );
|
||||
$checkipHex = IPUtils::toHex( $checkip );
|
||||
if ( (string)$block->getTarget() === $checkip ) {
|
||||
if ( $block->isHardblock() ) {
|
||||
$blocksListExact['hard'] = $blocksListExact['hard'] ?: $block;
|
||||
|
|
|
|||
10
includes/cache/FileCacheBase.php
vendored
10
includes/cache/FileCacheBase.php
vendored
|
|
@ -21,6 +21,8 @@
|
|||
* @ingroup Cache
|
||||
*/
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Base class for data storage in the file system.
|
||||
*
|
||||
|
|
@ -233,13 +235,13 @@ abstract class FileCacheBase {
|
|||
# Get a large IP range that should include the user even if that
|
||||
# person's IP address changes
|
||||
$ip = $request->getIP();
|
||||
if ( !IP::isValid( $ip ) ) {
|
||||
if ( !IPUtils::isValid( $ip ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ip = IP::isIPv6( $ip )
|
||||
? IP::sanitizeRange( "$ip/32" )
|
||||
: IP::sanitizeRange( "$ip/16" );
|
||||
$ip = IPUtils::isIPv6( $ip )
|
||||
? IPUtils::sanitizeRange( "$ip/32" )
|
||||
: IPUtils::sanitizeRange( "$ip/16" );
|
||||
|
||||
# Bail out if a request already came from this range...
|
||||
$cache = ObjectCache::getLocalClusterInstance();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
use MediaWiki\ChangeTags\Taggable;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Utility class for creating new RC entries
|
||||
|
|
@ -1104,7 +1105,7 @@ class RecentChange implements Taggable {
|
|||
private static function checkIPAddress( $ip ) {
|
||||
global $wgRequest;
|
||||
if ( $ip ) {
|
||||
if ( !IP::isIPAddress( $ip ) ) {
|
||||
if ( !IPUtils::isIPAddress( $ip ) ) {
|
||||
throw new MWException( "Attempt to write \"" . $ip .
|
||||
"\" as an IP address into recent changes" );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* An HTTP 1.0 client built for the purposes of purging Squid and Varnish.
|
||||
* Uses asynchronous I/O, allowing purges to be done in a highly parallel
|
||||
|
|
@ -147,9 +149,9 @@ class SquidPurgeClient {
|
|||
*/
|
||||
protected function getIP() {
|
||||
if ( $this->ip === null ) {
|
||||
if ( IP::isIPv4( $this->host ) ) {
|
||||
if ( IPUtils::isIPv4( $this->host ) ) {
|
||||
$this->ip = $this->host;
|
||||
} elseif ( IP::isIPv6( $this->host ) ) {
|
||||
} elseif ( IPUtils::isIPv6( $this->host ) ) {
|
||||
throw new MWException( '$wgCdnServers does not support IPv6' );
|
||||
} else {
|
||||
Wikimedia\suppressWarnings();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\ObjectFactory;
|
||||
use Wikimedia\WaitConditionLoop;
|
||||
|
||||
|
|
@ -218,7 +219,7 @@ class EtcdConfig implements Config, LoggerAwareInterface {
|
|||
do {
|
||||
// Pick a random etcd server from dns
|
||||
$server = $dsd->pickServer( $servers );
|
||||
$host = IP::combineHostAndPort( $server['target'], $server['port'] );
|
||||
$host = IPUtils::combineHostAndPort( $server['target'], $server['port'] );
|
||||
// Try to load the config from this particular server
|
||||
$response = $this->fetchAllFromEtcdServer( $host );
|
||||
if ( is_array( $response['config'] ) || $response['retry'] ) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ use Wikimedia\AtEase\AtEase;
|
|||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\ScopedCallback;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Group all the pieces relevant to the context of a request into one instance
|
||||
|
|
@ -521,7 +522,7 @@ class RequestContext implements IContextSource, MutableContext {
|
|||
// Sanity check to avoid sending random cookies for the wrong users.
|
||||
// This method should only called by CLI scripts or by HTTP job runners.
|
||||
throw new MWException( "Sessions can only be imported when none is active." );
|
||||
} elseif ( !IP::isValid( $params['ip'] ) ) {
|
||||
} elseif ( !IPUtils::isValid( $params['ip'] ) ) {
|
||||
throw new MWException( "Invalid client IP address '{$params['ip']}'." );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use MediaWiki\Revision\SlotRecord;
|
|||
use MediaWiki\Revision\SuppressedDataException;
|
||||
use MediaWiki\Storage\SqlBlobStore;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* @ingroup Dump
|
||||
|
|
@ -615,7 +616,7 @@ class XmlDumpWriter {
|
|||
*/
|
||||
function writeContributor( $id, $text, $indent = " " ) {
|
||||
$out = $indent . "<contributor>\n";
|
||||
if ( $id || !IP::isValid( $text ) ) {
|
||||
if ( $id || !IPUtils::isValid( $text ) ) {
|
||||
$out .= $indent . " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
|
||||
$out .= $indent . " " . Xml::element( 'id', null, strval( $id ) ) . "\n";
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Class for updating an MWRestrictions value (which is, currently, basically just an IP address
|
||||
* list).
|
||||
|
|
@ -80,7 +82,7 @@ class HTMLRestrictionsField extends HTMLTextAreaField {
|
|||
// MWRestrictions::newFromArray failed; one of the IP ranges must be invalid
|
||||
$status = Status::newGood();
|
||||
foreach ( explode( "\n", $value ) as $range ) {
|
||||
if ( !\IP::isIPAddress( $range ) ) {
|
||||
if ( !IPUtils::isIPAddress( $range ) ) {
|
||||
$status->fatal( 'restrictionsfield-badip', $range );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Widget\UserInputWidget;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Implements a text input field for user names.
|
||||
|
|
@ -47,7 +48,7 @@ class HTMLUserTextField extends HTMLTextField {
|
|||
// check, if the user exists, if requested
|
||||
( $this->mParams['exists'] && $user->getId() === 0 ) &&
|
||||
// check, if the username is a valid IP address, otherwise save the error message
|
||||
!( $this->mParams['ipallowed'] && IP::isValid( $value ) ) &&
|
||||
!( $this->mParams['ipallowed'] && IPUtils::isValid( $value ) ) &&
|
||||
// check, if the username is a valid IP range, otherwise save the error message
|
||||
!( $this->mParams['iprange'] && ( $rangeError = $this->isValidIPRange( $value ) ) === true )
|
||||
) {
|
||||
|
|
@ -63,33 +64,33 @@ class HTMLUserTextField extends HTMLTextField {
|
|||
protected function isValidIPRange( $value ) {
|
||||
$cidrIPRanges = $this->mParams['iprangelimits'];
|
||||
|
||||
if ( !IP::isValidRange( $value ) ) {
|
||||
if ( !IPUtils::isValidRange( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
list( $ip, $range ) = explode( '/', $value, 2 );
|
||||
|
||||
if (
|
||||
( IP::isIPv4( $ip ) && $cidrIPRanges['IPv4'] == 32 ) ||
|
||||
( IP::isIPv6( $ip ) && $cidrIPRanges['IPv6'] == 128 )
|
||||
( IPUtils::isIPv4( $ip ) && $cidrIPRanges['IPv4'] == 32 ) ||
|
||||
( IPUtils::isIPv6( $ip ) && $cidrIPRanges['IPv6'] == 128 )
|
||||
) {
|
||||
// Range block effectively disabled
|
||||
return $this->msg( 'ip_range_toolow' )->parse();
|
||||
}
|
||||
|
||||
if (
|
||||
( IP::isIPv4( $ip ) && $range > 32 ) ||
|
||||
( IP::isIPv6( $ip ) && $range > 128 )
|
||||
( IPUtils::isIPv4( $ip ) && $range > 32 ) ||
|
||||
( IPUtils::isIPv6( $ip ) && $range > 128 )
|
||||
) {
|
||||
// Dodgy range
|
||||
return $this->msg( 'ip_range_invalid' )->parse();
|
||||
}
|
||||
|
||||
if ( IP::isIPv4( $ip ) && $range < $cidrIPRanges['IPv4'] ) {
|
||||
if ( IPUtils::isIPv4( $ip ) && $range < $cidrIPRanges['IPv4'] ) {
|
||||
return $this->msg( 'ip_range_exceeded', $cidrIPRanges['IPv4'] )->parse();
|
||||
}
|
||||
|
||||
if ( IP::isIPv6( $ip ) && $range < $cidrIPRanges['IPv6'] ) {
|
||||
if ( IPUtils::isIPv6( $ip ) && $range < $cidrIPRanges['IPv6'] ) {
|
||||
return $this->msg( 'ip_range_exceeded', $cidrIPRanges['IPv6'] )->parse();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
* @ingroup Installer
|
||||
*/
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
class WebInstallerOptions extends WebInstallerPage {
|
||||
|
||||
/**
|
||||
|
|
@ -547,7 +549,7 @@ class WebInstallerOptions extends WebInstallerPage {
|
|||
foreach ( $memcServers as $server ) {
|
||||
$memcParts = explode( ":", $server, 2 );
|
||||
if ( !isset( $memcParts[0] )
|
||||
|| ( !IP::isValid( $memcParts[0] )
|
||||
|| ( !IPUtils::isValid( $memcParts[0] )
|
||||
&& ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
|
||||
) {
|
||||
$this->parent->showError( 'config-memcache-badip', $memcParts[0] );
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* A generic class to send a message over UDP
|
||||
*
|
||||
|
|
@ -58,7 +60,7 @@ class UDPTransport {
|
|||
$domain = AF_INET6;
|
||||
} elseif ( preg_match( '!^udp:(?://)?([a-zA-Z0-9.-]+):(\d+)(?:/(.*))?$!', $info, $m ) ) {
|
||||
$host = $m[1];
|
||||
if ( !IP::isIPv4( $host ) ) {
|
||||
if ( !IPUtils::isIPv4( $host ) ) {
|
||||
$host = gethostbyname( $host );
|
||||
}
|
||||
$port = intval( $m[2] );
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ namespace Wikimedia\Rdbms;
|
|||
|
||||
use mysqli;
|
||||
use mysqli_result;
|
||||
use IP;
|
||||
use stdClass;
|
||||
use Wikimedia\AtEase\AtEase;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Database abstraction object for PHP extension mysqli.
|
||||
|
|
@ -72,7 +72,7 @@ class DatabaseMysqli extends DatabaseMysqlBase {
|
|||
// We need to parse the port or socket path out of $realServer
|
||||
$port = null;
|
||||
$socket = null;
|
||||
$hostAndPort = IP::splitHostAndPort( $realServer );
|
||||
$hostAndPort = IPUtils::splitHostAndPort( $realServer );
|
||||
if ( $hostAndPort ) {
|
||||
$realServer = $hostAndPort[0];
|
||||
if ( $hostAndPort[1] ) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use MediaWiki\Linker\LinkTarget;
|
|||
use MediaWiki\User\UserIdentity;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Class for creating new log entries and inserting them into the database.
|
||||
|
|
@ -334,7 +335,7 @@ class ManualLogEntry extends LogEntryBase implements Taggable {
|
|||
if ( $user->isAnon() ) {
|
||||
// "MediaWiki default" and friends may have
|
||||
// no IP address in their name
|
||||
if ( IP::isIPAddress( $user->getName() ) ) {
|
||||
if ( IPUtils::isIPAddress( $user->getName() ) ) {
|
||||
$ip = $user->getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use Wikimedia\Rdbms\IDatabase;
|
|||
use MediaWiki\Revision\MutableRevisionRecord;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Class for viewing MediaWiki article and history.
|
||||
|
|
@ -980,7 +981,7 @@ class Article implements Page {
|
|||
$specificTarget = null;
|
||||
$vagueTarget = null;
|
||||
$titleText = $this->getTitle()->getText();
|
||||
if ( IP::isValid( $titleText ) ) {
|
||||
if ( IPUtils::isValid( $titleText ) ) {
|
||||
$vagueTarget = $titleText;
|
||||
} else {
|
||||
$specificTarget = $titleText;
|
||||
|
|
@ -1171,7 +1172,7 @@ class Article implements Page {
|
|||
public function showViewFooter() {
|
||||
# check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
|
||||
if ( $this->getTitle()->getNamespace() == NS_USER_TALK
|
||||
&& IP::isValid( $this->getTitle()->getText() )
|
||||
&& IPUtils::isValid( $this->getTitle()->getText() )
|
||||
) {
|
||||
$this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ use MediaWiki\Storage\DerivedPageDataUpdater;
|
|||
use MediaWiki\Storage\PageUpdater;
|
||||
use MediaWiki\Storage\RevisionSlotsUpdate;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\Rdbms\FakeResultWrapper;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\LoadBalancer;
|
||||
|
|
@ -2953,7 +2954,7 @@ class WikiPage implements Page, IDBAccessObject {
|
|||
|
||||
// Keep track of IP edits, so that the corresponding rows can
|
||||
// be deleted in the ip_changes table.
|
||||
if ( (int)$row->rev_user === 0 && IP::isValid( $row->rev_user_text ) ) {
|
||||
if ( (int)$row->rev_user === 0 && IPUtils::isValid( $row->rev_user_text ) ) {
|
||||
$ipRevIds[] = $row->rev_id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use MediaWiki\Linker\LinkTarget;
|
|||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Special\SpecialPageFactory;
|
||||
use Psr\Log\NullLogger;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\ScopedCallback;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
|
@ -2157,7 +2158,7 @@ class Parser {
|
|||
$userinfo = '(?:[a-z0-9\-._~!$&\'()*+,;=:]|%[0-9a-f]{2})*';
|
||||
$ipv6Host = '\\[((?:[0-9a-f:]|%3[0-A]|%[46][1-6])+)\\]';
|
||||
if ( preg_match( "<^(?:{$scheme})?//(?:{$userinfo}@)?{$ipv6Host}(?:[:/?#].*|)$>i", $url, $m ) &&
|
||||
IP::isValid( rawurldecode( $m[1] ) )
|
||||
IPUtils::isValid( rawurldecode( $m[1] ) )
|
||||
) {
|
||||
$isIPv6 = rawurldecode( $m[1] );
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ use MediaWiki\Block\Restriction\PageRestriction;
|
|||
use MediaWiki\Block\Restriction\NamespaceRestriction;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* A special page that allows users with 'block' right to block users from
|
||||
|
|
@ -626,7 +627,7 @@ class SpecialBlock extends FormSpecialPage {
|
|||
protected static function getTargetUserTitle( $target ) {
|
||||
if ( $target instanceof User ) {
|
||||
return $target->getUserPage();
|
||||
} elseif ( IP::isIPAddress( $target ) ) {
|
||||
} elseif ( IPUtils::isIPAddress( $target ) ) {
|
||||
return Title::makeTitleSafe( NS_USER, $target );
|
||||
}
|
||||
|
||||
|
|
@ -735,26 +736,26 @@ class SpecialBlock extends FormSpecialPage {
|
|||
list( $ip, $range ) = explode( '/', $target, 2 );
|
||||
|
||||
if (
|
||||
( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
|
||||
( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
|
||||
( IPUtils::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
|
||||
( IPUtils::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
|
||||
) {
|
||||
// Range block effectively disabled
|
||||
$status->fatal( 'range_block_disabled' );
|
||||
}
|
||||
|
||||
if (
|
||||
( IP::isIPv4( $ip ) && $range > 32 ) ||
|
||||
( IP::isIPv6( $ip ) && $range > 128 )
|
||||
( IPUtils::isIPv4( $ip ) && $range > 32 ) ||
|
||||
( IPUtils::isIPv6( $ip ) && $range > 128 )
|
||||
) {
|
||||
// Dodgy range
|
||||
$status->fatal( 'ip_range_invalid' );
|
||||
}
|
||||
|
||||
if ( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
|
||||
if ( IPUtils::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
|
||||
$status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
|
||||
}
|
||||
|
||||
if ( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
|
||||
if ( IPUtils::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
|
||||
$status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
|
||||
}
|
||||
} elseif ( $type == DatabaseBlock::TYPE_IP ) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
use MediaWiki\Block\DatabaseBlock;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
|
|
@ -159,7 +160,7 @@ class SpecialBlockList extends SpecialPage {
|
|||
|
||||
case DatabaseBlock::TYPE_IP:
|
||||
case DatabaseBlock::TYPE_RANGE:
|
||||
list( $start, $end ) = IP::parseRange( $target );
|
||||
list( $start, $end ) = IPUtils::parseRange( $target );
|
||||
$conds[] = $db->makeList(
|
||||
[
|
||||
'ipb_address' => $target,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
use MediaWiki\Block\DatabaseBlock;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Special:Contributions, show user contributions in a paged list
|
||||
|
|
@ -112,7 +113,7 @@ class SpecialContributions extends IncludableSpecialPage {
|
|||
|
||||
# For IP ranges, we want the contributionsSub, but not the skin-dependent
|
||||
# links under 'Tools', which may include irrelevant links like 'Logs'.
|
||||
if ( !IP::isValidRange( $target ) ) {
|
||||
if ( !IPUtils::isValidRange( $target ) ) {
|
||||
$this->getSkin()->setRelevantUser( $userObj );
|
||||
}
|
||||
}
|
||||
|
|
@ -231,10 +232,10 @@ class SpecialContributions extends IncludableSpecialPage {
|
|||
$out->addHTML( $this->getForm( $this->opts ) );
|
||||
}
|
||||
|
||||
if ( IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
|
||||
if ( IPUtils::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
|
||||
// Valid range, but outside CIDR limit.
|
||||
$limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
|
||||
$limit = $limits[ IP::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
|
||||
$limit = $limits[ IPUtils::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
|
||||
$out->addWikiMsg( 'sp-contributions-outofrange', $limit );
|
||||
} elseif ( !$pager->getNumRows() ) {
|
||||
$out->addWikiMsg( 'nocontribs', $target );
|
||||
|
|
@ -276,9 +277,9 @@ class SpecialContributions extends IncludableSpecialPage {
|
|||
$out->preventClickjacking( $pager->getPreventClickjacking() );
|
||||
|
||||
# Show the appropriate "footer" message - WHOIS tools, etc.
|
||||
if ( IP::isValidRange( $target ) ) {
|
||||
if ( IPUtils::isValidRange( $target ) ) {
|
||||
$message = 'sp-contributions-footer-anon-range';
|
||||
} elseif ( IP::isIPAddress( $target ) ) {
|
||||
} elseif ( IPUtils::isIPAddress( $target ) ) {
|
||||
$message = 'sp-contributions-footer-anon';
|
||||
} elseif ( $userObj->isAnon() ) {
|
||||
// No message for non-existing users
|
||||
|
|
@ -394,8 +395,8 @@ class SpecialContributions extends IncludableSpecialPage {
|
|||
$username = $target->getName();
|
||||
$userpage = $target->getUserPage();
|
||||
$talkpage = $target->getTalkPage();
|
||||
$isIP = IP::isValid( $username );
|
||||
$isRange = IP::isValidRange( $username );
|
||||
$isIP = IPUtils::isValid( $username );
|
||||
$isRange = IPUtils::isValidRange( $username );
|
||||
|
||||
$linkRenderer = $sp->getLinkRenderer();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
use MediaWiki\Block\DatabaseBlock;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Implements Special:DeletedContributions to display archived revisions
|
||||
|
|
@ -114,7 +115,7 @@ class SpecialDeletedContributions extends SpecialPage {
|
|||
|
||||
# If there were contributions, and it was a valid user or IP, show
|
||||
# the appropriate "footer" message - WHOIS tools, etc.
|
||||
$message = IP::isIPAddress( $target ) ?
|
||||
$message = IPUtils::isIPAddress( $target ) ?
|
||||
'sp-contributions-footer-anon' :
|
||||
'sp-contributions-footer';
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinkRenderer;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\Rdbms\IResultWrapper;
|
||||
use Wikimedia\Rdbms\FakeResultWrapper;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -382,7 +383,7 @@ class ContribsPager extends RangeChronologicalPager {
|
|||
return false;
|
||||
}
|
||||
|
||||
list( $start, $end ) = IP::parseRange( $ip );
|
||||
list( $start, $end ) = IPUtils::parseRange( $ip );
|
||||
|
||||
return 'ipc_hex BETWEEN ' . $db->addQuotes( $start ) . ' AND ' . $db->addQuotes( $end );
|
||||
}
|
||||
|
|
@ -397,11 +398,11 @@ class ContribsPager extends RangeChronologicalPager {
|
|||
public function isQueryableRange( $ipRange ) {
|
||||
$limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
|
||||
|
||||
$bits = IP::parseCIDR( $ipRange )[1];
|
||||
$bits = IPUtils::parseCIDR( $ipRange )[1];
|
||||
if (
|
||||
( $bits === false ) ||
|
||||
( IP::isIPv4( $ipRange ) && $bits < $limits['IPv4'] ) ||
|
||||
( IP::isIPv6( $ipRange ) && $bits < $limits['IPv6'] )
|
||||
( IPUtils::isIPv4( $ipRange ) && $bits < $limits['IPv4'] ) ||
|
||||
( IPUtils::isIPv6( $ipRange ) && $bits < $limits['IPv6'] )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
use MediaWiki\Interwiki\InterwikiLookup;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* A codec for MediaWiki page titles.
|
||||
|
|
@ -478,7 +479,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
|
|||
// them all is silly and having some show the edits and others not is
|
||||
// inconsistent. Same for talk/userpages. Keep them normalized instead.
|
||||
if ( $parts['namespace'] == NS_USER || $parts['namespace'] == NS_USER_TALK ) {
|
||||
$dbkey = IP::sanitizeIP( $dbkey );
|
||||
$dbkey = IPUtils::sanitizeIP( $dbkey );
|
||||
}
|
||||
|
||||
// Any remaining initial :s are illegal.
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use MediaWiki\User\UserIdentity;
|
|||
use MediaWiki\Logger\LoggerFactory;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\IPSet;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\ScopedCallback;
|
||||
use Wikimedia\Rdbms\Database;
|
||||
use Wikimedia\Rdbms\DBExpectedError;
|
||||
|
|
@ -946,7 +947,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
*/
|
||||
public static function isIP( $name ) {
|
||||
return preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/', $name )
|
||||
|| IP::isIPv6( $name );
|
||||
|| IPUtils::isIPv6( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -956,7 +957,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
* @return bool
|
||||
*/
|
||||
public function isIPRange() {
|
||||
return IP::isValidRange( $this->mName );
|
||||
return IPUtils::isValidRange( $this->mName );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1840,7 +1841,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
|
||||
$found = false;
|
||||
// @todo FIXME: IPv6 ??? (https://bugs.php.net/bug.php?id=33170)
|
||||
if ( IP::isIPv4( $ip ) ) {
|
||||
if ( IPUtils::isIPv4( $ip ) ) {
|
||||
// Reverse IP, T23255
|
||||
$ipReversed = implode( '.', array_reverse( explode( '.', $ip ) ) );
|
||||
|
||||
|
|
@ -1902,8 +1903,8 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
|
||||
// backward compatibility: move all ip addresses in keys to values
|
||||
foreach ( $wgProxyList as $key => $value ) {
|
||||
$keyIsIP = IP::isIPAddress( $key );
|
||||
$valueIsIP = IP::isIPAddress( $value );
|
||||
$keyIsIP = IPUtils::isIPAddress( $key );
|
||||
$valueIsIP = IPUtils::isIPAddress( $value );
|
||||
if ( $keyIsIP && !$valueIsIP ) {
|
||||
$deprecatedIPEntries[] = $key;
|
||||
$resultProxyList[] = $key;
|
||||
|
|
@ -1933,7 +1934,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
*/
|
||||
public function isPingLimitable() {
|
||||
global $wgRateLimitsExcludedIPs;
|
||||
if ( IP::isInRanges( $this->getRequest()->getIP(), $wgRateLimitsExcludedIPs ) ) {
|
||||
if ( IPUtils::isInRanges( $this->getRequest()->getIP(), $wgRateLimitsExcludedIPs ) ) {
|
||||
// No other good way currently to disable rate limits
|
||||
// for specific IPs. :P
|
||||
// But this is a crappy hack and should die.
|
||||
|
|
@ -2006,7 +2007,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
// subnet-based limits
|
||||
if ( isset( $limits['subnet'] ) ) {
|
||||
$ip = $this->getRequest()->getIP();
|
||||
$subnet = IP::getSubnet( $ip );
|
||||
$subnet = IPUtils::getSubnet( $ip );
|
||||
if ( $subnet !== false ) {
|
||||
$keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
|
||||
}
|
||||
|
|
@ -2053,7 +2054,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
// subnet-based limits for all ping-limitable users
|
||||
if ( isset( $limits['subnet-all'] ) ) {
|
||||
$ip = $this->getRequest()->getIP();
|
||||
$subnet = IP::getSubnet( $ip );
|
||||
$subnet = IPUtils::getSubnet( $ip );
|
||||
if ( $subnet !== false ) {
|
||||
// ignore if user limit is more permissive
|
||||
if ( $isNewbie || $userLimit === false
|
||||
|
|
@ -2190,7 +2191,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
return $this->mGlobalBlock ?: null;
|
||||
}
|
||||
// User is already an IP?
|
||||
if ( IP::isIPAddress( $this->getName() ) ) {
|
||||
if ( IPUtils::isIPAddress( $this->getName() ) ) {
|
||||
$ip = $this->getName();
|
||||
} elseif ( !$ip ) {
|
||||
$ip = $this->getRequest()->getIP();
|
||||
|
|
@ -2288,7 +2289,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
$this->load();
|
||||
if ( $this->mName === false ) {
|
||||
// Clean up IPs
|
||||
$this->mName = IP::sanitizeIP( $this->getRequest()->getIP() );
|
||||
$this->mName = IPUtils::sanitizeIP( $this->getRequest()->getIP() );
|
||||
}
|
||||
|
||||
return $this->mName;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* A class to check request restrictions expressed as a JSON object
|
||||
*/
|
||||
|
|
@ -86,7 +88,7 @@ class MWRestrictions {
|
|||
throw new InvalidArgumentException( 'IPAddresses is not an array' );
|
||||
}
|
||||
foreach ( $restrictions['IPAddresses'] as $ip ) {
|
||||
if ( !\IP::isIPAddress( $ip ) ) {
|
||||
if ( !IPUtils::isIPAddress( $ip ) ) {
|
||||
throw new InvalidArgumentException( "Invalid IP address: $ip" );
|
||||
}
|
||||
}
|
||||
|
|
@ -137,7 +139,7 @@ class MWRestrictions {
|
|||
*/
|
||||
public function checkIP( $ip ) {
|
||||
foreach ( $this->ipAddresses as $range ) {
|
||||
if ( \IP::isInRange( $ip, $range ) ) {
|
||||
if ( IPUtils::isInRange( $ip, $range ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Maintenance script that displays replication lag times.
|
||||
|
|
@ -54,7 +55,7 @@ class GetLagTimes extends Maintenance {
|
|||
$lags = $lb->getLagTimes();
|
||||
foreach ( $lags as $serverIndex => $lag ) {
|
||||
$host = $lb->getServerName( $serverIndex );
|
||||
if ( IP::isValid( $host ) ) {
|
||||
if ( IPUtils::isValid( $host ) ) {
|
||||
$ip = $host;
|
||||
$host = gethostbyaddr( $host );
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
use MediaWiki\Shell\Shell;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
|
|
@ -126,7 +127,7 @@ class MysqlMaintenance extends Maintenance {
|
|||
|
||||
// Split host and port as in DatabaseMysqli::mysqlConnect()
|
||||
$realServer = $info['host'];
|
||||
$hostAndPort = IP::splitHostAndPort( $realServer );
|
||||
$hostAndPort = IPUtils::splitHostAndPort( $realServer );
|
||||
$socket = false;
|
||||
$port = false;
|
||||
if ( $hostAndPort ) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Maintenance script that will find all rows in the revision table where
|
||||
|
|
@ -116,11 +117,11 @@ TEXT
|
|||
$insertRows = [];
|
||||
foreach ( $rows as $row ) {
|
||||
// Make sure this is really an IP, e.g. not maintenance user or imported revision.
|
||||
if ( IP::isValid( $row->rev_user_text ) ) {
|
||||
if ( IPUtils::isValid( $row->rev_user_text ) ) {
|
||||
$insertRows[] = [
|
||||
'ipc_rev_id' => $row->rev_id,
|
||||
'ipc_rev_timestamp' => $row->rev_timestamp,
|
||||
'ipc_hex' => IP::toHex( $row->rev_user_text ),
|
||||
'ipc_hex' => IPUtils::toHex( $row->rev_user_text ),
|
||||
];
|
||||
|
||||
$attempted++;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
use MediaWiki\Auth\AuthManager;
|
||||
use MediaWiki\Auth\Throttler;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ class ResetAuthenticationThrottle extends Maintenance {
|
|||
$this->fatalError( '--usename and --ip are both required when using --login!' );
|
||||
} elseif ( $forSignup && $ip === null ) {
|
||||
$this->fatalError( '--ip is required when using --signup!' );
|
||||
} elseif ( $ip !== null && !IP::isValid( $ip ) ) {
|
||||
} elseif ( $ip !== null && !IPUtils::isValid( $ip ) ) {
|
||||
$this->fatalError( "Not a valid IP: $ip" );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -493,7 +493,7 @@ CREATE TABLE /*_*/ip_changes (
|
|||
-- The timestamp of the revision
|
||||
ipc_rev_timestamp binary(14) NOT NULL DEFAULT '',
|
||||
|
||||
-- Hex representation of the IP address, as returned by IP::toHex()
|
||||
-- Hex representation of the IP address, as returned by Wikimedia\IPUtils::toHex()
|
||||
-- For IPv4 it will resemble: ABCD1234
|
||||
-- For IPv6: v6-ABCD1234000000000000000000000000
|
||||
-- BETWEEN is then used to identify revisions within a given range
|
||||
|
|
|
|||
|
|
@ -441,7 +441,7 @@ util = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Note: borrows from IP::isIPv4
|
||||
* Note: borrows from \Wikimedia\IPUtils::isIPv4
|
||||
*
|
||||
* @param {string} address
|
||||
* @param {boolean} [allowBlock=false]
|
||||
|
|
@ -462,7 +462,7 @@ util = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Note: borrows from IP::isIPv6
|
||||
* Note: borrows from \Wikimedia\IPUtils::isIPv6
|
||||
*
|
||||
* @param {string} address
|
||||
* @param {boolean} [allowBlock=false]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use MediaWiki\Revision\RevisionStore;
|
|||
use MediaWiki\Revision\IncompleteRevisionException;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* RevisionDbTestBase contains test cases for the Revision class that have Database interactions.
|
||||
|
|
@ -740,7 +741,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
|
|||
$res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $orig->getId() ] );
|
||||
$row = $res->fetchObject();
|
||||
|
||||
$this->assertEquals( IP::toHex( $ip ), $row->ipc_hex );
|
||||
$this->assertEquals( IPUtils::toHex( $ip ), $row->ipc_hex );
|
||||
$this->assertEquals(
|
||||
$orig->getTimestamp(),
|
||||
wfTimestamp( TS_MW, $row->ipc_rev_timestamp )
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use MediaWiki\Block\DatabaseBlock;
|
|||
use MediaWiki\Block\Restriction\PageRestriction;
|
||||
use MediaWiki\Block\Restriction\NamespaceRestriction;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* @group Database
|
||||
|
|
@ -369,9 +370,9 @@ class DatabaseBlockTest extends MediaWikiLangTestCase {
|
|||
$target = $insBlock['target'];
|
||||
|
||||
if ( $insBlock['type'] === DatabaseBlock::TYPE_IP ) {
|
||||
$target = User::newFromName( IP::sanitizeIP( $target ), false )->getName();
|
||||
$target = User::newFromName( IPUtils::sanitizeIP( $target ), false )->getName();
|
||||
} elseif ( $insBlock['type'] === DatabaseBlock::TYPE_RANGE ) {
|
||||
$target = IP::sanitizeRange( $target );
|
||||
$target = IPUtils::sanitizeRange( $target );
|
||||
}
|
||||
|
||||
$block = new DatabaseBlock();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use Wikimedia\IPUtils;
|
||||
|
||||
/**
|
||||
* Base class for tests of PageArchive against different database schemas.
|
||||
|
|
@ -177,7 +178,7 @@ abstract class PageArchiveTestBase extends MediaWikiTestCase {
|
|||
// Should be back in ip_changes
|
||||
$row = $dbr->selectRow( 'ip_changes', [ 'ipc_hex' ], [ 'ipc_rev_id' => $this->ipRev->getId() ] );
|
||||
$this->assertNotFalse( $row, 'row exists in ip_changes table' );
|
||||
$this->assertEquals( IP::toHex( $this->ipEditor ), $row->ipc_hex );
|
||||
$this->assertEquals( IPUtils::toHex( $this->ipEditor ), $row->ipc_hex );
|
||||
}
|
||||
|
||||
abstract protected function getExpectedArchiveRows();
|
||||
|
|
|
|||
Loading…
Reference in a new issue