aboutsummaryrefslogtreecommitdiffstats
path: root/includes/block/AbstractBlock.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/block/AbstractBlock.php')
-rw-r--r--includes/block/AbstractBlock.php58
1 files changed, 39 insertions, 19 deletions
diff --git a/includes/block/AbstractBlock.php b/includes/block/AbstractBlock.php
index c56859b5f02c..49280ef4f168 100644
--- a/includes/block/AbstractBlock.php
+++ b/includes/block/AbstractBlock.php
@@ -34,7 +34,7 @@ use User;
* @note Extensions should not subclass this, as MediaWiki currently does not support custom block types.
* @since 1.34 Factored out from DatabaseBlock (previously Block).
*/
-abstract class AbstractBlock {
+abstract class AbstractBlock implements Block {
/** @var CommentStoreComment */
protected $reason;
@@ -80,14 +80,6 @@ abstract class AbstractBlock {
/** @var bool */
protected $isSitewide = true;
- # TYPE constants
- # Do not introduce negative constants without changing BlockUser command object.
- public const TYPE_USER = 1;
- public const TYPE_IP = 2;
- public const TYPE_RANGE = 3;
- public const TYPE_AUTO = 4;
- public const TYPE_ID = 5;
-
/**
* Create a new block with specified parameters on a user, IP or IP range.
*
@@ -139,15 +131,6 @@ abstract class AbstractBlock {
}
/**
- * Get the information that identifies this block, such that a user could
- * look up everything that can be found about this block. May be an ID,
- * array of IDs, type, etc.
- *
- * @return mixed Identifying information
- */
- abstract public function getIdentifier();
-
- /**
* Get the reason given for creating the block, as a string.
*
* Deprecated, since this gives the caller no control over the language
@@ -350,6 +333,9 @@ abstract class AbstractBlock {
*
* If the type is not null, it will be an AbstractBlock::TYPE_ constant.
*
+ * @deprecated since 1.37, use getTargetName() and getTargetUserIdentity()
+ * together with getType()
+ *
* @return array [ User|String|null, int|null ]
* @todo FIXME: This should be an integral part of the block member variables
*/
@@ -358,9 +344,11 @@ abstract class AbstractBlock {
}
/**
- * Get the target for this particular block. Note that for autoblocks,
+ * Get the target for this particular block. Note that for autoblocks,
* this returns the unredacted name; frontend functions need to call $block->getRedactedName()
* in this situation.
+ * @deprecated since 1.37, use getTargetName() and getTargetUserIdentity()
+ * together with getType()
* @return User|string|null
*/
public function getTarget() {
@@ -368,6 +356,38 @@ abstract class AbstractBlock {
}
/**
+ * @since 1.37
+ * @return ?UserIdentity
+ */
+ public function getTargetUserIdentity(): ?UserIdentity {
+ return $this->target instanceof UserIdentity ? $this->target : null;
+ }
+
+ /**
+ * @since 1.37
+ * @return string
+ */
+ public function getTargetName(): string {
+ return $this->target instanceof UserIdentity
+ ? $this->target->getName()
+ : (string)$this->target;
+ }
+
+ /**
+ * @param UserIdentity|string $target
+ *
+ * @return bool
+ * @since 1.37
+ */
+ public function isBlocking( $target ): bool {
+ $targetName = $target instanceof UserIdentity
+ ? $target->getName()
+ : (string)$target;
+
+ return $targetName === $this->getTargetName();
+ }
+
+ /**
* Get the block expiry time
*
* @since 1.19