MediaWiki  master
Block Class Reference
Collaboration diagram for Block:

Public Member Functions

 __construct ( $options=[])
 Create a new block with specified parameters on a user, IP or IP range. More...
 
 appliesToNamespace ( $ns)
 Checks if a block applies to a particular namespace. More...
 
 appliesToPage ( $pageId)
 Checks if a block applies to a particular page. More...
 
 appliesToPasswordReset ()
 Check if the block prevents a user from resetting their password. More...
 
 appliesToRight ( $right)
 Determine whether the Block prevents a given right. More...
 
 appliesToTitle (Title $title)
 Checks if a block applies to a particular title. More...
 
 appliesToUsertalk (Title $usertalk=null)
 Determine whether the block allows the user to edit their own user talk page. More...
 
 delete ()
 Delete the row from the IP blocks table. More...
 
 deleteIfExpired ()
 Check if a block has expired. More...
 
 doAutoblock ( $autoblockIP)
 Autoblocks the given IP, referring to this Block. More...
 
 equals (Block $block)
 Check if two blocks are effectively equal. More...
 
 fromMaster ( $x=null)
 Get/set a flag determining whether the master is used for reads. More...
 
 getBlocker ()
 Get the user who implemented this block. More...
 
 getBlockErrorParams (IContextSource $context)
 Get block information used in different block error messages. More...
 
 getBy ()
 Get the user id of the blocking sysop. More...
 
 getByName ()
 Get the username of the blocking sysop. More...
 
 getCookieValue ()
 Get the BlockID cookie's value for this block. More...
 
 getExpiry ()
 Get the block expiry time. More...
 
 getHideName ()
 Get whether the block hides the target's username. More...
 
 getId ()
 Get the block ID. More...
 
 getPermissionsError (IContextSource $context)
 Get the key and parameters for the corresponding error message. More...
 
 getRangeEnd ()
 Get the IP address at the end of the range in Hex form. More...
 
 getRangeStart ()
 Get the IP address at the start of the range in Hex form. More...
 
 getReason ()
 Get the reason given for creating the block. More...
 
 getRedactedName ()
 Get the block name, but with autoblocked IPs hidden as per standard privacy policy. More...
 
 getRestrictions ()
 Get Restrictions. More...
 
 getSystemBlockType ()
 Get the system block type, if any. More...
 
 getTarget ()
 Get the target for this particular Block. More...
 
 getTargetAndType ()
 Get the target and target type for this particular Block. More...
 
 getTimestamp ()
 Get the timestamp indicating when the block was created. More...
 
 getType ()
 Get the type of target for this particular block. More...
 
 insert ( $dbw=null)
 Insert a block into the block table. More...
 
 isAutoblocking ( $x=null)
 
 isCreateAccountBlocked ( $x=null)
 Get or set the flag indicating whether this block blocks the target from creating an account. More...
 
 isEmailBlocked ( $x=null)
 Get or set the flag indicating whether this block blocks the target from sending emails. More...
 
 isExpired ()
 Has the block expired? More...
 
 isHardblock ( $x=null)
 Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range) More...
 
 isSitewide ( $x=null)
 Indicates that the block is a sitewide block. More...
 
 isUsertalkEditAllowed ( $x=null)
 Get or set the flag indicating whether this block blocks the target from editing their own user talk page. More...
 
 isValid ()
 Is the block address valid (i.e. More...
 
 prevents ( $action, $x=null)
 Get/set whether the Block prevents a given action. More...
 
 setBlocker ( $user)
 Set the user who implemented (or will implement) this block. More...
 
 setCookie (WebResponse $response)
 Set the 'BlockID' cookie to this block's ID and expiry time. More...
 
 setExpiry ( $expiry)
 Set the block expiry time. More...
 
 setHideName ( $hideName)
 Set whether ths block hides the target's username. More...
 
 setReason ( $reason)
 Set the reason for creating the block. More...
 
 setRestrictions (array $restrictions)
 Set Restrictions. More...
 
 setTarget ( $target)
 Set the target for this block, and update $this->type accordingly. More...
 
 setTimestamp ( $timestamp)
 Set the timestamp indicating when the block was created. More...
 
 shouldTrackWithCookie ( $isIpUser)
 Check if the block should be tracked with a cookie. More...
 
 update ()
 Update a block in the DB with new parameters. More...
 
 updateTimestamp ()
 Update the timestamp on autoblocks. More...
 

Static Public Member Functions

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

Public Attributes

bool $mAuto
 
string $mExpiry
 
bool $mHideName
 
int $mParentBlockId
 
string $mReason
 
string $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. More...
 
 getAutoblockUpdateArray (IDatabase $dbw)
 
 getDatabaseArray (IDatabase $dbw)
 Get an array suitable for passing to $dbw->insert() or $dbw->update() More...
 
 initFromRow ( $row)
 Given a database row from the ipblocks table, initialize member variables. More...
 
 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. More...
 

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. More...
 
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. More...
 

Private Member Functions

 findRestriction ( $type, $value)
 Find Restriction by type and value. More...
 
 setId ( $blockId)
 Set the block ID. More...
 

Private Attributes

bool $allowUsertalk
 
bool $blockCreateAccount
 
User $blocker
 
int $forcedTargetID
 Hack for foreign blocking (CentralAuth) More...
 
bool $isAutoblocking
 
bool $isHardblock
 
bool $isSitewide
 
bool $mBlockEmail
 
bool $mFromMaster
 
int $mId
 
Restriction [] $restrictions
 
string null $systemBlockType
 
User string $target
 
int $type
 Block::TYPE_ constant. More...
 

Detailed Description

Definition at line 31 of file Block.php.

Constructor & Destructor Documentation

◆ __construct()

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) systemBlock string Indicate that this block is automatically created by MediaWiki rather than being stored in the database. Value is a string to return from self::getSystemBlockType(). sitewide bool Disallow editing all pages and all contribution actions, except those specifically allowed by other block flags
Since
1.26 accepts $options array instead of individual parameters; order of parameters above reflects the original order

Definition at line 131 of file Block.php.

References $options, DB_REPLICA, isAutoblocking(), isCreateAccountBlocked(), isEmailBlocked(), isHardblock(), isSitewide(), isUsertalkEditAllowed(), User\newFromId(), null, setBlocker(), setExpiry(), setHideName(), setReason(), setTarget(), setTimestamp(), wfGetDB(), and wfTimestamp().

Member Function Documentation

◆ appliesToNamespace()

Block::appliesToNamespace (   $ns)

Checks if a block applies to a particular namespace.

Since
1.33
Parameters
int$ns
Returns
bool

Definition at line 2060 of file Block.php.

References findRestriction(), and isSitewide().

Referenced by appliesToUsertalk().

◆ appliesToPage()

Block::appliesToPage (   $pageId)

Checks if a block applies to a particular page.

This check does not consider whether $this->isUsertalkEditAllowed returns false, as the identity of the user making the hypothetical edit isn't known here (particularly in the case of IP hardblocks, range blocks, and auto-blocks).

Since
1.33
Parameters
int$pageId
Returns
bool

Definition at line 2088 of file Block.php.

References findRestriction(), and isSitewide().

Referenced by appliesToUsertalk().

◆ appliesToPasswordReset()

Block::appliesToPasswordReset ( )

Check if the block prevents a user from resetting their password.

Since
1.33
Returns
bool The block blocks password reset

Definition at line 2151 of file Block.php.

References getSystemBlockType(), isCreateAccountBlocked(), and null.

◆ appliesToRight()

Block::appliesToRight (   $right)

Determine whether the Block prevents a given right.

A right may be blacklisted or whitelisted, or determined from a property on the Block object. For certain rights, the property may be overridden according to global configs.

Since
1.33
Parameters
string$rightRight to check
Returns
bool|null null if unrecognized right or unset property

Definition at line 1227 of file Block.php.

References $res, RequestContext\getMain(), isCreateAccountBlocked(), isEmailBlocked(), isSitewide(), null, and User.

Referenced by chooseBlock(), and User\isBlockedFromCreateAccount().

◆ appliesToTitle()

Block::appliesToTitle ( Title  $title)

Checks if a block applies to a particular title.

This check does not consider whether $this->isUsertalkEditAllowed returns false, as the identity of the user making the hypothetical edit isn't known here (particularly in the case of IP hardblocks, range blocks, and auto-blocks).

Parameters
Title$title
Returns
bool

Definition at line 2037 of file Block.php.

References as, getRestrictions(), and isSitewide().

◆ appliesToUsertalk()

Block::appliesToUsertalk ( Title  $usertalk = null)

Determine whether the block allows the user to edit their own user talk page.

This is done separately from Block::appliesToRight because there is no right for editing one's own user talk page and because the user's talk page needs to be passed into the Block object, which is unaware of the user.

The ipb_allow_usertalk flag (which corresponds to the property allowUsertalk) is used on sitewide blocks and partial blocks that contain a namespace restriction on the user talk namespace, but do not contain a page restriction on the user's talk page. For all other (i.e. most) partial blocks, the flag is ignored, and the user can always edit their user talk page unless there is a page restriction on their user talk page, in which case they can never edit it. (Ideally the flag would be stored as null in these cases, but the database field isn't nullable.)

This method does not validate that the passed in talk page belongs to the block target since the target (an IP) might not be the same as the user's talk page (if they are logged in).

Since
1.33
Parameters
Title | null$usertalkThe user's user talk page. If null, and if the target is a User, the target's userpage is used
Returns
bool The user can edit their talk page

Definition at line 1991 of file Block.php.

References appliesToNamespace(), appliesToPage(), RequestContext\getMain(), isSitewide(), isUsertalkEditAllowed(), and NS_USER_TALK.

◆ chooseBlock()

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 This should be used when $blocks where retrieved from the user's IP address and $ipChain is populated from the same IP address information.
Parameters
array$blocksArray of Block objects
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, ...)
Exceptions
MWException
Returns
Block|null The "best" block from the list

Definition at line 1517 of file Block.php.

References appliesToRight(), as, false, isHardblock(), null, and IP\toHex().

Referenced by User\getBlockedStatus(), and BlockTest\testBlocksOnXff().

◆ clearCookie()

static Block::clearCookie ( WebResponse  $response)
static

Unset the 'BlockID' cookie.

Since
1.29
Parameters
WebResponse$responseThe response on which to unset the cookie.

Definition at line 1809 of file Block.php.

References WebResponse\clearCookie().

Referenced by User\getBlockFromCookieValue().

◆ defaultRetroactiveAutoblock()

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

Definition at line 757 of file Block.php.

References $dbr, $options, $res, $wgPutIPinRC, as, DB_REPLICA, doAutoblock(), getTarget(), getType(), ActorMigration\newMigration(), wfDebug(), and wfGetDB().

◆ delete()

Block::delete ( )

Delete the row from the IP blocks table.

Exceptions
MWException
Returns
bool

Definition at line 515 of file Block.php.

References DB_MASTER, getId(), wfGetDB(), and wfReadOnly().

◆ deleteIfExpired()

Block::deleteIfExpired ( )

Check if a block has expired.

Delete it if it is.

Returns
bool

Definition at line 937 of file Block.php.

References isExpired(), and wfDebug().

◆ doAutoblock()

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.

Definition at line 856 of file Block.php.

References $mId, getBlocker(), getExpiry(), getHideName(), getReason(), getRestrictions(), getSystemBlockType(), getTarget(), isAutoblocking(), isCreateAccountBlocked(), isSitewide(), isUsertalkEditAllowed(), null, plain, Hooks\run(), wfDebug(), wfMessage(), and wfTimestampNow().

Referenced by defaultRetroactiveAutoblock().

◆ doRetroactiveAutoblock()

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

Definition at line 734 of file Block.php.

References getTarget(), getType(), isAutoblocking(), Hooks\run(), and wfDebug().

Referenced by insert(), and update().

◆ equals()

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

Definition at line 292 of file Block.php.

References getExpiry(), getHideName(), getReason(), getRestrictions(), isAutoblocking(), isCreateAccountBlocked(), isEmailBlocked(), isHardblock(), isSitewide(), and isUsertalkEditAllowed().

◆ findRestriction()

Block::findRestriction (   $type,
  $value 
)
private

Find Restriction by type and value.

Parameters
string$type
int$value
Returns
Restriction|null

Definition at line 2110 of file Block.php.

References $type, $value, as, getRestrictions(), and null.

Referenced by appliesToNamespace(), and appliesToPage().

◆ fromMaster()

Block::fromMaster (   $x = null)

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

Parameters
bool | null$x
Returns
bool

Definition at line 1133 of file Block.php.

References wfSetVar().

◆ getAutoblockExpiry()

static Block::getAutoblockExpiry (   $timestamp)
static

Get a timestamp of the expiry for autoblocks.

Parameters
string | int$timestamp
Returns
string

Definition at line 1346 of file Block.php.

References $wgAutoblockExpiry, and wfTimestamp().

◆ getAutoblockUpdateArray()

Block::getAutoblockUpdateArray ( IDatabase  $dbw)
protected
Parameters
IDatabase$dbw
Returns
array

Definition at line 718 of file Block.php.

References getBlocker(), getHideName(), getReason(), CommentStore\getStore(), isCreateAccountBlocked(), isSitewide(), isUsertalkEditAllowed(), and ActorMigration\newMigration().

Referenced by update().

◆ getBlocker()

Block::getBlocker ( )

Get the user who implemented this block.

Returns
User User object. May name a foreign user.

Definition at line 1755 of file Block.php.

References $blocker.

Referenced by doAutoblock(), getAutoblockUpdateArray(), getBlockErrorParams(), getBy(), getByName(), getDatabaseArray(), and insert().

◆ getBlockErrorParams()

Block::getBlockErrorParams ( IContextSource  $context)

Get block information used in different block error messages.

Since
1.33
Parameters
IContextSource$context
Returns
array

Definition at line 1896 of file Block.php.

References $blocker, $lang, $link, getBlocker(), getByName(), getExpiry(), getId(), IContextSource\getLanguage(), getReason(), IContextSource\getRequest(), getSystemBlockType(), getTarget(), IContextSource\getUser(), User\getUserPage(), MessageLocalizer\msg(), and string.

Referenced by getPermissionsError().

◆ getBlocksForIPList()

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 replica DB
Returns
array Array of Blocks
Since
1.22

Definition at line 1436 of file Block.php.

References $rows, as, DB_MASTER, DB_REPLICA, IP\isValid(), LIST_OR, IP\toHex(), and wfGetDB().

Referenced by User\getBlockedStatus(), and BlockTest\testBlocksOnXff().

◆ getBy()

Block::getBy ( )

Get the user id of the blocking sysop.

Returns
int (0 for foreign users)

Definition at line 1041 of file Block.php.

References getBlocker().

Referenced by ApiQueryUserInfo\getBlockInfo().

◆ getByName()

Block::getByName ( )

Get the username of the blocking sysop.

Returns
string

Definition at line 1050 of file Block.php.

References getBlocker().

Referenced by getBlockErrorParams(), and ApiQueryUserInfo\getBlockInfo().

◆ getCookieValue()

Block::getCookieValue ( )

Get the BlockID cookie's value for this block.

This is usually the block ID concatenated with an HMAC in order to avoid spoofing (T152951), but if wgSecretKey is not set will just be the block ID.

Since
1.29
Returns
string The block ID, probably concatenated with "!" and the HMAC.

Definition at line 1822 of file Block.php.

References getId(), RequestContext\getMain(), and MWCryptHash\hmac().

Referenced by setCookie().

◆ getDatabaseArray()

◆ getExpiry()

Block::getExpiry ( )

Get the block expiry time.

Since
1.19
Returns
string

Definition at line 1709 of file Block.php.

References $mExpiry.

Referenced by doAutoblock(), equals(), getBlockErrorParams(), ApiQueryUserInfo\getBlockInfo(), getDatabaseArray(), isExpired(), and setCookie().

◆ getHideName()

Block::getHideName ( )

Get whether the block hides the target's username.

Since
1.33
Returns
bool The block hides the username

Definition at line 1104 of file Block.php.

References $mHideName.

Referenced by doAutoblock(), equals(), getAutoblockUpdateArray(), and getDatabaseArray().

◆ getId()

◆ getIdFromCookieValue()

static Block::getIdFromCookieValue (   $cookieValue)
static

Get the stored ID from the 'BlockID' cookie.

The cookie's value is usually a combination of the ID and a HMAC (see Block::setCookie), but will sometimes only be the ID.

Since
1.29
Parameters
string$cookieValueThe string in which to find the ID.
Returns
int|null The block ID, or null if the HMAC is present and invalid.

Definition at line 1845 of file Block.php.

References false, RequestContext\getMain(), MWCryptHash\hmac(), and null.

Referenced by User\getBlockFromCookieValue(), and UserTest\testAutoblockCookies().

◆ getIpFragment()

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

Definition at line 454 of file Block.php.

References $wgBlockCIDRLimit.

◆ getPermissionsError()

Block::getPermissionsError ( IContextSource  $context)

Get the key and parameters for the corresponding error message.

Since
1.22
Parameters
IContextSource$context
Returns
array

Definition at line 1872 of file Block.php.

References $params, getBlockErrorParams(), getSystemBlockType(), isSitewide(), and null.

Referenced by UserBlockedError\__construct().

◆ getQueryInfo()

static Block::getQueryInfo ( )
static

Return the tables, fields, and join conditions to be selected to create a new block object.

Since
1.31
Returns
array With three keys:
  • tables: (string[]) to include in the $table to IDatabase->select()
  • fields: (string[]) to include in the $vars to IDatabase->select()
  • joins: (array) to include in the $join_conds to IDatabase->select()

Definition at line 260 of file Block.php.

References CommentStore\getStore(), and ActorMigration\newMigration().

Referenced by CleanupBlocks\execute(), and BlockTest\testNewFromRow().

◆ getRangeCond()

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 | null$endHexadecimal IP representation, or null to use $start = $end
Returns
string

Definition at line 421 of file Block.php.

References $dbr, DB_REPLICA, LIST_AND, null, and wfGetDB().

Referenced by SpecialBlockList\getBlockListPager().

◆ getRangeEnd()

Block::getRangeEnd ( )

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

Exceptions
MWException
Returns
string IP in Hex form

Definition at line 1022 of file Block.php.

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

Referenced by getDatabaseArray().

◆ getRangeStart()

Block::getRangeStart ( )

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

Exceptions
MWException
Returns
string IP in Hex form

Definition at line 1003 of file Block.php.

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

Referenced by getDatabaseArray().

◆ getReason()

Block::getReason ( )

Get the reason given for creating the block.

Since
1.33
Returns
string

Definition at line 1084 of file Block.php.

References $mReason.

Referenced by doAutoblock(), equals(), getAutoblockUpdateArray(), getBlockErrorParams(), ApiQueryUserInfo\getBlockInfo(), and getDatabaseArray().

◆ getRedactedName()

Block::getRedactedName ( )

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

Returns
string Text is escaped

Definition at line 1328 of file Block.php.

References Html\element(), getTarget(), text, and wfMessage().

◆ getRestrictions()

Block::getRestrictions ( )

Get Restrictions.

Getting the restrictions will perform a database query if the restrictions are not already loaded.

Since
1.33
Returns
Restriction[]

Definition at line 1937 of file Block.php.

References $restrictions, and null.

Referenced by appliesToTitle(), doAutoblock(), equals(), and findRestriction().

◆ getSystemBlockType()

Block::getSystemBlockType ( )

Get the system block type, if any.

Since
1.29
Returns
string|null

Definition at line 1123 of file Block.php.

References $systemBlockType.

Referenced by appliesToPasswordReset(), doAutoblock(), getBlockErrorParams(), ApiQueryUserInfo\getBlockInfo(), getPermissionsError(), and insert().

◆ getTarget()

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

Definition at line 1699 of file Block.php.

References $target.

Referenced by defaultRetroactiveAutoblock(), doAutoblock(), doRetroactiveAutoblock(), getBlockErrorParams(), getRedactedName(), getTargetAndType(), and isValid().

◆ getTargetAndType()

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

Definition at line 1689 of file Block.php.

References getTarget(), and getType().

◆ getTimestamp()

Block::getTimestamp ( )

Get the timestamp indicating when the block was created.

Since
1.33
Returns
string

Definition at line 1729 of file Block.php.

References $mTimestamp.

Referenced by ApiQueryUserInfo\getBlockInfo(), and updateTimestamp().

◆ getType()

Block::getType ( )

Get the type of target for this particular block.

Autoblocks have whichever type corresponds to their target, so to detect if a block is an autoblock, we have to check the mAuto property instead.

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

Definition at line 1676 of file Block.php.

References $type.

Referenced by defaultRetroactiveAutoblock(), ApiBase\dieBlocked(), doRetroactiveAutoblock(), getTargetAndType(), isAutoblocking(), isHardblock(), SpecialBlock\maybeAlterFormDefaults(), and shouldTrackWithCookie().

◆ initFromRow()

Block::initFromRow (   $row)
protected

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

Parameters
stdClass$rowA row from the ipblocks table

Definition at line 468 of file Block.php.

References DB_REPLICA, CommentStore\getStore(), isAutoblocking(), isCreateAccountBlocked(), isEmailBlocked(), isHardblock(), isSitewide(), isUsertalkEditAllowed(), User\newFromAnyId(), null, setBlocker(), setExpiry(), setHideName(), setReason(), setTarget(), setTimestamp(), text, wfGetDB(), and wfTimestamp().

Referenced by newFromRow(), and newLoad().

◆ insert()

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 | null$dbwIf you have one available
Returns
bool|array False on failure, assoc array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)

Definition at line 543 of file Block.php.

References $mId, $wgBlockDisablesLogin, DB_MASTER, doRetroactiveAutoblock(), getBlocker(), getDatabaseArray(), getSystemBlockType(), insert, null, setId(), wfDebug(), and wfGetDB().

Referenced by LocalIdLookupTest\addDBData(), ApiUnblockTest\setUp(), ApiBlockTest\testBlockByBlockedUser(), ApiUserrightsTest\testBlockedWithoutUserrights(), ApiUserrightsTest\testBlockedWithUserrights(), ApiQueryBlocksTest\testExecuteBlock(), ApiQueryBlocksTest\testExecuteRestrictions(), ApiQueryBlocksTest\testExecuteSitewide(), BlockTest\testNewFromRow(), ApiUnblockTest\testUnblockSelfWhenBlocked(), and ApiUnblockTest\testUnblockWhenBlocked().

◆ isAutoblocking()

Block::isAutoblocking (   $x = null)
Parameters
null | bool$x
Returns
bool

Definition at line 1155 of file Block.php.

References getType(), and wfSetVar().

Referenced by __construct(), doAutoblock(), doRetroactiveAutoblock(), equals(), getDatabaseArray(), initFromRow(), shouldTrackWithCookie(), and update().

◆ isCreateAccountBlocked()

Block::isCreateAccountBlocked (   $x = null)

Get or set the flag indicating whether this block blocks the target from creating an account.

(Note that the flag may be overridden depending on global configs.)

Since
1.33
Parameters
null | bool$xValue to set (if null, just get the property value)
Returns
bool Value of the property

Definition at line 1187 of file Block.php.

References wfSetVar().

Referenced by __construct(), appliesToPasswordReset(), appliesToRight(), doAutoblock(), equals(), getAutoblockUpdateArray(), getDatabaseArray(), and initFromRow().

◆ isEmailBlocked()

Block::isEmailBlocked (   $x = null)

Get or set the flag indicating whether this block blocks the target from sending emails.

(Note that the flag may be overridden depending on global configs.)

Since
1.33
Parameters
null | bool$xValue to set (if null, just get the property value)
Returns
bool Value of the property

Definition at line 1200 of file Block.php.

References wfSetVar().

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

◆ isExpired()

Block::isExpired ( )

Has the block expired?

Returns
bool

Definition at line 954 of file Block.php.

References getExpiry(), wfDebug(), and wfTimestampNow().

Referenced by deleteIfExpired().

◆ isHardblock()

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

Definition at line 1142 of file Block.php.

References $isHardblock, getType(), true, and wfSetVar().

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

◆ isSitewide()

Block::isSitewide (   $x = null)

Indicates that the block is a sitewide block.

This means the user is prohibited from editing any page on the site (other than their own talk page).

Since
1.33
Parameters
null | bool$x
Returns
bool

Definition at line 1174 of file Block.php.

References wfSetVar().

Referenced by __construct(), appliesToNamespace(), appliesToPage(), appliesToRight(), appliesToTitle(), appliesToUsertalk(), ApiBase\dieBlocked(), doAutoblock(), equals(), getAutoblockUpdateArray(), ApiQueryUserInfo\getBlockInfo(), getDatabaseArray(), getPermissionsError(), initFromRow(), SpecialBlock\maybeAlterFormDefaults(), and prevents().

◆ isUsertalkEditAllowed()

Block::isUsertalkEditAllowed (   $x = null)

Get or set the flag indicating whether this block blocks the target from editing their own user talk page.

(Note that the flag may be overridden depending on global configs.)

Since
1.33
Parameters
null | bool$xValue to set (if null, just get the property value)
Returns
bool Value of the property

Definition at line 1213 of file Block.php.

References wfSetVar().

Referenced by __construct(), appliesToUsertalk(), doAutoblock(), equals(), getAutoblockUpdateArray(), getDatabaseArray(), initFromRow(), and prevents().

◆ isValid()

Block::isValid ( )

Is the block address valid (i.e.

not a null string?)

Deprecated:
since 1.33 No longer needed in core.
Returns
bool

Definition at line 971 of file Block.php.

References getTarget(), null, and wfDeprecated().

◆ isWhitelistedFromAutoblocks()

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

Definition at line 810 of file Block.php.

References $cache, $line, $lines, array(), as, DB_REPLICA, IP\isInRange(), plain, wfDebug(), wfGetDB(), and wfMessage().

◆ newFromID()

static Block::newFromID (   $id)
static

Load a block from the block id.

Parameters
int$idBlock id to search for
Returns
Block|null

Definition at line 192 of file Block.php.

References $dbr, $res, DB_REPLICA, null, and wfGetDB().

Referenced by User\getBlockFromCookieValue(), ApiUnblockTest\setUp(), BlockTest\testCrappyCrossWikiBlocks(), BlockTest\testINewFromIDReturnsCorrectBlock(), and BlockTest\testRestrictionsFromDatabase().

◆ newFromRow()

static Block::newFromRow (   $row)
static

Create a new Block object from a database row.

Parameters
stdClass$rowRow from the ipblocks table
Returns
Block

Definition at line 503 of file Block.php.

References initFromRow().

Referenced by CleanupBlocks\execute(), and BlockTest\testNewFromRow().

◆ newFromTarget()

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 | null$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!

Definition at line 1397 of file Block.php.

References list, and null.

Referenced by BlockTest\addBlockForUser(), SpecialContributions\contributionsSub(), ApiBlockTest\doBlock(), ApiUnblock\execute(), ApiBlock\execute(), SpecialUnblock\execute(), User\getBlockedStatus(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProviderTest\getBlockedUser(), ApiUnblockTest\getBlockFromParams(), Article\getRobotPolicy(), DeletedContributionsPage\getSubTitle(), User\isBlockedFromCreateAccount(), SpecialBlock\maybeAlterFormDefaults(), SpecialBlock\processForm(), SpecialUnblock\processUnblock(), EditPage\showIntro(), Article\showMissingArticle(), User\spreadBlock(), BlockTest\testBlockedUserCanNotCreateAccount(), ApiBlockTest\testBlockWithoutRestrictions(), ApiBlockTest\testBlockWithRestrictions(), MediaWiki\Auth\AuthManagerTest\testCheckAccountCreatePermissions(), BlockTest\testCrappyCrossWikiBlocks(), ApiEditPageTest\testEditWhileBlocked(), BlockTest\testINewFromTargetReturnsCorrectBlock(), SpecialBlockTest\testMaybeAlterFormDefaults(), SpecialBlockTest\testMaybeAlterFormDefaultsPartial(), ApiMoveTest\testMoveWhileBlocked(), SpecialBlockTest\testProcessForm(), SpecialBlockTest\testProcessFormExisting(), SpecialBlockTest\testProcessFormRestrictions(), SpecialBlockTest\testProcessFormRestrictionsChange(), and BlockTest\testT31116NewFromTargetWithEmptyIp().

◆ newLoad()

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 | null$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

Definition at line 322 of file Block.php.

References $res, as, DB_MASTER, DB_REPLICA, initFromRow(), list, LIST_OR, null, IP\parseRange(), string, IP\toHex(), type, and wfGetDB().

◆ parseTarget()

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 ]

Definition at line 1619 of file Block.php.

References $target, IP\isValid(), IP\isValidRange(), User\newFromName(), null, IP\sanitizeIP(), and IP\sanitizeRange().

Referenced by BlockListPager\formatValue(), SpecialBlockList\getBlockListPager(), SpecialBlock\getTargetAndType(), and SpecialBlock\setParameter().

◆ prevents()

Block::prevents (   $action,
  $x = null 
)

Get/set whether the Block prevents a given action.

Deprecated:
since 1.33, use appliesToRight to determine block behaviour, and specific methods to get/set properties
Parameters
string$actionAction to check
bool | null$xValue for set, or null to just get value
Returns
bool|null Null for unrecognized rights.

Definition at line 1273 of file Block.php.

References $res, RequestContext\getMain(), isSitewide(), isUsertalkEditAllowed(), null, User, and wfSetVar().

◆ purgeExpired()

◆ selectFields()

static Block::selectFields ( )
static

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

Deprecated:
since 1.31, use self::getQueryInfo() instead.
Returns
array

Definition at line 216 of file Block.php.

References $wgActorTableSchemaMigrationStage, CommentStore\getStore(), SCHEMA_COMPAT_READ_NEW, and wfDeprecated().

◆ setBlocker()

Block::setBlocker (   $user)

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

Parameters
User | string$userLocal User object or username string

Definition at line 1763 of file Block.php.

References $user, User\isUsableName(), and User\newFromName().

Referenced by __construct(), and initFromRow().

◆ setCookie()

Block::setCookie ( WebResponse  $response)

Set the 'BlockID' cookie to this block's ID and expiry time.

The cookie's expiry will be the same as the block's, to a maximum of 24 hours.

Since
1.29
Parameters
WebResponse$responseThe response on which to set the cookie.

Definition at line 1785 of file Block.php.

References $expiryTime, false, getCookieValue(), getExpiry(), WebResponse\setCookie(), and wfTimestamp().

◆ setExpiry()

Block::setExpiry (   $expiry)

Set the block expiry time.

Since
1.33
Parameters
string$expiry

Definition at line 1719 of file Block.php.

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

◆ setHideName()

Block::setHideName (   $hideName)

Set whether ths block hides the target's username.

Since
1.33
Parameters
bool$hideNameThe block hides the username

Definition at line 1114 of file Block.php.

Referenced by __construct(), and initFromRow().

◆ setId()

Block::setId (   $blockId)
private

Set the block ID.

Parameters
int$blockId
Returns
int

Definition at line 1068 of file Block.php.

Referenced by insert().

◆ setReason()

Block::setReason (   $reason)

Set the reason for creating the block.

Since
1.33
Parameters
string$reason

Definition at line 1094 of file Block.php.

Referenced by __construct(), and initFromRow().

◆ setRestrictions()

Block::setRestrictions ( array  $restrictions)

Set Restrictions.

Since
1.33
Parameters
Restriction[]$restrictions
Returns
self

Definition at line 1957 of file Block.php.

Referenced by BlockListPagerTest\testPreprocessResults().

◆ setTarget()

Block::setTarget (   $target)

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

Parameters
mixed$target

Definition at line 1747 of file Block.php.

References list, and type.

Referenced by __construct(), and initFromRow().

◆ setTimestamp()

Block::setTimestamp (   $timestamp)

Set the timestamp indicating when the block was created.

Since
1.33
Parameters
string$timestamp

Definition at line 1739 of file Block.php.

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

◆ shouldTrackWithCookie()

Block::shouldTrackWithCookie (   $isIpUser)

Check if the block should be tracked with a cookie.

Since
1.33
Parameters
bool$isIpUserThe user is logged out
Returns
bool The block should be tracked with a cookie

Definition at line 2132 of file Block.php.

References RequestContext\getMain(), getType(), and isAutoblocking().

◆ update()

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)

Definition at line 620 of file Block.php.

References $mId, $success, DB_MASTER, doRetroactiveAutoblock(), getAutoblockUpdateArray(), getDatabaseArray(), getId(), isAutoblocking(), null, wfDebug(), and wfGetDB().

◆ updateTimestamp()

Block::updateTimestamp ( )

Update the timestamp on autoblocks.

Definition at line 979 of file Block.php.

References DB_MASTER, getId(), getTimestamp(), setExpiry(), setTimestamp(), wfGetDB(), and wfTimestamp().

Member Data Documentation

◆ $allowUsertalk

bool Block::$allowUsertalk
private

Definition at line 60 of file Block.php.

◆ $blockCreateAccount

bool Block::$blockCreateAccount
private

Definition at line 63 of file Block.php.

◆ $blocker

User Block::$blocker
private

Definition at line 78 of file Block.php.

Referenced by getBlocker(), and getBlockErrorParams().

◆ $forcedTargetID

int Block::$forcedTargetID
private

Hack for foreign blocking (CentralAuth)

Definition at line 69 of file Block.php.

Referenced by getDatabaseArray().

◆ $isAutoblocking

bool Block::$isAutoblocking
private

Definition at line 84 of file Block.php.

◆ $isHardblock

bool Block::$isHardblock
private

Definition at line 81 of file Block.php.

Referenced by isHardblock().

◆ $isSitewide

bool Block::$isSitewide
private

Definition at line 90 of file Block.php.

◆ $mAuto

bool Block::$mAuto

Definition at line 39 of file Block.php.

◆ $mBlockEmail

bool Block::$mBlockEmail
private

Definition at line 57 of file Block.php.

◆ $mExpiry

string Block::$mExpiry

Definition at line 42 of file Block.php.

Referenced by getExpiry().

◆ $mFromMaster

bool Block::$mFromMaster
private

Definition at line 54 of file Block.php.

◆ $mHideName

bool Block::$mHideName

Definition at line 45 of file Block.php.

Referenced by getHideName().

◆ $mId

int Block::$mId
private

Definition at line 51 of file Block.php.

Referenced by doAutoblock(), getId(), insert(), and update().

◆ $mParentBlockId

int Block::$mParentBlockId

Definition at line 48 of file Block.php.

Referenced by getDatabaseArray().

◆ $mReason

string Block::$mReason

Definition at line 33 of file Block.php.

Referenced by getReason().

◆ $mTimestamp

string Block::$mTimestamp

Definition at line 36 of file Block.php.

Referenced by getTimestamp().

◆ $restrictions

Restriction [] Block::$restrictions
private

Definition at line 93 of file Block.php.

Referenced by getRestrictions().

◆ $systemBlockType

string null Block::$systemBlockType
private

Definition at line 87 of file Block.php.

Referenced by getSystemBlockType().

◆ $target

User string Block::$target
private

Definition at line 66 of file Block.php.

Referenced by getTarget(), and parseTarget().

◆ $type

int Block::$type
private

Block::TYPE_ constant.

After the block has been loaded from the database, this can only be USER, IP or RANGE.

Definition at line 75 of file Block.php.

Referenced by findRestriction(), and getType().

◆ TYPE_AUTO

◆ TYPE_ID

const Block::TYPE_ID = 5

Definition at line 100 of file Block.php.

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

◆ TYPE_IP

◆ TYPE_RANGE

◆ TYPE_USER


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