From a95684e56215f5dcdcc76e754d57793c35c514f6 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 9 Oct 2008 21:49:20 +0000 Subject: [PATCH] (bug 14634) Show range blocks for IPs --- includes/specials/SpecialIpblocklist.php | 23 +++++++++++++++++------ languages/messages/MessagesEn.php | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/specials/SpecialIpblocklist.php b/includes/specials/SpecialIpblocklist.php index 6787a25c08..9e29c23276 100644 --- a/includes/specials/SpecialIpblocklist.php +++ b/includes/specials/SpecialIpblocklist.php @@ -78,6 +78,7 @@ class IPUnblockForm { $this->hideuserblocks = $wgRequest->getBool( 'hideuserblocks' ); $this->hidetempblocks = $wgRequest->getBool( 'hidetempblocks' ); $this->hideaddressblocks = $wgRequest->getBool( 'hideaddressblocks' ); + $this->scanRange = $wgRequest->getBool( 'range' ); } /** @@ -162,8 +163,7 @@ class IPUnblockForm { * @return array array(message key, parameters) on failure, empty array on success */ - static function doUnblock(&$id, &$ip, &$reason, &$range = null) - { + static function doUnblock(&$id, &$ip, &$reason, &$range = null) { if ( $id ) { $block = Block::newFromID( $id ); if ( !$block ) { @@ -245,10 +245,20 @@ class IPUnblockForm { // No extra conditions } elseif ( substr( $this->ip, 0, 1 ) == '#' ) { $conds['ipb_id'] = substr( $this->ip, 1 ); + // Single IPs } elseif ( IP::isIPAddress($this->ip) && strpos($this->ip,'/') === false ) { - $conds['ipb_address'] = IP::sanitizeIP($this->ip); + if( $this->scanRange && $iaddr = IP::toHex($this->ip) ) { + # Only scan ranges which start in this /16, this improves search speed + # Blocks should not cross a /16 boundary. + $range = substr( $iaddr, 0, 4 ); + $conds[] = "(ipb_address = '" . IP::sanitizeIP($this->ip) . "') OR + (ipb_range_start LIKE '$range%' AND ipb_range_start <= '$iaddr' AND ipb_range_end >= '$iaddr')"; + } else { + $conds['ipb_address'] = IP::sanitizeIP($this->ip); + } $conds['ipb_auto'] = 0; - } elseif( IP::isIPAddress($this->ip) ) { + // IP range + } elseif ( IP::isIPAddress($this->ip) ) { $conds['ipb_address'] = Block::normaliseRange( $this->ip ); $conds['ipb_auto'] = 0; } else { @@ -298,8 +308,9 @@ class IPUnblockForm { Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'ipblocklist-legend' ) ) . Xml::inputLabel( wfMsg( 'ipblocklist-username' ), 'ip', 'ip', /* size */ false, $this->ip ) . - ' ' . - Xml::submitButton( wfMsg( 'ipblocklist-submit' ) ) . + '
' . + Xml::checkLabel( wfMsg('ipblocklist-scanrange'), 'range', 'range', $this->scanRange ) . + ' ' . Xml::submitButton( wfMsg( 'ipblocklist-submit' ) ) . Xml::closeElement( 'fieldset' ) ); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 0147c1b3db..fa9755c161 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2566,6 +2566,7 @@ See [[Special:IPBlockList|IP block list]] to review blocks.', 'ipblocklist-sh-userblocks' => '$1 account blocks', 'ipblocklist-sh-tempblocks' => '$1 temporary blocks', 'ipblocklist-sh-addressblocks' => '$1 single IP blocks', +'ipblocklist-scanrange' => 'For IPs, include all blocks that affect the address', 'ipblocklist-summary' => '', # do not translate or duplicate this message to other languages 'ipblocklist-submit' => 'Search', 'blocklistline' => '$1, $2 blocked $3 ($4)', -- 2.20.1