Index: trunk/phase3/includes/Block.php |
— | — | @@ -130,22 +130,45 @@ |
131 | 131 | } |
132 | 132 | |
133 | 133 | # Try IP block |
| 134 | + # TODO: improve performance by merging this query with the autoblock one |
| 135 | + # Slightly tricky while handling killExpired as well |
134 | 136 | 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 ); |
139 | 138 | $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); |
140 | 139 | 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 | + } |
142 | 148 | } |
143 | 149 | } |
144 | 150 | |
145 | 151 | # Try range block |
146 | 152 | 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 | + } |
148 | 159 | } |
149 | 160 | |
| 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 | + |
150 | 173 | # Give up |
151 | 174 | $this->clear(); |
152 | 175 | return false; |
— | — | @@ -189,7 +212,7 @@ |
190 | 213 | * Search the database for any range blocks matching the given address, and |
191 | 214 | * load the row if one is found. |
192 | 215 | */ |
193 | | - function loadRange( $address, $killExpired = true, $isAnon = true ) |
| 216 | + function loadRange( $address, $killExpired = true ) |
194 | 217 | { |
195 | 218 | $iaddr = wfIP2Hex( $address ); |
196 | 219 | if ( $iaddr === false ) { |
— | — | @@ -208,9 +231,6 @@ |
209 | 232 | "ipb_range_start <= '$iaddr'", |
210 | 233 | "ipb_range_end >= '$iaddr'" |
211 | 234 | ); |
212 | | - if ( !$isAnon ) { |
213 | | - $conds['ipb_anon_only'] = 0; |
214 | | - } |
215 | 235 | |
216 | 236 | $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); |
217 | 237 | $success = $this->loadFromResult( $res, $killExpired ); |