MediaWiki master
MediaWiki\Block\DatabaseBlockStore Class Reference

Public Member Functions

 __construct (ServiceOptions $options, LoggerInterface $logger, ActorStoreFactory $actorStoreFactory, BlockRestrictionStore $blockRestrictionStore, CommentStore $commentStore, HookContainer $hookContainer, IConnectionProvider $dbProvider, ReadOnlyMode $readOnlyMode, UserFactory $userFactory, TempUserConfig $tempUserConfig, BlockUtils $blockUtils, AutoblockExemptionList $autoblockExemptionList, $wikiId=DatabaseBlock::LOCAL)
 
 getReadStage ()
 Get the read stage of the block_target migration.
 
 getWriteStage ()
 Get the write stage of the block_target migration.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 
const SCHEMA_BLOCK = 'block'
 The new schema.
 
const SCHEMA_CURRENT = 'current'
 The schema currently selected by the read stage.
 
const SCHEMA_IPBLOCKS = 'ipblocks'
 The old schema.
 

Database read methods

 newFromID ( $id)
 Load a block from the block ID.
 
 getQueryInfo ( $schema=self::SCHEMA_BLOCK)
 Return the tables, fields, and join conditions to be selected to create a new block object.
 
 getRangeCond ( $start, $end, $schema=self::SCHEMA_BLOCK)
 Get a set of SQL conditions which select range blocks encompassing a given range.
 
 newFromRow (IReadableDatabase $db, $row)
 Create a new DatabaseBlock object from a database row.
 
 newFromTarget ( $specificTarget, $vagueTarget=null, $fromPrimary=false)
 Given a target and the target's type, get an existing block object if possible.
 
 newListFromTarget ( $specificTarget, $vagueTarget=null, $fromPrimary=false)
 This is similar to DatabaseBlockStore::newFromTarget, but it returns all the relevant blocks.
 
 newListFromIPs (array $addresses, $applySoftBlocks, $fromPrimary=false)
 Get all blocks that match any IP from an array of IP addresses.
 
 newListFromConds ( $conds, $fromPrimary=false, $includeExpired=false)
 Construct an array of blocks from database conditions.
 

Database write methods

 purgeExpiredBlocks ()
 Delete expired blocks from the ipblocks table.
 
 deleteBlocksMatchingConds (array $conds, $limit=null)
 Delete all blocks matching the given conditions.
 
 insertBlock (DatabaseBlock $block, $expectedTargetCount=0)
 Insert a block into the block table.
 
 updateBlock (DatabaseBlock $block)
 Update a block in the DB with new parameters.
 
 updateTarget (DatabaseBlock $block, $newTarget)
 Update the target in the specified object and in the database.
 
 deleteBlock (DatabaseBlock $block)
 Delete a DatabaseBlock from the database.
 
 doAutoblock (DatabaseBlock $parentBlock, $autoblockIP)
 Autoblocks the given IP, referring to the specified block.
 
 updateTimestamp (DatabaseBlock $block)
 Update the timestamp on autoblocks.
 
 getAutoblockExpiry ( $timestamp, string $parentExpiry=null)
 Get the expiry timestamp for an autoblock created at the given time.
 

Detailed Description

Since
1.36
Author
DannyS712

Definition at line 59 of file DatabaseBlockStore.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Block\DatabaseBlockStore::__construct ( ServiceOptions $options,
LoggerInterface $logger,
ActorStoreFactory $actorStoreFactory,
BlockRestrictionStore $blockRestrictionStore,
CommentStore $commentStore,
HookContainer $hookContainer,
IConnectionProvider $dbProvider,
ReadOnlyMode $readOnlyMode,
UserFactory $userFactory,
TempUserConfig $tempUserConfig,
BlockUtils $blockUtils,
AutoblockExemptionList $autoblockExemptionList,
$wikiId = DatabaseBlock::LOCAL )
Parameters
ServiceOptions$options
LoggerInterface$logger
ActorStoreFactory$actorStoreFactory
BlockRestrictionStore$blockRestrictionStore
CommentStore$commentStore
HookContainer$hookContainer
IConnectionProvider$dbProvider
ReadOnlyMode$readOnlyMode
UserFactory$userFactory
TempUserConfig$tempUserConfig
BlockUtils$blockUtils
AutoblockExemptionList$autoblockExemptionList
string | false$wikiId

Definition at line 132 of file DatabaseBlockStore.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ deleteBlock()

MediaWiki\Block\DatabaseBlockStore::deleteBlock ( DatabaseBlock $block)

Delete a DatabaseBlock from the database.

Parameters
DatabaseBlock$block
Returns
bool whether it was deleted

Definition at line 1344 of file DatabaseBlockStore.php.

◆ deleteBlocksMatchingConds()

MediaWiki\Block\DatabaseBlockStore::deleteBlocksMatchingConds ( array $conds,
$limit = null )

Delete all blocks matching the given conditions.

Since
1.42
Parameters
array$condsAn associative array mapping the field name to the matched value. Some limited schema abstractions are implemented, to allow new field names to be used with the old schema.
int | null$limitThe maximum number of blocks to delete
Returns
int The number of blocks deleted

Definition at line 827 of file DatabaseBlockStore.php.

◆ doAutoblock()

MediaWiki\Block\DatabaseBlockStore::doAutoblock ( DatabaseBlock $parentBlock,
$autoblockIP )

◆ getAutoblockExpiry()

MediaWiki\Block\DatabaseBlockStore::getAutoblockExpiry ( $timestamp,
string $parentExpiry = null )

Get the expiry timestamp for an autoblock created at the given time.

If the parent block expiry is specified, the return value will be earlier than or equal to the parent block expiry.

Access: internal
Public to support deprecated DatabaseBlock method
Parameters
string | int$timestamp
string | null$parentExpiry
Returns
string

Definition at line 1682 of file DatabaseBlockStore.php.

References wfTimestamp().

◆ getQueryInfo()

MediaWiki\Block\DatabaseBlockStore::getQueryInfo ( $schema = self::SCHEMA_BLOCK)

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.42
Access: internal
Avoid this method and DatabaseBlock::getQueryInfo() in new external code, since they are not schema-independent. Use newListFromConds() and deleteBlocksMatchingConds().
Parameters
string$schemaWhat schema to use for field aliases. May be either self::SCHEMA_IPBLOCKS or self::SCHEMA_BLOCK. This parameter will soon be removed.
Returns
array[] With three keys:
  • tables: (string[]) to include in the $table to IDatabase->select() or SelectQueryBuilder::tables
  • fields: (string[]) to include in the $vars to IDatabase->select() or SelectQueryBuilder::fields
  • joins: (array) to include in the $join_conds to IDatabase->select() or SelectQueryBuilder::joinConds

Definition at line 240 of file DatabaseBlockStore.php.

Referenced by MediaWiki\Block\DatabaseBlockStore\newFromID(), MediaWiki\Block\DatabaseBlockStore\newListFromConds(), and MediaWiki\Block\DatabaseBlockStore\newListFromIPs().

◆ getRangeCond()

MediaWiki\Block\DatabaseBlockStore::getRangeCond ( $start,
$end,
$schema = self::SCHEMA_BLOCK )

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

If the given range is a single IP with start=end, it will also select single IP blocks with that IP.

Since
1.42
Parameters
string$startHexadecimal IP representation
string | null$endHexadecimal IP representation, or null to use $start = $end
string$schemaWhat schema to use for field aliases. Can be one of:
  • self::SCHEMA_IPBLOCKS for the old schema
  • self::SCHEMA_BLOCK for the new schema
  • self::SCHEMA_CURRENT formerly used the configured schema, but now acts the same as SCHEMA_BLOCK In future this parameter will be removed.
Returns
string

Definition at line 511 of file DatabaseBlockStore.php.

References LIST_AND, and MediaWiki\Block\DatabaseBlockStore\SCHEMA_BLOCK.

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

◆ getReadStage()

MediaWiki\Block\DatabaseBlockStore::getReadStage ( )

Get the read stage of the block_target migration.

Since
1.42
Deprecated
since 1.43
Returns
int

Definition at line 172 of file DatabaseBlockStore.php.

References SCHEMA_COMPAT_NEW, and wfDeprecated().

◆ getWriteStage()

MediaWiki\Block\DatabaseBlockStore::getWriteStage ( )

Get the write stage of the block_target migration.

Since
1.42
Deprecated
since 1.43
Returns
int

Definition at line 184 of file DatabaseBlockStore.php.

References SCHEMA_COMPAT_NEW, and wfDeprecated().

◆ insertBlock()

MediaWiki\Block\DatabaseBlockStore::insertBlock ( DatabaseBlock $block,
$expectedTargetCount = 0 )

Insert a block into the block table.

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

Parameters
DatabaseBlock$block
int | null$expectedTargetCountThe expected number of existing blocks on the specified target. If this is zero but there is an existing block, the insertion will fail.
Returns
bool|array False on failure, assoc array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)

Definition at line 974 of file DatabaseBlockStore.php.

References $success, MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Block\DatabaseBlock\getBlocker(), MediaWiki\Block\DatabaseBlock\getId(), MediaWiki\Block\AbstractBlock\getTargetUserIdentity(), and MediaWiki\Block\AbstractBlock\getTimestamp().

◆ newFromID()

MediaWiki\Block\DatabaseBlockStore::newFromID ( $id)

Load a block from the block ID.

Since
1.42
Parameters
int$idID to search for
Returns
DatabaseBlock|null

Definition at line 200 of file DatabaseBlockStore.php.

References MediaWiki\Block\DatabaseBlockStore\getQueryInfo(), and MediaWiki\Block\DatabaseBlockStore\newFromRow().

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

◆ newFromRow()

MediaWiki\Block\DatabaseBlockStore::newFromRow ( IReadableDatabase $db,
$row )

Create a new DatabaseBlock object from a database row.

Since
1.42
Parameters
IReadableDatabase$dbThe database you got the row from
stdClass$rowRow from the ipblocks table
Returns
DatabaseBlock

Definition at line 581 of file DatabaseBlockStore.php.

References Wikimedia\Rdbms\Platform\ISQLPlatform\decodeExpiry().

Referenced by MediaWiki\Block\DatabaseBlockStore\newFromID(), MediaWiki\Block\DatabaseBlockStore\newListFromConds(), and MediaWiki\Block\DatabaseBlockStore\newListFromIPs().

◆ newFromTarget()

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

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

Since
1.42
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 660 of file DatabaseBlockStore.php.

References MediaWiki\Block\DatabaseBlockStore\newListFromTarget().

◆ newListFromConds()

MediaWiki\Block\DatabaseBlockStore::newListFromConds ( $conds,
$fromPrimary = false,
$includeExpired = false )

Construct an array of blocks from database conditions.

Since
1.42
Parameters
array$condsFor schema-independence this should be an associative array mapping field names to values. Field names from the new schema should be used.
bool$fromPrimary
bool$includeExpired
Returns
DatabaseBlock[]

Definition at line 764 of file DatabaseBlockStore.php.

References MediaWiki\Block\DatabaseBlockStore\getQueryInfo(), and MediaWiki\Block\DatabaseBlockStore\newFromRow().

◆ newListFromIPs()

MediaWiki\Block\DatabaseBlockStore::newListFromIPs ( array $addresses,
$applySoftBlocks,
$fromPrimary = false )

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

Since
1.42
Parameters
string[]$addressesValidated list of IP addresses
bool$applySoftBlocksInclude soft blocks (anonymous-only blocks). These should only block anonymous and temporary users.
bool$fromPrimaryWhether to query the primary or replica DB
Returns
DatabaseBlock[]

Definition at line 711 of file DatabaseBlockStore.php.

References MediaWiki\Block\DatabaseBlockStore\getQueryInfo(), MediaWiki\Block\DatabaseBlockStore\getRangeCond(), LIST_OR, and MediaWiki\Block\DatabaseBlockStore\newFromRow().

◆ newListFromTarget()

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

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

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

Definition at line 678 of file DatabaseBlockStore.php.

References MediaWiki\Block\DatabaseBlockStore\newFromID(), MediaWiki\Block\Block\TYPE_AUTO, MediaWiki\Block\Block\TYPE_ID, MediaWiki\Block\Block\TYPE_IP, MediaWiki\Block\Block\TYPE_RANGE, and MediaWiki\Block\Block\TYPE_USER.

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

◆ purgeExpiredBlocks()

MediaWiki\Block\DatabaseBlockStore::purgeExpiredBlocks ( )

Delete expired blocks from the ipblocks table.

Access: internal
only public for use in DatabaseBlock

Definition at line 793 of file DatabaseBlockStore.php.

References Wikimedia\Rdbms\IReadableDatabase\expr(), Wikimedia\Rdbms\IReadableDatabase\newSelectQueryBuilder(), Wikimedia\Rdbms\Platform\ISQLPlatform\timestamp(), and MediaWiki\MainConfigNames\UpdateRowsPerQuery.

◆ updateBlock()

MediaWiki\Block\DatabaseBlockStore::updateBlock ( DatabaseBlock $block)

Update a block in the DB with new parameters.

The ID field needs to be loaded first. The target must stay the same.

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

Definition at line 1223 of file DatabaseBlockStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Block\DatabaseBlock\getId(), MediaWiki\Block\DatabaseBlock\getRawRestrictions(), MediaWiki\Block\AbstractBlock\getTimestamp(), and MediaWiki\Block\DatabaseBlock\isAutoblocking().

◆ updateTarget()

MediaWiki\Block\DatabaseBlockStore::updateTarget ( DatabaseBlock $block,
$newTarget )

Update the target in the specified object and in the database.

The block ID must be set.

This is an unusual operation, currently used only by the UserMerge extension.

Since
1.42
Parameters
DatabaseBlock$block
UserIdentity | string$newTarget
Returns
bool True if the update was successful, false if there was no match for the block ID.

Definition at line 1301 of file DatabaseBlockStore.php.

References MediaWiki\Block\DatabaseBlock\getId(), and MediaWiki\Block\AbstractBlock\setTarget().

◆ updateTimestamp()

MediaWiki\Block\DatabaseBlockStore::updateTimestamp ( DatabaseBlock $block)

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Block\DatabaseBlockStore::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const UpdateRowsPerQuery
Name constant for the UpdateRowsPerQuery setting, for use with Config::get()
const BlockDisablesLogin
Name constant for the BlockDisablesLogin setting, for use with Config::get()
const AutoblockExpiry
Name constant for the AutoblockExpiry setting, for use with Config::get()
const BlockCIDRLimit
Name constant for the BlockCIDRLimit setting, for use with Config::get()
const PutIPinRC
Name constant for the PutIPinRC setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 70 of file DatabaseBlockStore.php.

◆ SCHEMA_BLOCK

const MediaWiki\Block\DatabaseBlockStore::SCHEMA_BLOCK = 'block'

The new schema.

Definition at line 63 of file DatabaseBlockStore.php.

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

◆ SCHEMA_CURRENT

const MediaWiki\Block\DatabaseBlockStore::SCHEMA_CURRENT = 'current'

The schema currently selected by the read stage.

Definition at line 65 of file DatabaseBlockStore.php.

◆ SCHEMA_IPBLOCKS

const MediaWiki\Block\DatabaseBlockStore::SCHEMA_IPBLOCKS = 'ipblocks'

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