r15520 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15519‎ | r15520 | r15521 >
Date:05:30, 11 July 2006
Author:tstarling
Status:old
Tags:
Comment:
Give manual blocks precedence over autoblocks
Modified paths:
  • /trunk/phase3/includes/Block.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Block.php
@@ -130,22 +130,45 @@
131131 }
132132
133133 # Try IP block
 134+ # TODO: improve performance by merging this query with the autoblock one
 135+ # Slightly tricky while handling killExpired as well
134136 if ( $address ) {
135 - $conds = array( 'ipb_address' => $address );
136 - if ( $user ) {
137 - $conds['ipb_anon_only'] = 0;
138 - }
 137+ $conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 );
139138 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
140139 if ( $this->loadFromResult( $res, $killExpired ) ) {
141 - return true;
 140+ if ( $user && $this->mAnonOnly ) {
 141+ # Block is marked anon-only
 142+ # Whitelist this IP address against autoblocks and range blocks
 143+ $this->clear();
 144+ return false;
 145+ } else {
 146+ return true;
 147+ }
142148 }
143149 }
144150
145151 # Try range block
146152 if ( $this->loadRange( $address, $killExpired, $user == 0 ) ) {
147 - return true;
 153+ if ( $user && $this->mAnonOnly ) {
 154+ $this->clear();
 155+ return false;
 156+ } else {
 157+ return true;
 158+ }
148159 }
149160
 161+ # Try autoblock
 162+ if ( $address ) {
 163+ $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 );
 164+ if ( $user ) {
 165+ $conds['ipb_anon_only'] = 0;
 166+ }
 167+ $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
 168+ if ( $this->loadFromResult( $res, $killExpired ) ) {
 169+ return true;
 170+ }
 171+ }
 172+
150173 # Give up
151174 $this->clear();
152175 return false;
@@ -189,7 +212,7 @@
190213 * Search the database for any range blocks matching the given address, and
191214 * load the row if one is found.
192215 */
193 - function loadRange( $address, $killExpired = true, $isAnon = true )
 216+ function loadRange( $address, $killExpired = true )
194217 {
195218 $iaddr = wfIP2Hex( $address );
196219 if ( $iaddr === false ) {
@@ -208,9 +231,6 @@
209232 "ipb_range_start <= '$iaddr'",
210233 "ipb_range_end >= '$iaddr'"
211234 );
212 - if ( !$isAnon ) {
213 - $conds['ipb_anon_only'] = 0;
214 - }
215235
216236 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
217237 $success = $this->loadFromResult( $res, $killExpired );