MediaWiki  master
MediaWiki\Block\DatabaseBlock Class Reference

A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may be tracked with cookies. More...

Inheritance diagram for MediaWiki\Block\DatabaseBlock:
Collaboration diagram for MediaWiki\Block\DatabaseBlock:

Public Member Functions

 __construct (array $options=[])
 Create a new block with specified option parameters on a user, IP or IP range. More...
 
 appliesToNamespace ( $ns)
 Checks if a block applies to a particular namespace.
Since
1.33
Parameters
int$ns
Returns
bool
More...
 
 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
More...
 
 appliesToRight ( $right)
 Determine whether the block prevents a given right.A right may be allowed or disallowed by default, 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$right
Returns
bool|null The block applies to the right, or null if unsure (e.g. unrecognized right or unset property)
More...
 
 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
More...
 
 delete ()
 Delete the row from the IP blocks table. More...
 
 doAutoblock ( $autoblockIP)
 Autoblocks the given IP, referring to this block. More...
 
 equals (DatabaseBlock $block)
 Check if two blocks are effectively equal. More...
 
 getBlocker ()
 Get the user who implemented this block. More...
 
 getBy ()
 Get the user id of the blocking sysop.
Returns
int (0 for foreign users)
More...
 
 getByName ()
 Get the username of the blocking sysop.
Returns
string
More...
 
 getId ()
 Get the block ID.
Returns
int|null
More...
 
 getIdentifier ()
 Get the information that identifies this block, such that a user could look up everything that can be found about this block.Typically a scalar ID (integer or string), but can also return a list of IDs, or an associative array encoding a composite ID. Must be safe to serialize as JSON.
Returns
mixed Identifying information
More...
 
 getParentBlockId ()
 
 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...
 
 getRawRestrictions ()
 Get restrictions without loading from database if not yet loaded. More...
 
 getReason ()
 Get the reason given for creating the block, as a string.Deprecated, since this gives the caller no control over the language or format, and no access to the comment's data.
Deprecated:
since 1.35. Use getReasonComment instead.
Since
1.33
Returns
string
More...
 
 getRedactedName ()
 Get the block name, but with autoblocked IPs hidden as per standard privacy policy. More...
 
 getRestrictions ()
 Getting the restrictions will perform a database query if the restrictions are not already loaded. More...
 
 getType ()
 Get the type of target for this particular block.
Returns
int|null AbstractBlock::TYPE_ constant, will never be TYPE_ID
More...
 
 insert (IDatabase $dbw=null)
 Insert a block into the block table. More...
 
 isAutoblocking ( $x=null)
 
 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...
 
 setBlocker ( $user)
 Set the user who implemented (or will implement) this block. More...
 
 setId ( $blockId)
 Set the block ID. More...
 
 setRestrictions (array $restrictions)
 
 update ()
 Update a block in the DB with new parameters. More...
 
 updateTimestamp ()
 Update the timestamp on autoblocks. More...
 
- Public Member Functions inherited from MediaWiki\Block\AbstractBlock
 appliesToPasswordReset ()
 Check if the block prevents a user from resetting their password. More...
 
 appliesToUsertalk (Title $usertalk=null)
 Determine whether the block allows the user to edit their own user talk page. More...
 
 getExpiry ()
 Get the block expiry time. More...
 
 getHideName ()
 Get whether the block hides the target's username. More...
 
 getPermissionsError (IContextSource $context)
 Get the key and parameters for the corresponding error message. More...
 
 getReasonComment ()
 Get the reason for creating the block. More...
 
 getTarget ()
 Get the target for this particular block. More...
 
 getTargetAndType ()
 Get the target and target type for this particular block. More...
 
 getTargetName ()
 
 getTargetUserIdentity ()
 
 getTimestamp ()
 Get the timestamp indicating when the block was created. More...
 
 isBlocking ( $target)
 
 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...
 
 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...
 
 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...
 
 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...
 
- Public Member Functions inherited from MediaWiki\Block\Block
 isCreateAccountBlocked ()
 Get the flag indicating whether this block blocks the target from creating an account. More...
 
 isHardblock ()
 Returns whether the block is a hardblock (affects logged-in users on a given IP/range) More...
 
 isSitewide ()
 Indicates that the block is a sitewide block. More...
 

Static Public Member Functions

static getAutoblockExpiry ( $timestamp)
 Get a timestamp of the expiry for autoblocks. More...
 
static getBlocksForIPList (array $ipChain, $isAnon, $fromPrimary=false)
 Get all blocks that match any IP from an array of IP addresses. 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 isExemptedFromAutoblocks ( $ip)
 Checks whether a given IP is on the autoblock exemption list. More...
 
static isWhitelistedFromAutoblocks ( $ip)
 Checks whether a given IP is on the autoblock exemption list. More...
 
static newFromID ( $id)
 Load a block from the block id. More...
 
static newFromRow ( $row)
 Create a new DatabaseBlock object from a database row. More...
 
static newFromTarget ( $specificTarget, $vagueTarget=null, $fromPrimary=false)
 Given a target and the target's type, get an existing block object if possible. More...
 
static newListFromTarget ( $specificTarget, $vagueTarget=null, $fromPrimary=false)
 This is similar to DatabaseBlock::newFromTarget, but it returns all the relevant blocks. More...
 
static purgeExpired ()
 Purge expired blocks from the ipblocks table. More...
 

Public Attributes

bool $mAuto
 
int $mParentBlockId
 
- Public Attributes inherited from MediaWiki\Block\AbstractBlock
string $mExpiry = ''
 
bool $mHideName = false
 
string $mTimestamp = ''
 
- Public Attributes inherited from MediaWiki\Block\Block
const TYPE_AUTO = 4
 
const TYPE_ID = 5
 
const TYPE_IP = 2
 
const TYPE_RANGE = 3
 
const TYPE_USER = 1
 

Protected Member Functions

 initFromRow ( $row)
 Given a database row from the ipblocks table, initialize member variables. More...
 

Static Protected Member Functions

static chooseMostSpecificBlock (array $blocks)
 Choose the most specific block from some combination of user, IP and IP range blocks. 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...
 
static newLoad ( $specificTarget, $specificType, $fromPrimary, $vagueTarget=null)
 Load blocks from the database which target the specific target exactly, or which cover the vague target. More...
 

Private Member Functions

 findRestriction ( $type, $value)
 Find Restriction by type and value. More...
 
 getBlockRestrictionStore ()
 Get a BlockRestrictionStore instance. More...
 

Private Attributes

UserIdentity null $blocker
 
bool $isAutoblocking
 
bool $mFromPrimary
 
int $mId
 
Restriction[] $restrictions
 

Additional Inherited Members

- Protected Attributes inherited from MediaWiki\Block\AbstractBlock
bool $allowUsertalk = false
 
bool $blockCreateAccount = false
 
bool $isHardblock
 
bool $isSitewide = true
 
bool $mBlockEmail = false
 
CommentStoreComment $reason
 
UserIdentity string null $target
 
int null $type
 AbstractBlock::TYPE_ constant. More...
 

Detailed Description

A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may be tracked with cookies.

Such blocks are more customizable than system blocks: they may be hardblocks, and they may be sitewide or partial.

Since
1.34 Renamed from Block.

Definition at line 52 of file DatabaseBlock.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Block\DatabaseBlock::__construct ( array  $options = [])

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

Parameters
array$optionsParameters of the block, with options supported by AbstractBlock::__construct, and also:
  • user: (int) Override target user ID (for foreign users)
  • 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
  • blockEmail: (bool) Disallow sending emails
  • allowUsertalk: (bool) Allow the target to edit its own talk page
  • sitewide: (bool) Disallow editing all pages and all contribution actions, except those specifically allowed by other block flags
  • by: (int|UserIdentity) UserIdentity object or an ID of the blocker. Calling with ID is deprecated since 1.36, hard deprecated since 1.37.
  • byText: (string) Username of the blocker (for foreign users) Deprecated since 1.36, hard deprecated since 1.37. Use 'by' parameter instead.
Since
1.26 $options array

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 102 of file DatabaseBlock.php.

References DB_REPLICA, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Block\DatabaseBlock\isAutoblocking(), MediaWiki\Block\Block\isCreateAccountBlocked(), MediaWiki\Block\AbstractBlock\isEmailBlocked(), MediaWiki\Block\Block\isSitewide(), MediaWiki\Block\AbstractBlock\isUsertalkEditAllowed(), MediaWiki\Block\DatabaseBlock\setBlocker(), MediaWiki\Block\AbstractBlock\setExpiry(), wfDeprecatedMsg(), and wfGetDB().

Member Function Documentation

◆ appliesToNamespace()

MediaWiki\Block\DatabaseBlock::appliesToNamespace (   $ns)

Checks if a block applies to a particular namespace.

Since
1.33
Parameters
int$ns
Returns
bool

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1087 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\findRestriction(), MediaWiki\Block\Block\isSitewide(), and MediaWiki\Block\Restriction\NamespaceRestriction\TYPE.

◆ appliesToPage()

MediaWiki\Block\DatabaseBlock::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

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1105 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\findRestriction(), MediaWiki\Block\Block\isSitewide(), and MediaWiki\Block\Restriction\PageRestriction\TYPE.

◆ appliesToRight()

MediaWiki\Block\DatabaseBlock::appliesToRight (   $right)

Determine whether the block prevents a given right.A right may be allowed or disallowed by default, 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$right
Returns
bool|null The block applies to the right, or null if unsure (e.g. unrecognized right or unset property)

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1123 of file DatabaseBlock.php.

References MediaWiki\$config, $res, MediaWiki\Block\DatabaseBlock\findRestriction(), Config\get(), MediaWiki\MediaWikiServices\getInstance(), and MediaWiki\Block\Restriction\ActionRestriction\TYPE.

◆ appliesToTitle()

MediaWiki\Block\DatabaseBlock::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

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1069 of file DatabaseBlock.php.

References $title, MediaWiki\Block\DatabaseBlock\getRestrictions(), and MediaWiki\Block\Block\isSitewide().

◆ chooseMostSpecificBlock()

static MediaWiki\Block\DatabaseBlock::chooseMostSpecificBlock ( array  $blocks)
staticprotected

Choose the most specific block from some combination of user, IP and IP range blocks.

Decreasing order of specificity: user > IP > narrower IP range > wider IP range. A range that encompasses one IP address is ranked equally to a singe IP.

This is refactored out from DatabaseBlock::newLoad.

Parameters
DatabaseBlock[]$blocksThese should not include autoblocks or ID blocks
Returns
DatabaseBlock|null The block with the most specific target

Definition at line 372 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\$target.

Referenced by MediaWiki\Block\DatabaseBlock\newFromTarget().

◆ delete()

MediaWiki\Block\DatabaseBlock::delete ( )

Delete the row from the IP blocks table.

Deprecated:
since 1.36 Use DatabaseBlockStore::deleteBlock instead.
Exceptions
MWException
Returns
bool

Definition at line 510 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ doAutoblock()

◆ equals()

◆ findRestriction()

MediaWiki\Block\DatabaseBlock::findRestriction (   $type,
  $value 
)
private

◆ getAutoblockExpiry()

static MediaWiki\Block\DatabaseBlock::getAutoblockExpiry (   $timestamp)
static

Get a timestamp of the expiry for autoblocks.

Parameters
string | int$timestamp
Returns
string

Definition at line 860 of file DatabaseBlock.php.

References $wgAutoblockExpiry, and wfTimestamp().

◆ getBlocker()

MediaWiki\Block\DatabaseBlock::getBlocker ( )

◆ getBlockRestrictionStore()

MediaWiki\Block\DatabaseBlock::getBlockRestrictionStore ( )
private

◆ getBlocksForIPList()

static MediaWiki\Block\DatabaseBlock::getBlocksForIPList ( array  $ipChain,
  $isAnon,
  $fromPrimary = 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$fromPrimaryWhether to query the primary or replica DB
Returns
self[]
Since
1.22

Definition at line 944 of file DatabaseBlock.php.

References DB_PRIMARY, DB_REPLICA, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Block\DatabaseBlock\getQueryInfo(), MediaWiki\Block\DatabaseBlock\getRangeCond(), LIST_OR, MediaWiki\Block\DatabaseBlock\newFromRow(), and wfGetDB().

Referenced by MediaWiki\Block\BlockManager\getAdditionalIpBlocks().

◆ getBy()

MediaWiki\Block\DatabaseBlock::getBy ( )

Get the user id of the blocking sysop.

Returns
int (0 for foreign users)

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1183 of file DatabaseBlock.php.

◆ getByName()

MediaWiki\Block\DatabaseBlock::getByName ( )

Get the username of the blocking sysop.

Returns
string

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1190 of file DatabaseBlock.php.

◆ getId()

◆ getIdentifier()

MediaWiki\Block\DatabaseBlock::getIdentifier ( )

Get the information that identifies this block, such that a user could look up everything that can be found about this block.Typically a scalar ID (integer or string), but can also return a list of IDs, or an associative array encoding a composite ID. Must be safe to serialize as JSON.

Returns
mixed Identifying information

Implements MediaWiki\Block\Block.

Definition at line 1019 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\getId().

◆ getIpFragment()

static MediaWiki\Block\DatabaseBlock::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 447 of file DatabaseBlock.php.

References $wgBlockCIDRLimit.

Referenced by MediaWiki\Block\DatabaseBlock\getRangeCond().

◆ getParentBlockId()

MediaWiki\Block\DatabaseBlock::getParentBlockId ( )
Since
1.34
Returns
int|null If this is an autoblock, ID of the parent block; otherwise null

Definition at line 806 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\$mParentBlockId.

Referenced by MediaWiki\Block\DatabaseBlockStore\getArrayForDatabaseBlock().

◆ getQueryInfo()

static MediaWiki\Block\DatabaseBlock::getQueryInfo ( )
static

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

Since 1.34, ipb_by and ipb_by_text have not been present in the database, but they continue to be available in query results as aliases.

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 199 of file DatabaseBlock.php.

References CommentStore\getStore().

Referenced by MediaWiki\Block\DatabaseBlock\getBlocksForIPList(), MediaWiki\Block\DatabaseBlock\newFromID(), and MediaWiki\Block\DatabaseBlock\newLoad().

◆ getRangeCond()

static MediaWiki\Block\DatabaseBlock::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 414 of file DatabaseBlock.php.

References $dbr, DB_REPLICA, MediaWiki\Block\DatabaseBlock\getIpFragment(), LIST_AND, and wfGetDB().

Referenced by MediaWiki\Block\DatabaseBlock\getBlocksForIPList(), and MediaWiki\Block\DatabaseBlock\newLoad().

◆ getRangeEnd()

MediaWiki\Block\DatabaseBlock::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 751 of file DatabaseBlock.php.

References MediaWiki\Block\Block\TYPE_IP, MediaWiki\Block\Block\TYPE_RANGE, and MediaWiki\Block\Block\TYPE_USER.

Referenced by MediaWiki\Block\DatabaseBlockStore\getArrayForDatabaseBlock().

◆ getRangeStart()

MediaWiki\Block\DatabaseBlock::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 732 of file DatabaseBlock.php.

References MediaWiki\Block\Block\TYPE_IP, MediaWiki\Block\Block\TYPE_RANGE, and MediaWiki\Block\Block\TYPE_USER.

Referenced by MediaWiki\Block\DatabaseBlockStore\getArrayForDatabaseBlock().

◆ getRawRestrictions()

MediaWiki\Block\DatabaseBlock::getRawRestrictions ( )

Get restrictions without loading from database if not yet loaded.

Access: internal
Returns
?Restriction[]

Definition at line 1049 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\$restrictions.

Referenced by MediaWiki\Block\DatabaseBlockStore\insertBlock(), and MediaWiki\Block\DatabaseBlockStore\updateBlock().

◆ getReason()

MediaWiki\Block\DatabaseBlock::getReason ( )

Get the reason given for creating the block, as a string.Deprecated, since this gives the caller no control over the language or format, and no access to the comment's data.

Deprecated:
since 1.35. Use getReasonComment instead.
Since
1.33
Returns
string

Deprecated:
since 1.35. Use getReasonComment instead.

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 769 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\getType().

◆ getRedactedName()

MediaWiki\Block\DatabaseBlock::getRedactedName ( )

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

Returns
string Text is escaped

Definition at line 842 of file DatabaseBlock.php.

References Html\element(), MediaWiki\Block\AbstractBlock\getTargetName(), and wfMessage().

◆ getRestrictions()

MediaWiki\Block\DatabaseBlock::getRestrictions ( )

◆ getType()

MediaWiki\Block\DatabaseBlock::getType ( )

Get the type of target for this particular block.

Returns
int|null AbstractBlock::TYPE_ constant, will never be TYPE_ID

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.

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 1010 of file DatabaseBlock.php.

References MediaWiki\Block\Block\TYPE_AUTO.

Referenced by MediaWiki\Block\DatabaseBlockStore\doRetroactiveAutoblock(), MediaWiki\Block\DatabaseBlockStore\getArrayForDatabaseBlock(), MediaWiki\Block\DatabaseBlock\getReason(), MediaWiki\Block\DatabaseBlock\isAutoblocking(), MediaWiki\Block\DatabaseBlock\isHardblock(), SpecialBlock\maybeAlterFormDefaults(), MediaWiki\Block\DatabaseBlockStore\performRetroactiveAutoblock(), and MediaWiki\Block\BlockManager\shouldApplyCookieBlock().

◆ initFromRow()

◆ insert()

MediaWiki\Block\DatabaseBlock::insert ( IDatabase  $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.

Deprecated:
since 1.36 Use DatabaseBlockStore::insertBlock instead.
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 525 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ isAutoblocking()

◆ isExemptedFromAutoblocks()

static MediaWiki\Block\DatabaseBlock::isExemptedFromAutoblocks (   $ip)
static

Checks whether a given IP is on the autoblock exemption list.

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

Since
1.36
Parameters
string$ipThe IP to check
Returns
bool

Definition at line 568 of file DatabaseBlock.php.

References $cache, $line, $lines, DB_REPLICA, Wikimedia\Rdbms\Database\getCacheSetOptions(), MediaWiki\MediaWikiServices\getInstance(), wfDebug(), wfGetDB(), and wfMessage().

Referenced by MediaWiki\Block\DatabaseBlock\isWhitelistedFromAutoblocks().

◆ isExpired()

MediaWiki\Block\DatabaseBlock::isExpired ( )

Has the block expired?

Returns
bool

Definition at line 694 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\getExpiry(), wfDebug(), and wfTimestampNow().

Referenced by MediaWiki\Block\BlockManager\shouldApplyCookieBlock().

◆ isHardblock()

MediaWiki\Block\DatabaseBlock::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

Reimplemented from MediaWiki\Block\AbstractBlock.

Definition at line 815 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\$isHardblock, MediaWiki\Block\DatabaseBlock\getType(), MediaWiki\Block\Block\isHardblock(), true, and wfSetVar().

Referenced by MediaWiki\Block\DatabaseBlock\equals(), and MediaWiki\Block\DatabaseBlockStore\getArrayForDatabaseBlock().

◆ isWhitelistedFromAutoblocks()

static MediaWiki\Block\DatabaseBlock::isWhitelistedFromAutoblocks (   $ip)
static

Checks whether a given IP is on the autoblock exemption list.

Deprecated:
since 1.36; use DatabaseBlock::isExemptedFromAutoblocks()
Parameters
string$ipThe IP to check
Returns
bool

Definition at line 553 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\isExemptedFromAutoblocks(), and wfDeprecated().

◆ newFromID()

static MediaWiki\Block\DatabaseBlock::newFromID (   $id)
static

Load a block from the block id.

Parameters
int$idid to search for
Returns
DatabaseBlock|null

Definition at line 167 of file DatabaseBlock.php.

References $dbr, $res, DB_REPLICA, MediaWiki\Block\DatabaseBlock\getQueryInfo(), MediaWiki\Block\DatabaseBlock\newFromRow(), and wfGetDB().

Referenced by MediaWiki\Block\BlockManager\getBlockFromCookieValue(), and MediaWiki\Block\DatabaseBlock\newListFromTarget().

◆ newFromRow()

static MediaWiki\Block\DatabaseBlock::newFromRow (   $row)
static

Create a new DatabaseBlock object from a database row.

Parameters
stdClass$rowRow from the ipblocks table
Returns
DatabaseBlock

Definition at line 497 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\initFromRow().

Referenced by MediaWiki\Block\DatabaseBlock\getBlocksForIPList(), MediaWiki\Block\DatabaseBlock\newFromID(), and MediaWiki\Block\DatabaseBlock\newLoad().

◆ newFromTarget()

static MediaWiki\Block\DatabaseBlock::newFromTarget (   $specificTarget,
  $vagueTarget = null,
  $fromPrimary = false 
)
static

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

Parameters
string | UserIdentity | int | null$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 | UserIdentity | 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$fromPrimaryWhether to use the DB_PRIMARY database
Returns
DatabaseBlock|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 895 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\chooseMostSpecificBlock(), and MediaWiki\Block\DatabaseBlock\newListFromTarget().

Referenced by MediaWiki\Block\UnblockUser\__construct(), MediaWiki\Permissions\PermissionManager\checkUserBlock(), MediaWiki\Block\DatabaseBlock\doAutoblock(), MediaWiki\Block\BlockUser\placeBlock(), and MediaWiki\Block\BlockUser\placeBlockInternal().

◆ newListFromTarget()

static MediaWiki\Block\DatabaseBlock::newListFromTarget (   $specificTarget,
  $vagueTarget = null,
  $fromPrimary = false 
)
static

This is similar to DatabaseBlock::newFromTarget, but it returns all the relevant blocks.

Since
1.34
Parameters
string | UserIdentity | int | null$specificTarget
string | UserIdentity | int | null$vagueTarget
bool$fromPrimary
Returns
DatabaseBlock[] Any relevant blocks

Definition at line 909 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\$target, MediaWiki\Block\AbstractBlock\$type, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Block\DatabaseBlock\newFromID(), and MediaWiki\Block\DatabaseBlock\newLoad().

Referenced by MediaWiki\Block\BlockManager\getUserBlock(), and MediaWiki\Block\DatabaseBlock\newFromTarget().

◆ newLoad()

static MediaWiki\Block\DatabaseBlock::newLoad (   $specificTarget,
  $specificType,
  $fromPrimary,
  $vagueTarget = null 
)
staticprotected

Load blocks from the database which target the specific target exactly, or which cover the vague target.

Parameters
UserIdentity | string | null$specificTarget
int | null$specificType
bool$fromPrimary
UserIdentity | 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
DatabaseBlock[] Any relevant blocks

Definition at line 271 of file DatabaseBlock.php.

References $res, MediaWiki\Block\AbstractBlock\$target, MediaWiki\Block\AbstractBlock\$type, DB_PRIMARY, DB_REPLICA, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Block\DatabaseBlock\getQueryInfo(), MediaWiki\Block\DatabaseBlock\getRangeCond(), LIST_OR, MediaWiki\Block\DatabaseBlock\newFromRow(), MediaWiki\Block\Block\TYPE_IP, MediaWiki\Block\Block\TYPE_RANGE, MediaWiki\Block\Block\TYPE_USER, and wfGetDB().

Referenced by MediaWiki\Block\DatabaseBlock\newListFromTarget().

◆ purgeExpired()

static MediaWiki\Block\DatabaseBlock::purgeExpired ( )
static

Purge expired blocks from the ipblocks table.

Deprecated:
since 1.36 Use DatabaseBlockStore::purgeExpiredBlocks instead.

Definition at line 871 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ setBlocker()

MediaWiki\Block\DatabaseBlock::setBlocker (   $user)

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

Parameters
UserIdentity | string$userLocal user object or username string. Calling with string is deprecated since 1.36

Definition at line 1209 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\getId(), MediaWiki\Logger\LoggerFactory\getInstance(), MediaWiki\MediaWikiServices\getInstance(), and wfDeprecatedMsg().

Referenced by MediaWiki\Block\DatabaseBlock\__construct(), and MediaWiki\Block\DatabaseBlock\initFromRow().

◆ setId()

MediaWiki\Block\DatabaseBlock::setId (   $blockId)

Set the block ID.

Access: internal
Only for use in DatabaseBlockStore; private until 1.36
Parameters
int$blockId
Returns
self

Definition at line 790 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore().

Referenced by MediaWiki\Block\DatabaseBlockStore\insertBlock().

◆ setRestrictions()

MediaWiki\Block\DatabaseBlock::setRestrictions ( array  $restrictions)
Since
1.33
Parameters
Restriction[]$restrictions
Returns
self

Definition at line 1058 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\$restrictions.

◆ update()

MediaWiki\Block\DatabaseBlock::update ( )

Update a block in the DB with new parameters.

The ID field needs to be loaded first.

Deprecated:
since 1.36 Use DatabaseBlockStore::updateBlock instead.
Returns
bool|array False on failure, array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)

Definition at line 539 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ updateTimestamp()

MediaWiki\Block\DatabaseBlock::updateTimestamp ( )

Member Data Documentation

◆ $blocker

UserIdentity null MediaWiki\Block\DatabaseBlock::$blocker
private

Definition at line 78 of file DatabaseBlock.php.

Referenced by MediaWiki\Block\DatabaseBlock\getBlocker().

◆ $isAutoblocking

bool MediaWiki\Block\DatabaseBlock::$isAutoblocking
private

Definition at line 72 of file DatabaseBlock.php.

◆ $mAuto

bool MediaWiki\Block\DatabaseBlock::$mAuto
Deprecated:
since 1.34. Use getType to check whether a block is autoblocking.

Definition at line 57 of file DatabaseBlock.php.

◆ $mFromPrimary

bool MediaWiki\Block\DatabaseBlock::$mFromPrimary
private

Definition at line 69 of file DatabaseBlock.php.

◆ $mId

int MediaWiki\Block\DatabaseBlock::$mId
private

◆ $mParentBlockId

int MediaWiki\Block\DatabaseBlock::$mParentBlockId
Deprecated:
since 1.34. Use getParentBlockId instead.

Definition at line 63 of file DatabaseBlock.php.

Referenced by MediaWiki\Block\DatabaseBlock\getParentBlockId().

◆ $restrictions


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