if ( $block->getType() == self::TYPE_RANGE ) {
# This is the number of bits that are allowed to vary in the block, give
# or take some floating point errors
- $prefix = 'v6-';
- $end = Wikimedia\base_convert( ltrim( $block->getRangeEnd(), $prefix ), 16, 10 );
- $start = Wikimedia\base_convert( ltrim( $block->getRangeStart(), $prefix ), 16, 10 );
- $size = log( $end - $start + 1, 2 );
+ $target = $block->getTarget();
+ $max = IP::isIPv6( $target ) ? 128 : 32;
+ list( $network, $bits ) = IP::parseCIDR( $target );
+ $size = $max - $bits;
# Rank a range block covering a single IP equally with a single-IP block
- $score = self::TYPE_RANGE - 1 + ( $size / 128 );
+ $score = self::TYPE_RANGE - 1 + ( $size / $max );
} else {
$score = $block->getType();
'0.0.0.0',
'0.0.0.0'
],
- 'Blocks to wide IPv6 range and IP' => [
- [ '0:0:0:0:0:0:0:0/19', '0:0:0:0:0:0:0:0' ],
- '0:0:0:0:0:0:0:0',
- '0:0:0:0:0:0:0:0'
- ],
'Blocks to narrow IPv4 range and IP' => [
[ '0.0.0.0/31', '0.0.0.0' ],
'0.0.0.0',
'0.0.0.0'
],
+ 'Blocks to wide IPv6 range and IP' => [
+ [ '0:0:0:0:0:0:0:0/19', '0:0:0:0:0:0:0:0' ],
+ '0:0:0:0:0:0:0:0',
+ '0:0:0:0:0:0:0:0'
+ ],
'Blocks to narrow IPv6 range and IP' => [
[ '0:0:0:0:0:0:0:0/127', '0:0:0:0:0:0:0:0' ],
'0:0:0:0:0:0:0:0',
'0:0:0:0:0:0:0:0'
],
+ 'Blocks to wide IPv6 range and IP, large numbers' => [
+ [ '2000:DEAD:BEEF:A:0:0:0:0/19', '2000:DEAD:BEEF:A:0:0:0:0' ],
+ '2000:DEAD:BEEF:A:0:0:0:0',
+ '2000:DEAD:BEEF:A:0:0:0:0'
+ ],
+ 'Blocks to narrow IPv6 range and IP, large numbers' => [
+ [ '2000:DEAD:BEEF:A:0:0:0:0/127', '2000:DEAD:BEEF:A:0:0:0:0' ],
+ '2000:DEAD:BEEF:A:0:0:0:0',
+ '2000:DEAD:BEEF:A:0:0:0:0'
+ ],
];
}