public static function newFromDB( $address, $user = 0, $killExpired = true ) {
$block = new Block;
$block->load( $address, $user, $killExpired );
+
if ( $block->isValid() ) {
return $block;
} else {
$res = $dbr->resultObject( $dbr->select( 'ipblocks', '*',
array( 'ipb_id' => $id ), __METHOD__ ) );
$block = new Block;
+
if ( $block->loadFromResult( $res ) ) {
return $block;
} else {
$db = wfGetDB( DB_SLAVE );
$options = array();
}
+
return $db;
}
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;
}
if ( $user ) {
$res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ),
__METHOD__, $options ) );
+
if ( $this->loadFromResult( $res, $killExpired ) ) {
return true;
}
if ( !$this->mCreateAccount ) {
$this->clear();
}
+
return false;
} else {
return true;
if ( !$this->mCreateAccount ) {
$this->clear();
}
+
return false;
} else {
return true;
}
}
$res->free();
+
return $ret;
}
*
* @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 ) {
$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'",
$res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
$success = $this->loadFromResult( $res, $killExpired );
+
return $success;
}
$dbw = wfGetDB( DB_MASTER );
$dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId ), __METHOD__ );
+
return $dbw->affectedRows() > 0;
}
*/
public function insert( $dbw = null ) {
wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
+
if ( $dbw === null )
$dbw = wfGetDB( DB_MASTER );
if ( !$this->mUser && $this->mAnonOnly ) {
$this->mBlockEmail = 0;
}
+
if ( !$this->mByName ) {
if ( $this->mBy ) {
$this->mByName = User::whoIs( $this->mBy );
wfDebug( "No IP found to retroactively autoblock\n" );
} else {
while ( $row = $dbr->fetchObject( $res ) ) {
- if ( $row->rc_ip )
+ if ( $row->rc_ip ) {
$this->doAutoblock( $row->rc_ip );
+ }
}
}
}
# 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;
# 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 ) {
} else {
$ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
}
+
# Insert it
return $ipblock->insert();
}
*/
public function deleteIfExpired() {
wfProfileIn( __METHOD__ );
+
if ( $this->isExpired() ) {
wfDebug( "Block::deleteIfExpired() -- deleting\n" );
$this->delete();
wfDebug( "Block::deleteIfExpired() -- not expired\n" );
$retVal = false;
}
+
wfProfileOut( __METHOD__ );
return $retVal;
}
*/
public function isExpired() {
wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
+
if ( !$this->mExpiry ) {
return false;
} else {
*/
public static function getAutoblockExpiry( $timestamp ) {
global $wgAutoblockExpiry;
+
return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
}
$range = "$newip/{$parts[1]}";
}
}
+
return $range;
}
if ( is_null( $msg ) ) {
$msg = array();
$keys = array( 'infiniteblock', 'expiringblock' );
+
foreach ( $keys as $key ) {
$msg[$key] = wfMsgHtml( $key );
}
$expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) );
$expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) );
}
+
return $expirystr;
}
return false;
}
}
+
return $expiry;
}
-
}