http://www.mediawiki.org/wiki/Special:Code/MediaWiki/58261

Revision: 58261
Author:   raymond
Date:     2009-10-28 15:45:27 +0000 (Wed, 28 Oct 2009)

Log Message:
-----------
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: trunk/extensions/GlobalBlocking/GlobalBlocking.class.php
===================================================================
--- trunk/extensions/GlobalBlocking/GlobalBlocking.class.php    2009-10-28 
15:25:41 UTC (rev 58260)
+++ trunk/extensions/GlobalBlocking/GlobalBlocking.class.php    2009-10-28 
15:45:27 UTC (rev 58261)
@@ -29,25 +29,9 @@
                
                // Instance cache
                if (!is_null($result)) return $result;
-       
-               $dbr = GlobalBlocking::getGlobalBlockingSlave();
-               
-               $hex_ip = IP::toHex( $ip );
-               $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother 
checking blocks out of this /16.
-       
-               $conds = array( 
-                       'gb_range_end>='.$dbr->addQuotes($hex_ip), // This 
block in the given range.
-                       'gb_range_start<='.$dbr->addQuotes($hex_ip),
-                       'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ),
-                       
'gb_expiry>'.$dbr->addQuotes($dbr->timestamp(wfTimestampNow())) 
-               );
-       
-               if ( !$user->isAnon() )
-                       $conds['gb_anon_only'] = 0;
-       
-               // Get the block
-               if ($block = $dbr->selectRow( 'globalblocks', '*', $conds, 
__METHOD__ )) {
-               
+
+               $block = getGlobalBlockingBlock( $ip, $user->isAnon() );
+               if  ( $block ) {
                        // Check for local whitelisting
                        if (GlobalBlocking::getWhitelistInfo( $block->gb_id ) ) 
{
                                // Block has been whitelisted.
@@ -71,7 +55,35 @@
                }
                return $result = array();
        }
-       
+
+       /**
+        * Get a block
+        * @param string $ip The IP address to be checked
+        * @param boolean $anon Get anon blocks only
+        * @return object The block
+        */
+       static function getGlobalBlockingBlock( $ip, $anon ) {
+               $dbr = GlobalBlocking::getGlobalBlockingSlave();
+
+               $hex_ip = IP::toHex( $ip );
+               $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother 
checking blocks out of this /16.
+
+               $conds = array( 
+                       'gb_range_end>='.$dbr->addQuotes( $hex_ip ), // This 
block in the given range.
+                       'gb_range_start<='.$dbr->addQuotes( $hex_ip ),
+                       'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ),
+                       'gb_expiry>'.$dbr->addQuotes( $dbr->timestamp( 
wfTimestampNow() ) )
+               );
+
+               if ( !$anon ) {
+                       $conds['gb_anon_only'] = 0;
+               }
+
+               // Get the block
+               $block = $dbr->selectRow( 'globalblocks', '*', $conds, 
__METHOD__ );
+               return $block;
+       }
+
        static function getGlobalBlockingMaster() {
                global $wgGlobalBlockingDatabase;
                return wfGetDB( DB_MASTER, 'globalblocking', 
$wgGlobalBlockingDatabase );



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to