X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2FBlock.php;h=f97cabce15a2e23b0056f7897478b350d5f5c270;hb=7cb597d5136207ec2a1e5ce9ca1e52740ffddba3;hp=3b4916c288f2e471e7330f7e1ae79c2101c01d92;hpb=4b42f18b66e843f362e5e159d95fee9d2c26ef9c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index 3b4916c288..f97cabce15 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -35,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(); @@ -54,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; @@ -76,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"; } @@ -126,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(); } @@ -147,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(); @@ -180,6 +199,9 @@ class Block function delete() { $fname = 'Block::delete'; + if (wfReadOnly()) { + return; + } $dbw =& wfGetDB( DB_MASTER ); if ( $this->mAddress == '' ) { @@ -193,6 +215,7 @@ class Block function insert() { + wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" ); $dbw =& wfGetDB( DB_MASTER ); $dbw->insert( 'ipblocks', array( @@ -202,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' ); @@ -212,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; } }