Disable Special:Sitesettings, as it is far far far from working.
[lhc/web/wiklou.git] / includes / Block.php
index 6dab0d3..f97cabc 100644 (file)
@@ -2,7 +2,6 @@
 /**
  * Blocks and bans object
  * @package MediaWiki
- * $Id$
  */
 
 /**
@@ -36,7 +35,11 @@ class Block
                $this->mReason = $reason;
                $this->mTimestamp = wfTimestamp(TS_MW,$timestamp);
                $this->mAuto = $auto;
-               $this->mExpiry = wfTimestamp(TS_MW,$expiry);
+               if( empty( $expiry ) ) {
+                       $this->mExpiry = $expiry;
+               } else {
+                       $this->mExpiry = wfTimestamp( TS_MW, $expiry );
+               }
                
                $this->mForUpdate = false;
                $this->initialiseRange();
@@ -55,10 +58,14 @@ class Block
                $mUser = $mBy = 0;
        }
 
-       # Get a ban from the DB, with either the given address or the given username
+       /**
+        * Get a ban from the DB, with either the given address or the given username
+        */
        function load( $address = '', $user = 0, $killExpired = true ) 
        {
+               global $wgDBmysql4 ;
                $fname = 'Block::load';
+               wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
 
                $ret = false;
                $killed = false;
@@ -77,7 +84,14 @@ class Block
                        $sql = "SELECT * FROM $ipblocks WHERE ipb_user={$user} $options";
                } elseif ($user=="") {
                        $sql = "SELECT * FROM $ipblocks WHERE ipb_address='" . $db->strencode( $address ) . "' $options";
+               } elseif ( $options=='' && $wgDBmysql4 ) {
+                       # If there are no optiones (e.g. FOR UPDATE), use a UNION
+                       # so that the query can make efficient use of indices
+                       $sql = "SELECT * FROM $ipblocks WHERE ipb_address='" . $db->strencode( $address ) .
+                               "' UNION SELECT * FROM $ipblocks WHERE ipb_user={$user}";
                } else {
+                       # If there are options, a UNION can not be used, use one
+                       # SELECT instead. Will do a full table scan.
                        $sql = "SELECT * FROM $ipblocks WHERE (ipb_address='" . $db->strencode( $address ) . 
                                "' OR ipb_user={$user}) $options";
                }
@@ -127,7 +141,9 @@ class Block
                $this->mBy = $row->ipb_by;
                $this->mAuto = $row->ipb_auto;
                $this->mId = $row->ipb_id;
-               $this->mExpiry = wfTimestamp(TS_MW,$row->ipb_expiry);
+               $this->mExpiry = $row->ipb_expiry ?
+                       wfTimestamp(TS_MW,$row->ipb_expiry) :
+                       $row->ipb_expiry;
 
                $this->initialiseRange();
        }       
@@ -148,7 +164,9 @@ class Block
                }
        }
        
-       # Callback with a Block object for every block
+       /**
+        * Callback with a Block object for every block
+        */
        /*static*/ function enumBlocks( $callback, $tag, $flags = 0 ) 
        {
                $block = new Block();
@@ -181,6 +199,9 @@ class Block
        function delete() 
        {
                $fname = 'Block::delete';
+               if (wfReadOnly()) {
+                       return;
+               }
                $dbw =& wfGetDB( DB_MASTER );
 
                if ( $this->mAddress == '' ) {
@@ -194,8 +215,9 @@ class Block
 
        function insert() 
        {
+               wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
                $dbw =& wfGetDB( DB_MASTER );
-               $dbw->insertArray( 'ipblocks',
+               $dbw->insert( 'ipblocks',
                        array(
                                'ipb_address' => $this->mAddress,
                                'ipb_user' => $this->mUser,
@@ -203,7 +225,9 @@ class Block
                                'ipb_reason' => $this->mReason,
                                'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
                                'ipb_auto' => $this->mAuto,
-                               'ipb_expiry' => $dbw->timestamp($this->mExpiry),
+                               'ipb_expiry' => $this->mExpiry ?
+                                       $dbw->timestamp($this->mExpiry) :
+                                       $this->mExpiry,
                        ), 'Block::insert' 
                );
 
@@ -213,19 +237,22 @@ class Block
        function deleteIfExpired() 
        {
                if ( $this->isExpired() ) {
+                       wfDebug( "Block::deleteIfExpired() -- deleting\n" );
                        $this->delete();
                        return true;
                } else {
+                       wfDebug( "Block::deleteIfExpired() -- not expired\n" );
                        return false;
                }
        }
 
        function isExpired() 
        {       
+               wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
                if ( !$this->mExpiry ) {
                        return false;
                } else {
-                       return wfTimestamp() > $this->mExpiry;
+                       return wfTimestampNow() > $this->mExpiry;
                }
        }
 
@@ -241,7 +268,7 @@ class Block
                        $this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
 
                        $dbw =& wfGetDB( DB_MASTER );
-                       $dbw->updateArray( 'ipblocks', 
+                       $dbw->update( 'ipblocks', 
                                array( /* SET */ 
                                        'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
                                        'ipb_expiry' => $dbw->timestamp($this->mExpiry),