Index: trunk/extensions/GlobalBlocking/GlobalBlocking.class.php |
— | — | @@ -29,25 +29,9 @@ |
30 | 30 | |
31 | 31 | // Instance cache |
32 | 32 | if (!is_null($result)) return $result; |
33 | | - |
34 | | - $dbr = GlobalBlocking::getGlobalBlockingSlave(); |
35 | | - |
36 | | - $hex_ip = IP::toHex( $ip ); |
37 | | - $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother checking blocks out of this /16. |
38 | | - |
39 | | - $conds = array( |
40 | | - 'gb_range_end>='.$dbr->addQuotes($hex_ip), // This block in the given range. |
41 | | - 'gb_range_start<='.$dbr->addQuotes($hex_ip), |
42 | | - 'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ), |
43 | | - 'gb_expiry>'.$dbr->addQuotes($dbr->timestamp(wfTimestampNow())) |
44 | | - ); |
45 | | - |
46 | | - if ( !$user->isAnon() ) |
47 | | - $conds['gb_anon_only'] = 0; |
48 | | - |
49 | | - // Get the block |
50 | | - if ($block = $dbr->selectRow( 'globalblocks', '*', $conds, __METHOD__ )) { |
51 | | - |
| 33 | + |
| 34 | + $block = getGlobalBlockingBlock( $ip, $user->isAnon() ); |
| 35 | + if ( $block ) { |
52 | 36 | // Check for local whitelisting |
53 | 37 | if (GlobalBlocking::getWhitelistInfo( $block->gb_id ) ) { |
54 | 38 | // Block has been whitelisted. |
— | — | @@ -71,7 +55,35 @@ |
72 | 56 | } |
73 | 57 | return $result = array(); |
74 | 58 | } |
75 | | - |
| 59 | + |
| 60 | + /** |
| 61 | + * Get a block |
| 62 | + * @param string $ip The IP address to be checked |
| 63 | + * @param boolean $anon Get anon blocks only |
| 64 | + * @return object The block |
| 65 | + */ |
| 66 | + static function getGlobalBlockingBlock( $ip, $anon ) { |
| 67 | + $dbr = GlobalBlocking::getGlobalBlockingSlave(); |
| 68 | + |
| 69 | + $hex_ip = IP::toHex( $ip ); |
| 70 | + $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother checking blocks out of this /16. |
| 71 | + |
| 72 | + $conds = array( |
| 73 | + 'gb_range_end>='.$dbr->addQuotes( $hex_ip ), // This block in the given range. |
| 74 | + 'gb_range_start<='.$dbr->addQuotes( $hex_ip ), |
| 75 | + 'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ), |
| 76 | + 'gb_expiry>'.$dbr->addQuotes( $dbr->timestamp( wfTimestampNow() ) ) |
| 77 | + ); |
| 78 | + |
| 79 | + if ( !$anon ) { |
| 80 | + $conds['gb_anon_only'] = 0; |
| 81 | + } |
| 82 | + |
| 83 | + // Get the block |
| 84 | + $block = $dbr->selectRow( 'globalblocks', '*', $conds, __METHOD__ ); |
| 85 | + return $block; |
| 86 | + } |
| 87 | + |
76 | 88 | static function getGlobalBlockingMaster() { |
77 | 89 | global $wgGlobalBlockingDatabase; |
78 | 90 | return wfGetDB( DB_MASTER, 'globalblocking', $wgGlobalBlockingDatabase ); |