$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();
$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;
$sql = "SELECT * FROM $ipblocks WHERE ipb_user={$user} $options";
} elseif ($user=="") {
$sql = "SELECT * FROM $ipblocks WHERE ipb_address='" . $db->strencode( $address ) . "' $options";
- } elseif ( $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 ) .
$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();
}
}
}
- # 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();
function delete()
{
$fname = 'Block::delete';
+ if (wfReadOnly()) {
+ return;
+ }
$dbw =& wfGetDB( DB_MASTER );
if ( $this->mAddress == '' ) {
function insert()
{
+ wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
$dbw =& wfGetDB( DB_MASTER );
$dbw->insert( 'ipblocks',
array(
'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'
);
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;
}
}