r41902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41901‎ | r41902 | r41903 >
Date:21:49, 9 October 2008
Author:aaron
Status:old (Comments)
Tags:
Comment:
(bug 14634) Show range blocks for IPs
Modified paths:
  • /trunk/phase3/includes/specials/SpecialIpblocklist.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialIpblocklist.php
@@ -78,6 +78,7 @@
7979 $this->hideuserblocks = $wgRequest->getBool( 'hideuserblocks' );
8080 $this->hidetempblocks = $wgRequest->getBool( 'hidetempblocks' );
8181 $this->hideaddressblocks = $wgRequest->getBool( 'hideaddressblocks' );
 82+ $this->scanRange = $wgRequest->getBool( 'range' );
8283 }
8384
8485 /**
@@ -162,8 +163,7 @@
163164 * @return array array(message key, parameters) on failure, empty array on success
164165 */
165166
166 - static function doUnblock(&$id, &$ip, &$reason, &$range = null)
167 - {
 167+ static function doUnblock(&$id, &$ip, &$reason, &$range = null) {
168168 if ( $id ) {
169169 $block = Block::newFromID( $id );
170170 if ( !$block ) {
@@ -245,10 +245,20 @@
246246 // No extra conditions
247247 } elseif ( substr( $this->ip, 0, 1 ) == '#' ) {
248248 $conds['ipb_id'] = substr( $this->ip, 1 );
 249+ // Single IPs
249250 } elseif ( IP::isIPAddress($this->ip) && strpos($this->ip,'/') === false ) {
250 - $conds['ipb_address'] = IP::sanitizeIP($this->ip);
 251+ if( $this->scanRange && $iaddr = IP::toHex($this->ip) ) {
 252+ # Only scan ranges which start in this /16, this improves search speed
 253+ # Blocks should not cross a /16 boundary.
 254+ $range = substr( $iaddr, 0, 4 );
 255+ $conds[] = "(ipb_address = '" . IP::sanitizeIP($this->ip) . "') OR
 256+ (ipb_range_start LIKE '$range%' AND ipb_range_start <= '$iaddr' AND ipb_range_end >= '$iaddr')";
 257+ } else {
 258+ $conds['ipb_address'] = IP::sanitizeIP($this->ip);
 259+ }
251260 $conds['ipb_auto'] = 0;
252 - } elseif( IP::isIPAddress($this->ip) ) {
 261+ // IP range
 262+ } elseif ( IP::isIPAddress($this->ip) ) {
253263 $conds['ipb_address'] = Block::normaliseRange( $this->ip );
254264 $conds['ipb_auto'] = 0;
255265 } else {
@@ -298,8 +308,9 @@
299309 Xml::openElement( 'fieldset' ) .
300310 Xml::element( 'legend', null, wfMsg( 'ipblocklist-legend' ) ) .
301311 Xml::inputLabel( wfMsg( 'ipblocklist-username' ), 'ip', 'ip', /* size */ false, $this->ip ) .
302 - '&nbsp;' .
303 - Xml::submitButton( wfMsg( 'ipblocklist-submit' ) ) .
 312+ '<br/>' .
 313+ Xml::checkLabel( wfMsg('ipblocklist-scanrange'), 'range', 'range', $this->scanRange ) .
 314+ '&nbsp;' . Xml::submitButton( wfMsg( 'ipblocklist-submit' ) ) .
304315 Xml::closeElement( 'fieldset' )
305316 );
306317 }
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2566,6 +2566,7 @@
25672567 'ipblocklist-sh-userblocks' => '$1 account blocks',
25682568 'ipblocklist-sh-tempblocks' => '$1 temporary blocks',
25692569 'ipblocklist-sh-addressblocks' => '$1 single IP blocks',
 2570+'ipblocklist-scanrange' => 'For IPs, include all blocks that affect the address',
25702571 'ipblocklist-summary' => '', # do not translate or duplicate this message to other languages
25712572 'ipblocklist-submit' => 'Search',
25722573 'blocklistline' => '$1, $2 blocked $3 ($4)',

Follow-up revisions

RevisionCommit summaryAuthorDate
r42011Tweaks to r41902 "(bug 14634) Show range blocks for IPs"...brion01:44, 13 October 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   01:44, 13 October 2008

Updated a bit in 42011:

  • Remove the "scan range blocks" checkbox -- doing the range check is sane default behavior, and should Just Work. :)
  • Paranoia SQL escaping. We may "know" that the strings will never include something escapable, but then again someone might make a mistake one day. By ensuring we escape them, we have one less thing to worry about, and one less thing to double-check every time we look at this code.

Note that a search for a particular range block currently does not turn up larger range blocks that include it, which it probably should.

Status & tagging log