BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
Block Class Reference

Public Member Functions

 __construct ($options=[])
 
 equals (Block $block)
 
 delete ()
 
 insert ($dbw=null)
 
 update ()
 
 doAutoblock ($autoblockIP)
 
 deleteIfExpired ()
 
 isExpired ()
 
 isValid ()
 
 updateTimestamp ()
 
 getRangeStart ()
 
 getRangeEnd ()
 
 getBy ()
 
 getByName ()
 
 getId ()
 
 fromMaster ($x=null)
 
 isHardblock ($x=null)
 
 isAutoblocking ($x=null)
 
 prevents ($action, $x=null)
 
 getRedactedName ()
 
 getType ()
 
 getTargetAndType ()
 
 getTarget ()
 
 getExpiry ()
 
 setTarget ($target)
 
 getBlocker ()
 
 setBlocker ($user)
 
 getPermissionsError (IContextSource $context)
 

Static Public Member Functions

static newFromID ($id)
 
static selectFields ()
 
static getRangeCond ($start, $end=null)
 
static newFromRow ($row)
 
static isWhitelistedFromAutoblocks ($ip)
 
static getAutoblockExpiry ($timestamp)
 
static purgeExpired ()
 
static newFromTarget ($specificTarget, $vagueTarget=null, $fromMaster=false)
 
static getBlocksForIPList (array $ipChain, $isAnon, $fromMaster=false)
 
static parseTarget ($target)
 

Public Attributes

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

Protected Member Functions

 newLoad ($vagueTarget=null)
 
 initFromRow ($row)
 
 getDatabaseArray ($db=null)
 
 getAutoblockUpdateArray ()
 
 doRetroactiveAutoblock ()
 

Static Protected Member Functions

static getIpFragment ($hex)
 
static defaultRetroactiveAutoblock (Block $block, array &$blockIds)
 

Protected Attributes

 $mId
 
 $mFromMaster
 
 $mBlockEmail
 
 $mDisableUsertalk
 
 $mCreateAccount
 
 $target
 
 $forcedTargetID
 
 $type
 
 $blocker
 
 $isHardblock
 
 $isAutoblocking
 

Constructor & Destructor Documentation

Block::__construct (   $options = [])

Create a new block with specified parameters on a user, IP or IP range.

Parameters
array$optionsParameters of the block: address string|User Target user name, User object, IP address or IP range user int Override target user ID (for foreign users) by int User ID of the blocker reason string Reason of the block timestamp string The time at which the block comes into effect auto bool Is this an automatic block? expiry string Timestamp of expiration of the block or 'infinity' anonOnly bool Only disallow anonymous actions createAccount bool Disallow creation of new accounts enableAutoblock bool Enable automatic blocking hideName bool Hide the target user name blockEmail bool Disallow sending emails allowUsertalk bool Allow the target to edit its own talk page byText string Username of the blocker (for foreign users)
Since
1.26 accepts $options array instead of individual parameters; order of parameters above reflects the original order

Member Function Documentation

static Block::defaultRetroactiveAutoblock ( Block  $block,
array &  $blockIds 
)
staticprotected

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
Block::delete ( )

Delete the row from the IP blocks table.

Exceptions
MWException
Returns
bool
Block::deleteIfExpired ( )

Check if a block has expired. Delete it if it is.

Returns
bool
Block::doAutoblock (   $autoblockIP)

Autoblocks the given IP, referring to this Block.

Parameters
string$autoblockIPThe IP to autoblock.
Returns
int|bool Block ID if an autoblock was inserted, false if not.
Block::doRetroactiveAutoblock ( )
protected

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
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
Block$block
Returns
bool
Block::fromMaster (   $x = null)

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

Parameters
bool | null$x
Returns
bool
static Block::getAutoblockExpiry (   $timestamp)
static

Get a timestamp of the expiry for autoblocks

Parameters
string | int$timestamp
Returns
string
Block::getAutoblockUpdateArray ( )
protected
Returns
array
Block::getBlocker ( )

Get the user who implemented this block

Returns
User|string Local User object or string for a foreign user
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 Array of Blocks
Since
1.22
Block::getBy ( )

Get the user id of the blocking sysop

Returns
int (0 for foreign users)
Block::getByName ( )

Get the username of the blocking sysop

Returns
string
Block::getDatabaseArray (   $db = null)
protected

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

Parameters
IDatabase$db
Returns
array
Block::getExpiry ( )
Since
1.19
Returns
mixed|string
Block::getId ( )

Get the block ID

Returns
int
static Block::getIpFragment (   $hex)
staticprotected

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
string$hexHexadecimal IP representation
Returns
string
Block::getPermissionsError ( IContextSource  $context)

Get the key and parameters for the corresponding error message.

Since
1.22
Parameters
IContextSource$context
Returns
array
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
Block::getRangeEnd ( )

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

Exceptions
MWException
Returns
string IP in Hex form
Block::getRangeStart ( )

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

Exceptions
MWException
Returns
string IP in Hex form
Block::getRedactedName ( )

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

Returns
string Text is escaped
Block::getTarget ( )

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
Block::getTargetAndType ( )

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
Block::getType ( )

Get the type of target for this particular block

Returns
int Block::TYPE_ constant, will never be TYPE_ID
Block::initFromRow (   $row)
protected

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

Parameters
stdClass$rowA row from the ipblocks table
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
IDatabase$dbwIf you have one available
Returns
bool|array False on failure, assoc array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)
Block::isAutoblocking (   $x = null)
Parameters
null | bool$x
Returns
bool
Block::isExpired ( )

Has the block expired?

Returns
bool
Block::isHardblock (   $x = null)

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

Parameters
bool | null$x
Returns
bool
Block::isValid ( )

Is the block address valid (i.e. not a null string?)

Returns
bool
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
bool
static Block::newFromID (   $id)
static

Load a blocked user from their block id.

Parameters
int$idBlock id to search for
Returns
Block|null
static Block::newFromRow (   $row)
static

Create a new Block object from a database row

Parameters
stdClass$rowRow from the ipblocks table
Returns
Block
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
string | User | int$specificTargetA 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)
string | User | int$vagueTargetAs 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!
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
User | string$vagueTargetAlso 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
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
string | int | User | null$target
Returns
array( User|String|null, Block::TYPE_ constant|null )
Block::prevents (   $action,
  $x = null 
)

Get/set whether the Block prevents a given action

Parameters
string$actionAction to check
bool | null$xValue for set, or null to just get value
Returns
bool|null Null for unrecognized rights.
static Block::purgeExpired ( )
static

Purge expired blocks from the ipblocks table

static Block::selectFields ( )
static

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

Returns
array
Block::setBlocker (   $user)

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

Parameters
User | string$userLocal User object or username string for foreign users
Block::setTarget (   $target)

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

Parameters
mixed$target
Block::update ( )

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)
Block::updateTimestamp ( )

Update the timestamp on autoblocks.


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