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)
 
 appliesToPage ( $pageId)
 
 appliesToTitle (Title $title)
 
 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 (DatabaseBlock $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...
 
 getCookieValue ()
 Get the BlockID cookie's value for this block. More...
 
 getId ()
 
 getIdentifier ()
 
 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...
 
 getRedactedName ()
 Get the block name, but with autoblocked IPs hidden as per standard privacy policy. More...
 
 getRestrictions ()
 Get Restrictions. More...
 
 getType ()
 
 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...
 
 isValid ()
 Is the block address valid (i.e. More...
 
 setCookie (WebResponse $response)
 Set the 'BlockID' cookie to this block's ID and expiry time. More...
 
 setRestrictions (array $restrictions)
 Set Restrictions. More...
 
 shouldTrackWithCookie ( $isAnon)
 
 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
 __construct (array $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...
 
 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...
 
 getExpiry ()
 Get the block expiry time. More...
 
 getHideName ()
 Get whether the block hides the target's username. More...
 
 getId ()
 Get the block ID. More...
 
 getIdentifier ()
 Get the information that identifies this block, such that a user could look up everything that can be found about this block. More...
 
 getPermissionsError (IContextSource $context)
 Get the key and parameters for the corresponding error message. More...
 
 getReason ()
 Get the reason given 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...
 
 getTimestamp ()
 Get the timestamp indicating when the block was created. More...
 
 getType ()
 Get the type of target for this particular block. More...
 
 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...
 
 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...
 
 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...
 
 shouldTrackWithCookie ( $isAnon)
 Check if the block should be tracked with a cookie. 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 DatabaseBlock 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 newListFromTarget ( $specificTarget, $vagueTarget=null, $fromMaster=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...
 
- Static Public Member Functions inherited from MediaWiki\Block\AbstractBlock
static parseTarget ( $target)
 From an existing block, get the target and the type of target. More...
 

Public Attributes

bool $mAuto
 
int $mParentBlockId
 
- Public Attributes inherited from MediaWiki\Block\AbstractBlock
string $mExpiry = ''
 
bool $mHideName = false
 
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...
 

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 defaultRetroactiveAutoblock (DatabaseBlock $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...
 
static newLoad ( $specificTarget, $specificType, $fromMaster, $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...
 
 setId ( $blockId)
 Set the block ID. More...
 

Private Attributes

int $forcedTargetID
 Hack for foreign blocking (CentralAuth) More...
 
bool $isAutoblocking
 
bool $isHardblock
 
bool $mFromMaster
 
int $mId
 
Restriction [] $restrictions
 

Additional Inherited Members

- Protected Attributes inherited from MediaWiki\Block\AbstractBlock
bool $allowUsertalk = false
 
bool $blockCreateAccount = false
 
User $blocker
 
bool $isSitewide = true
 
bool $mBlockEmail = false
 
User 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 53 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
Since
1.26 $options array

Definition at line 102 of file DatabaseBlock.php.

References DB_REPLICA, MediaWiki\Block\DatabaseBlock\isAutoblocking(), MediaWiki\Block\AbstractBlock\isCreateAccountBlocked(), MediaWiki\Block\AbstractBlock\isEmailBlocked(), MediaWiki\Block\DatabaseBlock\isHardblock(), MediaWiki\Block\AbstractBlock\isSitewide(), MediaWiki\Block\AbstractBlock\isUsertalkEditAllowed(), MediaWiki\Block\AbstractBlock\setExpiry(), and wfGetDB().

Member Function Documentation

◆ appliesToNamespace()

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

◆ appliesToPage()

MediaWiki\Block\DatabaseBlock::appliesToPage (   $pageId)

◆ appliesToTitle()

MediaWiki\Block\DatabaseBlock::appliesToTitle ( Title  $title)

◆ chooseBlock()

static MediaWiki\Block\DatabaseBlock::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 were retrieved from the user's IP address and $ipChain is populated from the same IP address information.
Parameters
array$blocksArray of DatabaseBlock 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-cdn, ...)
Exceptions
MWException
Returns
DatabaseBlock|null The "best" block from the list

Definition at line 1257 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\appliesToRight(), MediaWiki\Block\DatabaseBlock\isHardblock(), and IP\toHex().

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

Note that DatabaseBlock::chooseBlocks chooses blocks in a different way.

This is refactored out from DatabaseBlock::newLoad.

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

Definition at line 332 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\$target, IP\isIPv6(), and IP\parseCIDR().

◆ clearCookie()

static MediaWiki\Block\DatabaseBlock::clearCookie ( WebResponse  $response)
static

Unset the 'BlockID' cookie.

Since
1.29
Deprecated:
since 1.34 Use BlockManager::clearBlockCookie instead
Parameters
WebResponse$responseThe response on which to unset the cookie.

Definition at line 1380 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ defaultRetroactiveAutoblock()

static MediaWiki\Block\DatabaseBlock::defaultRetroactiveAutoblock ( DatabaseBlock  $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
DatabaseBlock$block
array&$blockIds

Definition at line 709 of file DatabaseBlock.php.

References $dbr, $res, MediaWiki\Block\AbstractBlock\$target, $wgPutIPinRC, DB_REPLICA, MediaWiki\Block\DatabaseBlock\doAutoblock(), MediaWiki\Block\AbstractBlock\getTarget(), MediaWiki\Block\DatabaseBlock\getType(), ActorMigration\newMigration(), wfDebug(), and wfGetDB().

◆ delete()

MediaWiki\Block\DatabaseBlock::delete ( )

Delete the row from the IP blocks table.

Exceptions
MWException
Returns
bool

Definition at line 468 of file DatabaseBlock.php.

References DB_MASTER, MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore(), MediaWiki\Block\DatabaseBlock\getId(), wfGetDB(), and wfReadOnly().

◆ deleteIfExpired()

MediaWiki\Block\DatabaseBlock::deleteIfExpired ( )

Check if a block has expired.

Delete it if it is.

Returns
bool

Definition at line 884 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\isExpired(), and wfDebug().

◆ doAutoblock()

◆ doRetroactiveAutoblock()

MediaWiki\Block\DatabaseBlock::doRetroactiveAutoblock ( )
protected

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

Returns
array IDs of retroactive autoblocks made

Definition at line 686 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\getTarget(), MediaWiki\Block\DatabaseBlock\getType(), MediaWiki\Block\DatabaseBlock\isAutoblocking(), Hooks\run(), and wfDebug().

Referenced by MediaWiki\Block\DatabaseBlock\insert(), and MediaWiki\Block\DatabaseBlock\update().

◆ equals()

◆ findRestriction()

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

Find Restriction by type and value.

Parameters
string$type
int$value
Returns
Restriction|null

Definition at line 1516 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\$type, and MediaWiki\Block\DatabaseBlock\getRestrictions().

Referenced by MediaWiki\Block\DatabaseBlock\appliesToNamespace(), and MediaWiki\Block\DatabaseBlock\appliesToPage().

◆ fromMaster()

MediaWiki\Block\DatabaseBlock::fromMaster (   $x = null)

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

Parameters
bool | null$x
Returns
bool

Definition at line 1022 of file DatabaseBlock.php.

References wfSetVar().

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

References $wgAutoblockExpiry, and wfTimestamp().

◆ getAutoblockUpdateArray()

◆ getBlockRestrictionStore()

◆ getBlocksForIPList()

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

References DB_MASTER, DB_REPLICA, MediaWiki\MediaWikiServices\getInstance(), IP\isValid(), LIST_OR, IP\toHex(), and wfGetDB().

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

◆ getCookieValue()

MediaWiki\Block\DatabaseBlock::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
Deprecated:
since 1.34 Use BlockManager::trackBlockWithCookie instead of calling this directly
Returns
string The block ID, probably concatenated with "!" and the HMAC.

Definition at line 1394 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ getDatabaseArray()

◆ getId()

◆ getIdentifier()

MediaWiki\Block\DatabaseBlock::getIdentifier ( )

Definition at line 1414 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\getId().

◆ getIdFromCookieValue()

static MediaWiki\Block\DatabaseBlock::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 DatabaseBlock::setCookie), but will sometimes only be the ID.

Since
1.29
Deprecated:
since 1.34 Use BlockManager::getUserBlock instead
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 1407 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

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

References $wgBlockCIDRLimit.

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

References MediaWiki\Block\DatabaseBlock\$mParentBlockId.

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

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

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

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

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

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

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

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

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

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

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

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

◆ getRestrictions()

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

References MediaWiki\Block\DatabaseBlock\$restrictions, and MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore().

Referenced by MediaWiki\Block\DatabaseBlock\appliesToTitle(), MediaWiki\Block\DatabaseBlock\doAutoblock(), MediaWiki\Block\DatabaseBlock\equals(), and MediaWiki\Block\DatabaseBlock\findRestriction().

◆ getType()

MediaWiki\Block\DatabaseBlock::getType ( )

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

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

References MediaWiki\Block\DatabaseBlock\$mId, $wgBlockDisablesLogin, DB_MASTER, MediaWiki\Block\DatabaseBlock\doRetroactiveAutoblock(), MediaWiki\Block\AbstractBlock\getBlocker(), MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore(), MediaWiki\Block\DatabaseBlock\getDatabaseArray(), MediaWiki\Block\DatabaseBlock\setId(), wfDebug(), and wfGetDB().

◆ isAutoblocking()

◆ isExpired()

MediaWiki\Block\DatabaseBlock::isExpired ( )

◆ isHardblock()

MediaWiki\Block\DatabaseBlock::isHardblock (   $x = null)

◆ isValid()

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

References MediaWiki\Block\AbstractBlock\getTarget(), and wfDeprecated().

◆ isWhitelistedFromAutoblocks()

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

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

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

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

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

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

References MediaWiki\Block\DatabaseBlock\initFromRow().

◆ newFromTarget()

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

◆ newListFromTarget()

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

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

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

Definition at line 1143 of file DatabaseBlock.php.

References MediaWiki\Block\AbstractBlock\$target, and MediaWiki\Block\AbstractBlock\$type.

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

◆ newLoad()

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

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

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

Definition at line 236 of file DatabaseBlock.php.

References $res, MediaWiki\Block\AbstractBlock\$target, MediaWiki\Block\AbstractBlock\$type, DB_MASTER, DB_REPLICA, LIST_OR, IP\parseRange(), IP\toHex(), and wfGetDB().

◆ purgeExpired()

◆ setCookie()

MediaWiki\Block\DatabaseBlock::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
Deprecated:
since 1.34 Set a cookie via BlockManager::trackBlockWithCookie instead.
Parameters
WebResponse$responseThe response on which to set the cookie.

Definition at line 1369 of file DatabaseBlock.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ setId()

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

Set the block ID.

Parameters
int$blockId
Returns
self

Definition at line 996 of file DatabaseBlock.php.

References MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore().

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

◆ setRestrictions()

MediaWiki\Block\DatabaseBlock::setRestrictions ( array  $restrictions)

Set Restrictions.

Since
1.33
Parameters
Restriction[]$restrictions
Returns
self

Definition at line 1447 of file DatabaseBlock.php.

◆ shouldTrackWithCookie()

MediaWiki\Block\DatabaseBlock::shouldTrackWithCookie (   $isAnon)

◆ update()

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

References MediaWiki\Block\DatabaseBlock\$mId, $success, DB_MASTER, MediaWiki\Block\DatabaseBlock\doRetroactiveAutoblock(), MediaWiki\Block\DatabaseBlock\getAutoblockUpdateArray(), MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore(), MediaWiki\Block\DatabaseBlock\getDatabaseArray(), MediaWiki\Block\DatabaseBlock\getId(), MediaWiki\Block\DatabaseBlock\isAutoblocking(), wfDebug(), and wfGetDB().

◆ updateTimestamp()

MediaWiki\Block\DatabaseBlock::updateTimestamp ( )

Member Data Documentation

◆ $forcedTargetID

int MediaWiki\Block\DatabaseBlock::$forcedTargetID
private

Hack for foreign blocking (CentralAuth)

Definition at line 73 of file DatabaseBlock.php.

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

◆ $isAutoblocking

bool MediaWiki\Block\DatabaseBlock::$isAutoblocking
private

Definition at line 79 of file DatabaseBlock.php.

◆ $isHardblock

bool MediaWiki\Block\DatabaseBlock::$isHardblock
private

Definition at line 76 of file DatabaseBlock.php.

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

◆ $mAuto

bool MediaWiki\Block\DatabaseBlock::$mAuto
Deprecated:
since 1.34.

Use getType to check whether a block is autoblocking.

Definition at line 58 of file DatabaseBlock.php.

◆ $mFromMaster

bool MediaWiki\Block\DatabaseBlock::$mFromMaster
private

Definition at line 70 of file DatabaseBlock.php.

◆ $mId

◆ $mParentBlockId

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

Use getParentBlockId instead.

Definition at line 64 of file DatabaseBlock.php.

Referenced by MediaWiki\Block\DatabaseBlock\getDatabaseArray(), and MediaWiki\Block\DatabaseBlock\getParentBlockId().

◆ $restrictions

Restriction [] MediaWiki\Block\DatabaseBlock::$restrictions
private

Definition at line 82 of file DatabaseBlock.php.

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


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