* Load blocks from the database which target the specific target exactly, or which cover the
* vague target.
*
- * @param User|String|null $specificTarget
+ * @param User|string|null $specificTarget
* @param int|null $specificType
* @param bool $fromMaster
* @param User|string|null $vagueTarget Also search for blocks affecting this target. Doesn't
* @param DatabaseBlock[] $blocks These should not include autoblocks or ID blocks
* @return DatabaseBlock|null The block with the most specific target
*/
- protected static function chooseMostSpecificBlock( $blocks ) {
+ protected static function chooseMostSpecificBlock( array $blocks ) {
if ( count( $blocks ) === 1 ) {
return $blocks[0];
}
* @return bool|array False on failure, assoc array on success:
* ('id' => block ID, 'autoIds' => array of autoblock IDs)
*/
- public function insert( $dbw = null ) {
+ public function insert( IDatabase $dbw = null ) {
global $wgBlockDisablesLogin;
if ( !$this->getBlocker() || $this->getBlocker()->getName() === '' ) {
return $this;
}
+ /**
+ * @since 1.34
+ * @return int|null If this is an autoblock, ID of the parent block; otherwise null
+ */
+ public function getParentBlockId() {
+ return $this->mParentBlockId;
+ }
+
/**
* Get/set a flag determining whether the master is used for reads
*
* not be the same as the target you gave if you used $vagueTarget!
*/
public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
+ $blocks = self::newListFromTarget( $specificTarget, $vagueTarget, $fromMaster );
+ return self::chooseMostSpecificBlock( $blocks );
+ }
+
+ /**
+ * This is similar to DatabaseBlock::newFromTarget, but it returns all the relevant blocks.
+ *
+ * @since 1.34
+ * @param string|User|int|null $specificTarget
+ * @param string|User|int|null $vagueTarget
+ * @param bool $fromMaster
+ * @return DatabaseBlock[] Any relevant blocks
+ */
+ public static function newListFromTarget(
+ $specificTarget,
+ $vagueTarget = null,
+ $fromMaster = false
+ ) {
list( $target, $type ) = self::parseTarget( $specificTarget );
if ( $type == self::TYPE_ID || $type == self::TYPE_AUTO ) {
- return self::newFromID( $target );
-
+ $block = self::newFromID( $target );
+ return $block ? [ $block ] : [];
} elseif ( $target === null && $vagueTarget == '' ) {
# We're not going to find anything useful here
# Be aware that the == '' check is explicit, since empty values will be
# passed by some callers (T31116)
- return null;
-
+ return [];
} elseif ( in_array(
$type,
[ self::TYPE_USER, self::TYPE_IP, self::TYPE_RANGE, null ] )
) {
- $blocks = self::newLoad( $target, $type, $fromMaster, $vagueTarget );
- if ( !empty( $blocks ) ) {
- return self::chooseMostSpecificBlock( $blocks );
- }
+ return self::newLoad( $target, $type, $fromMaster, $vagueTarget );
}
- return null;
+ return [];
}
/**