From 1b1e8a498afb25488eb571b9a556b1f804f6898e Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 11 Jul 2006 05:30:35 +0000 Subject: [PATCH] Give manual blocks precedence over autoblocks --- includes/Block.php | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 9a0cf789a2..563b14fc7b 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -130,22 +130,45 @@ class Block } # Try IP block + # TODO: improve performance by merging this query with the autoblock one + # Slightly tricky while handling killExpired as well if ( $address ) { - $conds = array( 'ipb_address' => $address ); - if ( $user ) { - $conds['ipb_anon_only'] = 0; - } + $conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 ); $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); if ( $this->loadFromResult( $res, $killExpired ) ) { - return true; + if ( $user && $this->mAnonOnly ) { + # Block is marked anon-only + # Whitelist this IP address against autoblocks and range blocks + $this->clear(); + return false; + } else { + return true; + } } } # Try range block if ( $this->loadRange( $address, $killExpired, $user == 0 ) ) { - return true; + if ( $user && $this->mAnonOnly ) { + $this->clear(); + return false; + } else { + return true; + } } + # Try autoblock + if ( $address ) { + $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 ); + if ( $user ) { + $conds['ipb_anon_only'] = 0; + } + $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); + if ( $this->loadFromResult( $res, $killExpired ) ) { + return true; + } + } + # Give up $this->clear(); return false; @@ -189,7 +212,7 @@ class Block * Search the database for any range blocks matching the given address, and * load the row if one is found. */ - function loadRange( $address, $killExpired = true, $isAnon = true ) + function loadRange( $address, $killExpired = true ) { $iaddr = wfIP2Hex( $address ); if ( $iaddr === false ) { @@ -208,9 +231,6 @@ class Block "ipb_range_start <= '$iaddr'", "ipb_range_end >= '$iaddr'" ); - if ( !$isAnon ) { - $conds['ipb_anon_only'] = 0; - } $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); $success = $this->loadFromResult( $res, $killExpired ); -- 2.20.1