r58261 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58260‎ | r58261 | r58262 >
Date:15:45, 28 October 2009
Author:raymond
Status:resolved
Tags:
Comment:
Refactor a bit. Function is needed to fix bug 20478 (Add a note to Special:Block)
Modified paths:
  • /trunk/extensions/GlobalBlocking/GlobalBlocking.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalBlocking/GlobalBlocking.class.php
@@ -29,25 +29,9 @@
3030
3131 // Instance cache
3232 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 ) {
5236 // Check for local whitelisting
5337 if (GlobalBlocking::getWhitelistInfo( $block->gb_id ) ) {
5438 // Block has been whitelisted.
@@ -71,7 +55,35 @@
7256 }
7357 return $result = array();
7458 }
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+
7688 static function getGlobalBlockingMaster() {
7789 global $wgGlobalBlockingDatabase;
7890 return wfGetDB( DB_MASTER, 'globalblocking', $wgGlobalBlockingDatabase );

Follow-up revisions

RevisionCommit summaryAuthorDate
r58292GlobalBlocking: Fix fatal from r58261catrope22:23, 28 October 2009
r58385* (bug 20478) Add a note to Special:Block when the IP is already globally blo...raymond09:35, 31 October 2009

Status & tagging log