Fixup to schema help, there's only one now
[lhc/web/wiklou.git] / includes / Block.php
index db5a521..162188c 100644 (file)
@@ -24,7 +24,7 @@ class Block {
        const EB_RANGE_ONLY = 4;
 
        function __construct( $address = '', $user = 0, $by = 0, $reason = '',
-               $timestamp = '' , $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
+               $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
                $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byName = false )
        {
                $this->mId = 0;
@@ -63,6 +63,7 @@ class Block {
        public static function newFromDB( $address, $user = 0, $killExpired = true ) {
                $block = new Block;
                $block->load( $address, $user, $killExpired );
+
                if ( $block->isValid() ) {
                        return $block;
                } else {
@@ -81,6 +82,7 @@ class Block {
                $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*',
                        array( 'ipb_id' => $id ), __METHOD__ ) );
                $block = new Block;
+
                if ( $block->loadFromResult( $res ) ) {
                        return $block;
                } else {
@@ -142,6 +144,7 @@ class Block {
                        $db = wfGetDB( DB_SLAVE );
                        $options = array();
                }
+
                return $db;
        }
 
@@ -158,11 +161,12 @@ class Block {
                wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
 
                $options = array();
-               $db =& $this->getDBOptions( $options );
+               $db = $this->getDBOptions( $options );
 
                if ( 0 == $user && $address === '' ) {
                        # Invalid user specification, not blocked
                        $this->clear();
+
                        return false;
                }
 
@@ -170,6 +174,7 @@ class Block {
                if ( $user ) {
                        $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ),
                                __METHOD__, $options ) );
+
                        if ( $this->loadFromResult( $res, $killExpired ) ) {
                                return true;
                        }
@@ -190,6 +195,7 @@ class Block {
                                        if ( !$this->mCreateAccount ) {
                                                $this->clear();
                                        }
+
                                        return false;
                                } else {
                                        return true;
@@ -204,6 +210,7 @@ class Block {
                                if ( !$this->mCreateAccount ) {
                                        $this->clear();
                                }
+
                                return false;
                        } else {
                                return true;
@@ -266,6 +273,7 @@ class Block {
                        }
                }
                $res->free();
+
                return $ret;
        }
 
@@ -275,7 +283,7 @@ class Block {
         *
         * @param $address String: IP address range
         * @param $killExpired Boolean: whether to delete expired rows while loading
-        * @param $userid Integer: if not 0, then sets ipb_anon_only
+        * @param $user Integer: if not 0, then sets ipb_anon_only
         * @return Boolean
         */
        public function loadRange( $address, $killExpired = true, $user = 0 ) {
@@ -291,7 +299,7 @@ class Block {
                $range = substr( $iaddr, 0, 4 );
 
                $options = array();
-               $db =& $this->getDBOptions( $options );
+               $db = $this->getDBOptions( $options );
                $conds = array(
                        'ipb_range_start' . $db->buildLike( $range, $db->anyString() ),
                        "ipb_range_start <= '$iaddr'",
@@ -304,6 +312,7 @@ class Block {
 
                $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
                $success = $this->loadFromResult( $res, $killExpired );
+
                return $success;
        }
 
@@ -368,6 +377,7 @@ class Block {
 
                $dbw = wfGetDB( DB_MASTER );
                $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId ), __METHOD__ );
+
                return $dbw->affectedRows() > 0;
        }
 
@@ -379,6 +389,7 @@ class Block {
         */
        public function insert( $dbw = null ) {
                wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
+
                if ( $dbw === null )
                        $dbw = wfGetDB( DB_MASTER );
 
@@ -476,6 +487,7 @@ class Block {
                if ( !$this->mUser && $this->mAnonOnly ) {
                        $this->mBlockEmail = 0;
                }
+
                if ( !$this->mByName ) {
                        if ( $this->mBy ) {
                                $this->mByName = User::whoIs( $this->mBy );
@@ -519,9 +531,10 @@ class Block {
                                # No results, don't autoblock anything
                                wfDebug( "No IP found to retroactively autoblock\n" );
                        } else {
-                               while ( $row = $dbr->fetchObject( $res ) ) {
-                                       if ( $row->rc_ip )
+                               foreach ( $res as $row ) {
+                                       if ( $row->rc_ip ) {
                                                $this->doAutoblock( $row->rc_ip );
+                                       }
                                }
                        }
                }
@@ -602,13 +615,16 @@ class Block {
                        # exceed the user block. If it would exceed, then do nothing, else
                        # prolong block time
                        if ( $this->mExpiry &&
-                       ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) ) {
+                               ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) )
+                       ) {
                                return;
                        }
+
                        # Just update the timestamp
                        if ( !$justInserted ) {
                                $ipblock->updateTimestamp();
                        }
+
                        return;
                } else {
                        $ipblock = new Block;
@@ -627,6 +643,7 @@ class Block {
                # Continue suppressing the name if needed
                $ipblock->mHideName = $this->mHideName;
                $ipblock->mAllowUsertalk = $this->mAllowUsertalk;
+
                # If the user is already blocked with an expiry date, we don't
                # want to pile on top of that!
                if ( $this->mExpiry ) {
@@ -634,6 +651,7 @@ class Block {
                } else {
                        $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
                }
+
                # Insert it
                return $ipblock->insert();
        }
@@ -644,6 +662,7 @@ class Block {
         */
        public function deleteIfExpired() {
                wfProfileIn( __METHOD__ );
+
                if ( $this->isExpired() ) {
                        wfDebug( "Block::deleteIfExpired() -- deleting\n" );
                        $this->delete();
@@ -652,6 +671,7 @@ class Block {
                        wfDebug( "Block::deleteIfExpired() -- not expired\n" );
                        $retVal = false;
                }
+
                wfProfileOut( __METHOD__ );
                return $retVal;
        }
@@ -662,6 +682,7 @@ class Block {
         */
        public function isExpired() {
                wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
+
                if ( !$this->mExpiry ) {
                        return false;
                } else {
@@ -778,6 +799,7 @@ class Block {
         */
        public static function getAutoblockExpiry( $timestamp ) {
                global $wgAutoblockExpiry;
+
                return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
        }
 
@@ -793,7 +815,7 @@ class Block {
                        // IPv6
                        if ( IP::isIPv6( $range ) && $parts[1] >= 64 && $parts[1] <= 128 ) {
                                $bits = $parts[1];
-                               $ipint = IP::toUnsigned6( $parts[0] );
+                               $ipint = IP::toUnsigned( $parts[0] );
                                # Native 32 bit functions WON'T work here!!!
                                # Convert to a padded binary number
                                $network = wfBaseConvert( $ipint, 10, 2, 128 );
@@ -813,6 +835,7 @@ class Block {
                                $range = "$newip/{$parts[1]}";
                        }
                }
+
                return $range;
        }
 
@@ -826,15 +849,12 @@ class Block {
 
        /**
         * Get a value to insert into expiry field of the database when infinite expiry
-        * is desired. In principle this could be DBMS-dependant, but currently all
-        * supported DBMS's support the string "infinity", so we just use that.
+        * is desired
         *
         * @return String
         */
        public static function infinity() {
-               # This is a special keyword for timestamps in PostgreSQL, and
-               # works with CHAR(14) as well because "i" sorts after all numbers.
-               return 'infinity';
+               return wfGetDB( DB_SLAVE )->getInfinity();
        }
 
        /**
@@ -849,6 +869,7 @@ class Block {
                if ( is_null( $msg ) ) {
                        $msg = array();
                        $keys = array( 'infiniteblock', 'expiringblock' );
+
                        foreach ( $keys as $key ) {
                                $msg[$key] = wfMsgHtml( $key );
                        }
@@ -863,6 +884,7 @@ class Block {
                        $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) );
                        $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) );
                }
+
                return $expirystr;
        }
 
@@ -881,7 +903,7 @@ class Block {
                                return false;
                        }
                }
+
                return $expiry;
        }
-
 }