Index: trunk/phase3/includes/Block.php |
— | — | @@ -813,35 +813,10 @@ |
814 | 814 | * For example, 127.111.113.151/24 -> 127.111.113.0/24 |
815 | 815 | * @param $range String: IP address to normalize |
816 | 816 | * @return string |
| 817 | + * @deprecated since 1.18, call IP::sanitizeRange() directly |
817 | 818 | */ |
818 | 819 | public static function normaliseRange( $range ) { |
819 | | - $parts = explode( '/', $range ); |
820 | | - if ( count( $parts ) == 2 ) { |
821 | | - // IPv6 |
822 | | - if ( IP::isIPv6( $range ) && $parts[1] >= 64 && $parts[1] <= 128 ) { |
823 | | - $bits = $parts[1]; |
824 | | - $ipint = IP::toUnsigned( $parts[0] ); |
825 | | - # Native 32 bit functions WON'T work here!!! |
826 | | - # Convert to a padded binary number |
827 | | - $network = wfBaseConvert( $ipint, 10, 2, 128 ); |
828 | | - # Truncate the last (128-$bits) bits and replace them with zeros |
829 | | - $network = str_pad( substr( $network, 0, $bits ), 128, 0, STR_PAD_RIGHT ); |
830 | | - # Convert back to an integer |
831 | | - $network = wfBaseConvert( $network, 2, 10 ); |
832 | | - # Reform octet address |
833 | | - $newip = IP::toOctet( $network ); |
834 | | - $range = "$newip/{$parts[1]}"; |
835 | | - } // IPv4 |
836 | | - elseif ( IP::isIPv4( $range ) && $parts[1] >= 16 && $parts[1] <= 32 ) { |
837 | | - $shift = 32 - $parts[1]; |
838 | | - $ipint = IP::toUnsigned( $parts[0] ); |
839 | | - $ipint = $ipint >> $shift << $shift; |
840 | | - $newip = long2ip( $ipint ); |
841 | | - $range = "$newip/{$parts[1]}"; |
842 | | - } |
843 | | - } |
844 | | - |
845 | | - return $range; |
| 820 | + return IP::sanitizeRange( $range ); |
846 | 821 | } |
847 | 822 | |
848 | 823 | /** |
Index: trunk/phase3/includes/IP.php |
— | — | @@ -614,4 +614,17 @@ |
615 | 615 | |
616 | 616 | return null; // give up |
617 | 617 | } |
| 618 | + |
| 619 | + /** |
| 620 | + * Gets rid of uneeded numbers in quad-dotted/octet IP strings |
| 621 | + * For example, 127.111.113.151/24 -> 127.111.113.0/24 |
| 622 | + * @param $range String: IP address to normalize |
| 623 | + * @return string |
| 624 | + */ |
| 625 | + public static function sanitizeRange( $range ){ |
| 626 | + list( /*...*/, $bits ) = self::parseCIDR( $range ); |
| 627 | + list( $start, /*...*/ ) = self::parseRange( $range ); |
| 628 | + $start = self::formatHex( $start ); |
| 629 | + return "$start/$bits"; |
| 630 | + } |
618 | 631 | } |