MediaWiki REL1_41
MediaWiki\Block\AbstractBlock Class Reference

Inherits MediaWiki\Block\Block.

Inherited by MediaWiki\Block\CompositeBlock, MediaWiki\Block\DatabaseBlock, and MediaWiki\Block\SystemBlock.

Collaboration diagram for MediaWiki\Block\AbstractBlock:

Public Member Functions

 __construct (array $options=[])
 Create a new block with specified parameters on a user, IP or IP range.
 
 appliesToNamespace ( $ns)
 Checks if a block applies to a particular namespace.
 
 appliesToPage ( $pageId)
 Checks if a block applies to a particular page.
 
 appliesToPasswordReset ()
 Check if the block prevents a user from resetting their password.
 
 appliesToRight ( $right)
 Determine whether the block prevents a given right.
 
 appliesToTitle (Title $title)
 Checks if a block applies to a particular title.
 
 appliesToUsertalk (Title $usertalk=null)
 Determine whether the block allows the user to edit their own user talk page.
 
 getBy ( $wikiId=self::LOCAL)
 Get the user id of the blocking sysop.
 
 getByName ()
 Get the username of the blocking sysop.
 
 getExpiry ()
 Get the block expiry time.
 
 getHideName ()
 Get whether the block hides the target's username.
 
 getId ( $wikiId=self::LOCAL)
 Get the block ID.
Parameters
string | false$wikiId(since 1.38)
Returns
?int

 
 getPermissionsError (IContextSource $context)
 Get the key and parameters for the corresponding error message.
 
 getReason ()
 Get the reason given for creating the block, as a string.
 
 getReasonComment ()
 Get the reason for creating the block.
 
 getTargetName ()
 
 getTargetUserIdentity ()
 
 getTimestamp ()
 Get the timestamp indicating when the block was created.
 
 getType ()
 Get the type of target for this particular block.
 
 getWikiId ()
 
 isBlocking ( $target)
 
 isCreateAccountBlocked ( $x=null)
 Get or set the flag indicating whether this block blocks the target from creating an account.
 
 isEmailBlocked ( $x=null)
 Get or set the flag indicating whether this block blocks the target from sending emails.
 
 isHardblock ( $x=null)
 Get/set whether the block is a hard block (affects logged-in users on a given IP/range).
 
 isSitewide ( $x=null)
 Indicates that the block is a sitewide block.
 
 isUsertalkEditAllowed ( $x=null)
 Get or set the flag indicating whether this block blocks the target from editing their own user talk page.
 
 setExpiry ( $expiry)
 Set the block expiry time.
 
 setHideName ( $hideName)
 Set whether the block hides the target's username.
 
 setReason ( $reason)
 Set the reason for creating the block.
 
 setTarget ( $target)
 Set the target for this block, and update $this->type accordingly.
 
 setTimestamp ( $timestamp)
 Set the timestamp indicating when the block was created.
 
 toArray ()
 Convert a block to an array of blocks.
 
- Public Member Functions inherited from MediaWiki\Block\Block
 getBlocker ()
 Get the user who applied this block.
 
 getIdentifier ( $wikiId=self::LOCAL)
 Get the information that identifies this block, such that a user could look up everything that can be found about this block.
 
 isCreateAccountBlocked ()
 Get the flag indicating whether this block blocks the target from creating an account.
 
 isHardblock ()
 Get whether the block is a hard block (affects logged-in users on a given IP/range).
 
 isSitewide ()
 Get whether the block is a sitewide block.
 
- Public Member Functions inherited from MediaWiki\DAO\WikiAwareEntity
 assertWiki ( $wikiId)
 Throws if $wikiId is different from the return value of getWikiId().
 

Protected Attributes

bool $allowUsertalk = false
 
bool $blockCreateAccount = false
 
bool $blockEmail = false
 
string $expiry = ''
 
bool $hideName = false
 
bool $isHardblock
 
bool $isSitewide = true
 
CommentStoreComment $reason
 
UserIdentity string null $target
 
string $timestamp = ''
 
int null $type
 AbstractBlock::TYPE_ constant.
 
string false $wikiId
 

Additional Inherited Members

- Public Attributes inherited from MediaWiki\Block\Block
const BLOCK_TYPES
 Map block types to strings, to allow convenient logging.
 
const TYPE_AUTO = 4
 
const TYPE_ID = 5
 
const TYPE_IP = 2
 
const TYPE_RANGE = 3
 
const TYPE_USER = 1
 

Detailed Description

Note
Extensions should not subclass this, as MediaWiki currently does not support custom block types.
Since
1.34 Factored out from DatabaseBlock (previously Block).

Definition at line 40 of file AbstractBlock.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

Parameters
array$optionsParameters of the block, with supported options:
  • address: (string|UserIdentity) Target user name, user identity object, IP address or IP range
  • wiki: (string|false) The wiki the block has been issued in, self::LOCAL for the local wiki (since 1.38)
  • reason: (string|Message|CommentStoreComment) Reason for the block
  • timestamp: (string) The time at which the block comes into effect
  • hideName: (bool) Hide the target user name
  • anonOnly: (bool) Used if the target is an IP address. The block only applies to anon and temporary users using this IP address, and not to logged-in users.

Reimplemented in MediaWiki\Block\CompositeBlock, MediaWiki\Block\DatabaseBlock, and MediaWiki\Block\SystemBlock.

Definition at line 97 of file AbstractBlock.php.

References MediaWiki\Block\Block\isHardblock(), MediaWiki\Block\AbstractBlock\setHideName(), MediaWiki\Block\AbstractBlock\setReason(), MediaWiki\Block\AbstractBlock\setTarget(), MediaWiki\Block\AbstractBlock\setTimestamp(), and wfTimestamp().

Member Function Documentation

◆ appliesToNamespace()

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

Checks if a block applies to a particular namespace.

Since
1.33
Parameters
int$ns
Returns
bool

Reimplemented in MediaWiki\Block\CompositeBlock, and MediaWiki\Block\DatabaseBlock.

Definition at line 536 of file AbstractBlock.php.

◆ appliesToPage()

MediaWiki\Block\AbstractBlock::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 hard blocks, range blocks, and auto-blocks).

Since
1.33
Parameters
int$pageId
Returns
bool

Reimplemented in MediaWiki\Block\CompositeBlock, and MediaWiki\Block\DatabaseBlock.

Definition at line 553 of file AbstractBlock.php.

◆ appliesToPasswordReset()

MediaWiki\Block\AbstractBlock::appliesToPasswordReset ( )

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

Since
1.33
Returns
bool The block blocks password reset

Reimplemented in MediaWiki\Block\CompositeBlock, and MediaWiki\Block\SystemBlock.

Definition at line 563 of file AbstractBlock.php.

◆ appliesToRight()

MediaWiki\Block\AbstractBlock::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 in MediaWiki\Block\CompositeBlock, and MediaWiki\Block\DatabaseBlock.

Definition at line 281 of file AbstractBlock.php.

Referenced by MediaWiki\User\User\isBlockedFromCreateAccount().

◆ appliesToTitle()

MediaWiki\Block\AbstractBlock::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 hard blocks, range blocks, and auto-blocks).

Parameters
Title$title
Returns
bool

Reimplemented in MediaWiki\Block\CompositeBlock, and MediaWiki\Block\DatabaseBlock.

Definition at line 524 of file AbstractBlock.php.

◆ appliesToUsertalk()

MediaWiki\Block\AbstractBlock::appliesToUsertalk ( Title $usertalk = null)

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

This is done separately from AbstractBlock::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

Reimplemented in MediaWiki\Block\CompositeBlock.

Definition at line 474 of file AbstractBlock.php.

References NS_USER_TALK.

◆ getBy()

MediaWiki\Block\AbstractBlock::getBy ( $wikiId = self::LOCAL)
abstract

Get the user id of the blocking sysop.

Parameters
string | false$wikiId(since 1.38)
Returns
int (0 for foreign users)

Reimplemented in MediaWiki\Block\CompositeBlock, MediaWiki\Block\DatabaseBlock, and MediaWiki\Block\SystemBlock.

◆ getByName()

MediaWiki\Block\AbstractBlock::getByName ( )
abstract

Get the username of the blocking sysop.

Returns
string

Reimplemented in MediaWiki\Block\CompositeBlock, MediaWiki\Block\DatabaseBlock, and MediaWiki\Block\SystemBlock.

◆ getExpiry()

MediaWiki\Block\AbstractBlock::getExpiry ( )

Get the block expiry time.

Since
1.19
Returns
string

Implements MediaWiki\Block\Block.

Reimplemented in MediaWiki\Block\CompositeBlock.

Definition at line 358 of file AbstractBlock.php.

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

◆ getHideName()

MediaWiki\Block\AbstractBlock::getHideName ( )

Get whether the block hides the target's username.

Since
1.33
Returns
bool The block hides the username

Definition at line 182 of file AbstractBlock.php.

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

◆ getId()

MediaWiki\Block\AbstractBlock::getId ( $wikiId = self::LOCAL)

Get the block ID.

Parameters
string | false$wikiId(since 1.38)
Returns
?int

Implements MediaWiki\Block\Block.

Reimplemented in MediaWiki\Block\DatabaseBlock.

Definition at line 135 of file AbstractBlock.php.

◆ getPermissionsError()

MediaWiki\Block\AbstractBlock::getPermissionsError ( IContextSource $context)

Get the key and parameters for the corresponding error message.

Deprecated
since 1.35 Use BlockErrorFormatter::getMessage instead, and build the array using Message::getKey and Message::getParams. Hard deprecated since 1.40.
Since
1.22
Parameters
IContextSource$context
Returns
array A message array: either a list of strings, the first of which is the message key and the remaining ones the parameters, or an array with a single MessageSpecifier object.

Definition at line 435 of file AbstractBlock.php.

References IContextSource\getLanguage(), IContextSource\getRequest(), IContextSource\getUser(), and wfDeprecated().

◆ getReason()

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

Reimplemented in MediaWiki\Block\DatabaseBlock.

Definition at line 150 of file AbstractBlock.php.

References wfDeprecated().

◆ getReasonComment()

MediaWiki\Block\AbstractBlock::getReasonComment ( )

Get the reason for creating the block.

Since
1.35
Returns
CommentStoreComment

Implements MediaWiki\Block\Block.

Definition at line 162 of file AbstractBlock.php.

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

◆ getTargetName()

MediaWiki\Block\AbstractBlock::getTargetName ( )
Since
1.37
Returns
string

Implements MediaWiki\Block\Block.

Definition at line 332 of file AbstractBlock.php.

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

◆ getTargetUserIdentity()

MediaWiki\Block\AbstractBlock::getTargetUserIdentity ( )
Since
1.37
Returns
?UserIdentity

Implements MediaWiki\Block\Block.

Definition at line 324 of file AbstractBlock.php.

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

◆ getTimestamp()

MediaWiki\Block\AbstractBlock::getTimestamp ( )

Get the timestamp indicating when the block was created.

Since
1.33
Returns
string

Implements MediaWiki\Block\Block.

Reimplemented in MediaWiki\Block\CompositeBlock.

Definition at line 379 of file AbstractBlock.php.

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

◆ getType()

MediaWiki\Block\AbstractBlock::getType ( )

Get the type of target for this particular block.

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

Implements MediaWiki\Block\Block.

Reimplemented in MediaWiki\Block\DatabaseBlock.

Definition at line 316 of file AbstractBlock.php.

◆ getWikiId()

◆ isBlocking()

MediaWiki\Block\AbstractBlock::isBlocking ( $target)
Parameters
UserIdentity | string$target
Returns
bool
Since
1.37

Implements MediaWiki\Block\Block.

Definition at line 344 of file AbstractBlock.php.

◆ isCreateAccountBlocked()

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

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

◆ isEmailBlocked()

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

References wfSetVar().

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

◆ isHardblock()

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

Get/set whether the block is a hard block (affects logged-in users on a given IP/range).

Note that temporary users are not considered logged-in here - they are always blocked by IP-address blocks.

Note that user blocks are always hard blocks, since the target is logged in by definition.

Since
1.36 Moved up from DatabaseBlock
Parameters
bool | null$x
Returns
bool

Reimplemented in MediaWiki\Block\DatabaseBlock.

Definition at line 262 of file AbstractBlock.php.

◆ isSitewide()

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

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

◆ isUsertalkEditAllowed()

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

References wfSetVar().

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

◆ setExpiry()

MediaWiki\Block\AbstractBlock::setExpiry ( $expiry)

Set the block expiry time.

Since
1.33
Parameters
string$expiry

Definition at line 368 of file AbstractBlock.php.

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

◆ setHideName()

MediaWiki\Block\AbstractBlock::setHideName ( $hideName)

Set whether the block hides the target's username.

Since
1.33
Parameters
bool$hideNameThe block hides the username

Definition at line 192 of file AbstractBlock.php.

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

◆ setReason()

MediaWiki\Block\AbstractBlock::setReason ( $reason)

Set the reason for creating the block.

Since
1.33
Parameters
string | Message | CommentStoreComment$reason

Definition at line 172 of file AbstractBlock.php.

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

◆ setTarget()

MediaWiki\Block\AbstractBlock::setTarget ( $target)

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

Parameters
string | UserIdentity | null$target

Definition at line 398 of file AbstractBlock.php.

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

◆ setTimestamp()

MediaWiki\Block\AbstractBlock::setTimestamp ( $timestamp)

Set the timestamp indicating when the block was created.

Since
1.33
Parameters
string$timestamp

Definition at line 389 of file AbstractBlock.php.

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

◆ toArray()

MediaWiki\Block\AbstractBlock::toArray ( )

Convert a block to an array of blocks.

If the block is a composite block, return the array of original blocks. Otherwise, return [$this].

Since
1.41
Returns
Block[]

Implements MediaWiki\Block\Block.

Reimplemented in MediaWiki\Block\CompositeBlock.

Definition at line 567 of file AbstractBlock.php.

Member Data Documentation

◆ $allowUsertalk

bool MediaWiki\Block\AbstractBlock::$allowUsertalk = false
protected

Definition at line 56 of file AbstractBlock.php.

◆ $blockCreateAccount

bool MediaWiki\Block\AbstractBlock::$blockCreateAccount = false
protected

Definition at line 59 of file AbstractBlock.php.

◆ $blockEmail

bool MediaWiki\Block\AbstractBlock::$blockEmail = false
protected

Definition at line 53 of file AbstractBlock.php.

◆ $expiry

string MediaWiki\Block\AbstractBlock::$expiry = ''
protected

Definition at line 50 of file AbstractBlock.php.

◆ $hideName

bool MediaWiki\Block\AbstractBlock::$hideName = false
protected

Definition at line 62 of file AbstractBlock.php.

◆ $isHardblock

bool MediaWiki\Block\AbstractBlock::$isHardblock
protected

Definition at line 65 of file AbstractBlock.php.

◆ $isSitewide

bool MediaWiki\Block\AbstractBlock::$isSitewide = true
protected

Definition at line 77 of file AbstractBlock.php.

◆ $reason

CommentStoreComment MediaWiki\Block\AbstractBlock::$reason
protected

Definition at line 44 of file AbstractBlock.php.

◆ $target

UserIdentity string null MediaWiki\Block\AbstractBlock::$target
protected

◆ $timestamp

string MediaWiki\Block\AbstractBlock::$timestamp = ''
protected

◆ $type

int null MediaWiki\Block\AbstractBlock::$type
protected

AbstractBlock::TYPE_ constant.

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

Definition at line 74 of file AbstractBlock.php.

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

◆ $wikiId

string false MediaWiki\Block\AbstractBlock::$wikiId
protected

Definition at line 80 of file AbstractBlock.php.


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