MediaWiki  REL1_23
Block Class Reference
Collaboration diagram for Block:

List of all members.

Public Member Functions

 __construct ($address= '', $user=0, $by=0, $reason= '', $timestamp=0, $auto=0, $expiry= '', $anonOnly=0, $createAccount=0, $enableAutoblock=0, $hideName=0, $blockEmail=0, $allowUsertalk=0, $byText= '')
 Constructor.
 delete ()
 Delete the row from the IP blocks table.
 deleteIfExpired ()
 Check if a block has expired.
 doAutoblock ($autoblockIP)
 Autoblocks the given IP, referring to this Block.
 equals (Block $block)
 Check if two blocks are effectively equal.
 fromMaster ($x=null)
 Get/set a flag determining whether the master is used for reads.
 getBlocker ()
 Get the user who implemented this block.
 getBy ()
 Get the user id of the blocking sysop.
 getByName ()
 Get the username of the blocking sysop.
 getExpiry ()
 getId ()
 Get the block ID.
 getPermissionsError (IContextSource $context)
 Get the key and parameters for the corresponding error message.
 getRangeEnd ()
 Get the IP address at the end of the range in Hex form.
 getRangeStart ()
 Get the IP address at the start of the range in Hex form.
 getRedactedName ()
 Get the block name, but with autoblocked IPs hidden as per standard privacy policy.
 getTarget ()
 Get the target for this particular Block.
 getTargetAndType ()
 Get the target and target type for this particular Block.
 getType ()
 Get the type of target for this particular block.
 insert ($dbw=null)
 Insert a block into the block table.
 isAutoblocking ($x=null)
 isExpired ()
 Has the block expired?
 isHardblock ($x=null)
 Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range.
 isValid ()
 Is the block address valid (i.e.
 prevents ($action, $x=null)
 Get/set whether the Block prevents a given action.
 setBlocker ($user)
 Set the user who implemented (or will implement) this block.
 setTarget ($target)
 Set the target for this block, and update $this->type accordingly.
 update ()
 Update a block in the DB with new parameters.
 updateTimestamp ()
 Update the timestamp on autoblocks.

Static Public Member Functions

static chooseBlock (array $blocks, array $ipChain)
 From a list of multiple blocks, find the most exact and strongest Block.
static getAutoblockExpiry ($timestamp)
 Get a timestamp of the expiry for autoblocks.
static getBlocksForIPList (array $ipChain, $isAnon, $fromMaster=false)
 Get all blocks that match any IP from an array of IP addresses.
static getRangeCond ($start, $end=null)
 Get a set of SQL conditions which will select rangeblocks encompassing a given range.
static isWhitelistedFromAutoblocks ($ip)
 Checks whether a given IP is on the autoblock whitelist.
static newFromID ($id)
 Load a blocked user from their block id.
static newFromRow ($row)
 Create a new Block object from a database row.
static newFromTarget ($specificTarget, $vagueTarget=null, $fromMaster=false)
 Given a target and the target's type, get an existing Block object if possible.
static parseTarget ($target)
 From an existing Block, get the target and the type of target.
static purgeExpired ()
 Purge expired blocks from the ipblocks table.
static selectFields ()
 Return the list of ipblocks fields that should be selected to create a new block.

Public Attributes

 $mAuto
 $mBlockEmail
 $mCreateAccount
 $mDisableUsertalk
 $mExpiry
 $mFromMaster
 $mHideName
 $mParentBlockId
 $mReason
 $mTimestamp
const TYPE_AUTO = 4
const TYPE_ID = 5
const TYPE_IP = 2
const TYPE_RANGE = 3
const TYPE_USER = 1

Protected Member Functions

 doRetroactiveAutoblock ()
 Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
 getAutoblockUpdateArray ()
 getDatabaseArray ($db=null)
 Get an array suitable for passing to $dbw->insert() or $dbw->update()
 initFromRow ($row)
 Given a database row from the ipblocks table, initialize member variables.
 newLoad ($vagueTarget=null)
 Load a block from the database which affects the already-set $this->target: 1) A block directly on the given user or IP 2) A rangeblock encompassing the given IP (smallest first) 3) An autoblock on the given IP.

Static Protected Member Functions

static defaultRetroactiveAutoblock (Block $block, array &$blockIds)
 Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
static getIpFragment ($hex)
 Get the component of an IP address which is certain to be the same between an IP address and a rangeblock containing that IP address.

Protected Attributes

User $blocker
 *
Integer $forcedTargetID
 Hack for foreign blocking (CentralAuth) *.
Bool $isAutoblocking = true
 *
Bool $isHardblock = true
 *
 $mId
User String $target
 *
Integer $type
 Block::TYPE_ constant.

Detailed Description

Definition at line 22 of file Block.php.


Constructor & Destructor Documentation

Block::__construct ( address = '',
user = 0,
by = 0,
reason = '',
timestamp = 0,
auto = 0,
expiry = '',
anonOnly = 0,
createAccount = 0,
enableAutoblock = 0,
hideName = 0,
blockEmail = 0,
allowUsertalk = 0,
byText = '' 
)

Constructor.

Todo:
FIXME: Don't know what the best format to have for this constructor is, but fourteen optional parameters certainly isn't it.

Definition at line 58 of file Block.php.

References $allowUsertalk, $timestamp, $user, isAutoblocking(), isHardblock(), prevents(), setBlocker(), setTarget(), wfGetDB(), wfTimestamp(), and wfTimestampNow().


Member Function Documentation

static Block::chooseBlock ( array blocks,
array ipChain 
) [static]

From a list of multiple blocks, find the most exact and strongest Block.

The logic for finding the "best" block is:

  • Blocks that match the block's target IP are preferred over ones in a range
  • Hardblocks are chosen over softblocks that prevent account creation
  • Softblocks that prevent account creation are chosen over other softblocks
  • Other softblocks are chosen over autoblocks
  • If there are multiple exact or range blocks at the same level, the one chosen is random
Parameters:
Array$ipChainlist of IPs (strings). This is used to determine how "close" a block is to the server, and if a block matches exactly, or is in a range. The order is furthest from the server to nearest e.g., (Browser, proxy1, proxy2, local-squid, ...)
Array$blockArray of blocks
Returns:
Block|null the "best" block from the list

Definition at line 1089 of file Block.php.

static Block::defaultRetroactiveAutoblock ( Block block,
array &$  blockIds 
) [static, protected]

Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.

This will use the recentchanges table.

Parameters:
Block$block
array&$blockIds
Returns:
Array: block IDs of retroactive autoblocks made

Definition at line 561 of file Block.php.

Delete the row from the IP blocks table.

Exceptions:
MWException
Returns:
Boolean

Definition at line 374 of file Block.php.

Check if a block has expired.

Delete it if it is.

Returns:
Boolean

Definition at line 715 of file Block.php.

Block::doAutoblock ( autoblockIP)

Autoblocks the given IP, referring to this Block.

Parameters:
string$autoblockIPthe IP to autoblock.
Returns:
mixed: block ID if an autoblock was inserted, false if not.

Definition at line 645 of file Block.php.

Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.

Returns:
Array: block IDs of retroactive autoblocks made

Definition at line 537 of file Block.php.

Block::equals ( Block block)

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

Parameters:
$blockBlock
Returns:
bool

Definition at line 152 of file Block.php.

Block::fromMaster ( x = null)

Get/set a flag determining whether the master is used for reads.

Parameters:
$xBool
Returns:
Bool

Definition at line 852 of file Block.php.

static Block::getAutoblockExpiry ( timestamp) [static]

Get a timestamp of the expiry for autoblocks.

Parameters:
$timestampString|Int
Returns:
String

Definition at line 928 of file Block.php.

Returns:
Array

Definition at line 520 of file Block.php.

Get the user who implemented this block.

Returns:
User|string Local User object or string for a foreign user

Definition at line 1298 of file Block.php.

Referenced by getBy(), and getByName().

static Block::getBlocksForIPList ( array ipChain,
isAnon,
fromMaster = false 
) [static]

Get all blocks that match any IP from an array of IP addresses.

Parameters:
Array$ipChainlist of IPs (strings), usually retrieved from the X-Forwarded-For header of the request
Bool$isAnonExclude anonymous-only blocks if false
Bool$fromMasterWhether to query the master or slave database
Returns:
Array of Blocks
Since:
1.22

Definition at line 1010 of file Block.php.

Get the user id of the blocking sysop.

Returns:
Integer (0 for foreign users)

Definition at line 819 of file Block.php.

References $blocker, getBlocker(), and User\getId().

Referenced by getDatabaseArray().

Get the username of the blocking sysop.

Returns:
String

Definition at line 831 of file Block.php.

References $blocker, getBlocker(), and User\getName().

Referenced by getDatabaseArray().

Block::getDatabaseArray ( db = null) [protected]

Get an array suitable for passing to $dbw->insert() or $dbw->update()

Parameters:
$dbDatabaseBase
Returns:
Array

Definition at line 482 of file Block.php.

References array(), getBy(), getByName(), getRangeEnd(), getRangeStart(), isAutoblocking(), isHardblock(), prevents(), and wfGetDB().

Since:
1.19
Returns:
Mixed|string

Definition at line 1282 of file Block.php.

Get the block ID.

Returns:
int

Definition at line 842 of file Block.php.

static Block::getIpFragment ( hex) [static, protected]

Get the component of an IP address which is certain to be the same between an IP address and a rangeblock containing that IP address.

Parameters:
$hexString Hexadecimal IP representation
Returns:
String

Definition at line 312 of file Block.php.

Get the key and parameters for the corresponding error message.

Since:
1.22
Parameters:
IContextSource$context
Returns:
array

Definition at line 1317 of file Block.php.

Referenced by UserBlockedError\__construct().

static Block::getRangeCond ( start,
end = null 
) [static]

Get a set of SQL conditions which will select rangeblocks encompassing a given range.

Parameters:
string$startHexadecimal IP representation
string$endHexadecimal IP representation, or null to use $start = $end
Returns:
String

Definition at line 279 of file Block.php.

Referenced by SpecialBlockList\showList().

Get the IP address at the end of the range in Hex form.

Exceptions:
MWException
Returns:
String IP in Hex form

Definition at line 800 of file Block.php.

References list, IP\parseRange(), IP\toHex(), and type.

Referenced by getDatabaseArray().

Get the IP address at the start of the range in Hex form.

Exceptions:
MWException
Returns:
String IP in Hex form

Definition at line 781 of file Block.php.

References list, IP\parseRange(), IP\toHex(), and type.

Referenced by getDatabaseArray().

Get the block name, but with autoblocked IPs hidden as per standard privacy policy.

Returns:
String, text is escaped

Definition at line 910 of file Block.php.

Get the target for this particular Block.

Note that for autoblocks, this returns the unredacted name; frontend functions need to call $block->getRedactedName() in this situation.

Returns:
User|String

Definition at line 1273 of file Block.php.

Get the target and target type for this particular Block.

Note that for autoblocks, this returns the unredacted name; frontend functions need to call $block->getRedactedName() in this situation.

Returns:
array( User|String, Block::TYPE_ constant )
Todo:
FIXME: This should be an integral part of the Block member variables

Definition at line 1263 of file Block.php.

Get the type of target for this particular block.

Returns:
Block::TYPE_ constant, will never be TYPE_ID

Definition at line 1250 of file Block.php.

Block::initFromRow ( row) [protected]

Given a database row from the ipblocks table, initialize member variables.

Parameters:
$rowResultWrapper: a row from the ipblocks table

Definition at line 326 of file Block.php.

References isAutoblocking(), isHardblock(), prevents(), setBlocker(), setTarget(), wfGetDB(), and wfTimestamp().

Referenced by newFromRow().

Block::insert ( dbw = null)

Insert a block into the block table.

Will fail if there is a conflicting block (same name and options) already in the database.

Parameters:
$dbwDatabaseBase if you have one available
Returns:
mixed: false on failure, assoc array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)

Definition at line 398 of file Block.php.

Block::isAutoblocking ( x = null)

Definition at line 870 of file Block.php.

Referenced by __construct(), getDatabaseArray(), and initFromRow().

Has the block expired?

Returns:
Boolean

Definition at line 735 of file Block.php.

Block::isHardblock ( x = null)

Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range.

Parameters:
$xBool
Returns:
Bool

Definition at line 861 of file Block.php.

References wfSetVar().

Referenced by __construct(), getDatabaseArray(), and initFromRow().

Is the block address valid (i.e.

not a null string?)

Returns:
Boolean

Definition at line 750 of file Block.php.

static Block::isWhitelistedFromAutoblocks ( ip) [static]

Checks whether a given IP is on the autoblock whitelist.

TODO: this probably belongs somewhere else, but not sure where...

Parameters:
string$ipThe IP to check
Returns:
Boolean

Definition at line 602 of file Block.php.

static Block::newFromID ( id) [static]

Load a blocked user from their block id.

Parameters:
$idInteger: Block id to search for
Returns:
Block object or null

Definition at line 104 of file Block.php.

static Block::newFromRow ( row) [static]

Create a new Block object from a database row.

Parameters:
$rowResultWrapper row from the ipblocks table
Returns:
Block

Definition at line 362 of file Block.php.

References initFromRow().

static Block::newFromTarget ( specificTarget,
vagueTarget = null,
fromMaster = false 
) [static]

Given a target and the target's type, get an existing Block object if possible.

Parameters:
$specificTargetString|User|Int a block target, which may be one of several types: * A user to block, in which case $target will be a User * An IP to block, in which case $target will be a User generated by using User::newFromName( $ip, false ) to turn off name validation * An IP range, in which case $target will be a String "123.123.123.123/18" etc * The ID of an existing block, in the format "#12345" (since pure numbers are valid usernames Calling this with a user, IP address or range will not select autoblocks, and will only select a block where the targets match exactly (so looking for blocks on 1.2.3.4 will not select 1.2.0.0/16 or even 1.2.3.4/32)
$vagueTargetString|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). Leave empty or blank to skip IP-based lookups.
bool$fromMasterwhether to use the DB_MASTER database
Returns:
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!

Definition at line 970 of file Block.php.

Referenced by BlockTest\addDBData(), ApiUnblock\execute(), SpecialUnblock\execute(), ApiBlock\execute(), User\isBlockedFromCreateAccount(), SpecialUnblock\processUnblock(), and ApiBlockTest\testMakeNormalBlock().

Block::newLoad ( vagueTarget = null) [protected]

Load a block from the database which affects the already-set $this->target: 1) A block directly on the given user or IP 2) A rangeblock encompassing the given IP (smallest first) 3) An autoblock on the given IP.

Parameters:
$vagueTargetUser|String also search for blocks affecting this target. Doesn't make any sense to use TYPE_AUTO / TYPE_ID here. Leave blank to skip IP lookups.
Exceptions:
MWException
Returns:
Bool whether a relevant block was found

Definition at line 178 of file Block.php.

static Block::parseTarget ( target) [static]

From an existing Block, get the target and the type of target.

Note that, except for null, it is always safe to treat the target as a string; for User objects this will return User::__toString() which in turn gives User::getName().

Parameters:
$targetString|Int|User|null
Returns:
array( User|String|null, Block::TYPE_ constant|null )

Definition at line 1194 of file Block.php.

Referenced by BlockListPager\formatValue(), and SpecialBlockList\showList().

Block::prevents ( action,
x = null 
)

Get/set whether the Block prevents a given action.

Parameters:
$actionString
$xBool
Returns:
Bool

Definition at line 886 of file Block.php.

Referenced by __construct(), getDatabaseArray(), and initFromRow().

static Block::purgeExpired ( ) [static]

Purge expired blocks from the ipblocks table.

Definition at line 937 of file Block.php.

Referenced by ApiQueryBlocks\execute(), and SpecialBlockList\showList().

static Block::selectFields ( ) [static]

Return the list of ipblocks fields that should be selected to create a new block.

Returns:
array

Definition at line 124 of file Block.php.

References array().

Block::setBlocker ( user)

Set the user who implemented (or will implement) this block.

Parameters:
$userUser|string Local User object or username string for foreign users

Definition at line 1306 of file Block.php.

Referenced by __construct(), and initFromRow().

Block::setTarget ( target)

Set the target for this block, and update $this->type accordingly.

Parameters:
$targetMixed

Definition at line 1290 of file Block.php.

Referenced by __construct(), and initFromRow().

Update a block in the DB with new parameters.

The ID field needs to be loaded first.

Returns:
bool|array False on failure, array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)

Definition at line 435 of file Block.php.

Update the timestamp on autoblocks.

Definition at line 757 of file Block.php.


Member Data Documentation

User Block::$blocker [protected]

*

Definition at line 40 of file Block.php.

Referenced by getBy(), and getByName().

Integer Block::$forcedTargetID [protected]

Hack for foreign blocking (CentralAuth) *.

Definition at line 36 of file Block.php.

Bool Block::$isAutoblocking = true [protected]

*

Definition at line 44 of file Block.php.

Bool Block::$isHardblock = true [protected]

*

Definition at line 42 of file Block.php.

Block::$mAuto

Definition at line 23 of file Block.php.

Block::$mBlockEmail

Definition at line 26 of file Block.php.

Block::$mCreateAccount

Definition at line 26 of file Block.php.

Block::$mDisableUsertalk

Definition at line 26 of file Block.php.

Block::$mExpiry

Definition at line 23 of file Block.php.

Block::$mFromMaster

Definition at line 26 of file Block.php.

Block::$mHideName

Definition at line 23 of file Block.php.

Block::$mId [protected]

Definition at line 26 of file Block.php.

Block::$mParentBlockId

Definition at line 26 of file Block.php.

Block::$mReason

Definition at line 23 of file Block.php.

Block::$mTimestamp

Definition at line 23 of file Block.php.

User String Block::$target [protected]

*

Definition at line 34 of file Block.php.

Integer Block::$type [protected]

Block::TYPE_ constant.

Can only be USER, IP or RANGE internally *

Definition at line 38 of file Block.php.

const Block::TYPE_ID = 5

Definition at line 51 of file Block.php.

Referenced by SpecialUnblock\execute(), and SpecialBlockList\showList().


The documentation for this class was generated from the following file: