Optional feature : 'Ajax show editors' based on an idea by Tim Starling
[lhc/web/wiklou.git] / includes / Block.php
index 14c87a8..5645ed3 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
  * Blocks and bans object
- * @package MediaWiki
  */
 
 /**
@@ -12,7 +11,6 @@
  * Globals used: $wgAutoblockExpiry, $wgAntiLockFlags
  *
  * @todo This could be used everywhere, but it isn't.
- * @package MediaWiki
  */
 class Block
 {
@@ -24,7 +22,7 @@ class Block
        const EB_FOR_UPDATE = 2;
        const EB_RANGE_ONLY = 4;
 
-       function Block( $address = '', $user = 0, $by = 0, $reason = '',
+       function __construct( $address = '', $user = 0, $by = 0, $reason = '',
                $timestamp = '' , $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0 )
        {
                $this->mId = 0;
@@ -113,9 +111,6 @@ class Block
                $options = array();
                $db =& $this->getDBOptions( $options );
 
-               $ret = false;
-               $killed = false;
-
                if ( 0 == $user && $address == '' ) {
                        # Invalid user specification, not blocked
                        $this->clear();
@@ -241,10 +236,10 @@ class Block
 
        /**
         * Determine if a given integer IPv4 address is in a given CIDR network
-        * @deprecated Use wfIsAddressInRange
+        * @deprecated Use IP::isInRange
         */
        function isAddressInRange( $addr, $range ) {
-               return wfIsAddressInRange( $addr, $range );
+               return IP::isInRange( $addr, $range );
        }
 
        function initFromRow( $row )
@@ -275,9 +270,7 @@ class Block
                $this->mRangeEnd = '';
 
                if ( $this->mUser == 0 ) {
-                       $startend = wfRangeStartEnd($this->mAddress);
-                       $this->mRangeStart = $startend[0];
-                       $this->mRangeEnd = $startend[1];
+                       list( $this->mRangeStart, $this->mRangeEnd ) = IP::parseRange( $this->mAddress );
                }
        }
 
@@ -310,7 +303,7 @@ class Block
 
                $now = wfTimestampNow();
 
-               extract( $db->tableNames( 'ipblocks', 'user' ) );
+               list( $ipblocks, $user ) = $db->tableNamesN( 'ipblocks', 'user' );
 
                $sql = "SELECT $ipblocks.*,user_name FROM $ipblocks,$user " .
                        "WHERE user_id=ipb_by $cond ORDER BY ipb_timestamp DESC $options";
@@ -407,7 +400,7 @@ class Block
        *@return Whether or not a retroactive autoblock was made.
        */
        function doRetroactiveAutoblock() {
-               $dbr = wfGetDb( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                #If autoblock is enabled, autoblock the LAST IP used
                # - stolen shamelessly from CheckUser_body.php
 
@@ -415,7 +408,7 @@ class Block
                        wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n");
 
                        $row = $dbr->selectRow( 'recentchanges', array( 'rc_ip' ), array( 'rc_user_text' => $this->mAddress ),
-                               $fname, array( 'ORDER BY' => 'rc_timestamp DESC' ) );
+                               __METHOD__ , array( 'ORDER BY' => 'rc_timestamp DESC' ) );
 
                        if ( !$row || !$row->rc_ip ) {
                                #No results, don't autoblock anything
@@ -435,7 +428,7 @@ class Block
        */
        function doAutoblock( $autoblockip ) {
                # Check if this IP address is already blocked
-               $dbw =& wfGetDb( DB_MASTER );
+               $dbw =& wfGetDB( DB_MASTER );
                $dbw->begin();
 
                # If autoblocks are disabled, go away.
@@ -460,14 +453,16 @@ class Block
                        $wlEntry = substr($line, 1);
                        $wlEntry = trim($wlEntry);
 
-                       wfDebug("Checking $wlEntry\n");
+                       wfDebug("Checking $ip against $wlEntry...");
 
                        # Is the IP in this range?
-                       if (wfIsAddressInRange( $ip, $wlEntry )) {
-                               wfDebug("IP $ip matches $wlEntry, not autoblocking\n");
+                       if (IP::isInRange( $ip, $wlEntry )) {
+                               wfDebug(" IP $ip matches $wlEntry, not autoblocking\n");
                                #$autoblockip = null; # Don't autoblock a whitelisted IP.
                                return; #This /SHOULD/ introduce a dummy block - but
                                        # I don't know a safe way to do so. -werdna
+                       } else {
+                               wfDebug( " No match\n" );
                        }
                }