On 22/11/06, werdna(a)svn.wikimedia.org <werdna(a)svn.wikimedia.org> wrote:
> Revision: 17847
> Author: werdna
> Date: 2006-11-22 03:51:49 -0800 (Wed, 22 Nov 2006)
>
> Log Message:
> -----------
> * (bug 7883) Added autoblock whitelisting feature, using which specific ranges can be protected from autoblocking. These ranges are specified, in list format, in the autoblock_whitelist system message.
Is this the best place for this to be specified?
> +* (bug 7883) Added autoblock whitelisting feature, using which specific ranges
> + can be protected from autoblocking. These ranges are specified, in list format,
> + in the autoblock_whitelist system message.
Nice and verbose. :D
> + $wlEntry = substr($line, 1);
> + $wlEntry = trim($wlEntry);
Investigate the trim() parameters a bit more, this should be able to
be cut down to one line.
> +/**
> + * Get the start and end of a range.
> + * @param $range The range to get the start and end for.
> + * @return array An array with the first element as the start of the range, as a long, and the second element as the end of the range, also as a long.
> + *
> + */
> +function wfRangeStartEnd( $range ) {
> + list( $network, $bits ) = wfParseCIDR( $range );
> + if ( $network !== false ) {
> + $start = sprintf( '%08X', $network );
> + $end = sprintf( '%08X', $network + (1 << (32 - $bits)) - 1 );
> + return array($start, $end);
> + }
> + return false;
> +}
Wouldn't a better place for this be as a static function of the IP
class? (And isn't wfParseCIDR deprecated in favour of such a
function?)
> +/**
> + * Determine if a given integer IPv4 address is in a given CIDR network
> + * @param $addr The address to check against the given range.
> + * @param $range The range to check the given address against.
> + * @return bool Whether or not the given address is in the given range.
> + */
> +function wfIsAddressInRange( $addr, $range ) {
> + $unsignedIP = IP::toUnsigned($addr);
> + $startend = wfRangeStartEnd($range);
> + $start = $startend[0];
> + $end = $startend[1];
> +
> + return (($unsignedIP >= $start) && ($unsignedip <= $end));
> +}
Ditto above.
Rob Church