*/
class Block {
/* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock;
-
+
protected
$mId,
$mFromMaster,
*
* @param $address String: IP address of user/anon
* @param $user Integer: user id of user
- * @param $killExpired Boolean: delete expired blocks on load
* @return Block Object
* @deprecated since 1.18
*/
/**
* Check if two blocks are effectively equal. Doesn't check irrelevant things like
* the blocking user or the block timestamp, only things which affect the blocked user *
- * @return Boolean
+ *
+ * @param $block Block
+ *
+ * @return bool
*/
public function equals( Block $block ) {
return (
* 2) A rangeblock encompasing the given IP (smallest first)
* 3) An autoblock on the given IP
* @param $vagueTarget User|String also search for blocks affecting this target. Doesn't
- * make any sense to use TYPE_AUTO / TYPE_ID here
+ * make any sense to use TYPE_AUTO / TYPE_ID here. Leave blank to skip IP lookups.
* @return Bool whether a relevant block was found
*/
protected function newLoad( $vagueTarget = null ) {
$conds = array( 'ipb_address' => array() );
}
- if( $vagueTarget !== null ){
+ # Be aware that the != '' check is explicit, since empty values will be passed by some callers.
+ if( $vagueTarget != ''){
list( $target, $type ) = self::parseTarget( $vagueTarget );
switch( $type ) {
case self::TYPE_USER:
# This has the nice property that a /32 block is ranked equally with a
# single-IP block, which is exactly what it is...
$score = self::TYPE_RANGE - 1 + ( $size / 128 );
-
+
} else {
$score = $block->getType();
}
* 1.2.3.4 will not select 1.2.0.0/16 or even 1.2.3.4/32)
* @param $vagueTarget String|User|Int as above, but we will search for *any* block which
* affects that target (so for an IP address, get ranges containing that IP; and also
- * get any relevant autoblocks)
+ * get any relevant autoblocks). Leave empty or blank to skip IP-based lookups.
* @param $fromMaster Bool whether to use the DB_MASTER database
* @return Block|null (null if no relevant block could be found). The target and type
* of the returned Block will refer to the actual block which was found, which might
* not be the same as the target you gave if you used $vagueTarget!
*/
public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
+ # (bug 29116) passing $vagueTarget = '' is not unreasonable here, but int(0)
+ # is a valid username, so we can't just use weak comparisons.
+ if( $vagueTarget === '' ){
+ $vagueTarget = null;
+ }
+
list( $target, $type ) = self::parseTarget( $specificTarget );
if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){
return Block::newFromID( $target );
- } elseif( $target === null && $vagueTarget === null ){
+ } elseif( $target === null && $vagueTarget == '' ){
# We're not going to find anything useful here
+ # Be aware that the == '' check is explicit, since empty values will be passed by some callers.
return null;
} elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
# We may have been through this before
if( $target instanceof User ){
if( IP::isValid( $target->getName() ) ){
- return self::TYPE_IP;
+ return array( $target, self::TYPE_IP );
} else {
- return self::TYPE_USER;
+ return array( $target, self::TYPE_USER );
}
} elseif( $target === null ){
return array( null, null );