return;
}
- $target = $block->getTarget();
- // FIXME: Push this into getTargetActor() or whatever to reuse
- if ( is_string( $target ) ) {
- $target = User::newFromName( $target, false );
+ // Autoblocks only apply to TYPE_USER
+ if ( $block->getType() !== self::TYPE_USER ) {
+ return;
}
+ $target = $block->getTarget(); // TYPE_USER => always a User object
$dbr = wfGetDB( DB_REPLICA );
$rcQuery = ActorMigration::newMigration()->getWhere( $dbr, 'rc_user', $target, false );
* prohibited from editing any page on the site (other than their own talk
* page).
*
+ * @since 1.33
* @param null|bool $x
* @return bool
*/
$res = $this->isSitewide();
break;
case 'editownusertalk':
+ // NOTE: this check is not reliable on partial blocks
+ // since partially blocked users are always allowed to edit
+ // their own talk page unless a restriction exists on the
+ // page or User_talk: namespace
$res = wfSetVar( $this->mDisableUsertalk, $x );
+
// edit own user talk can be disabled by config
if ( !$blockAllowsUTEdit ) {
$res = true;
* @since 1.22
*/
public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
- if ( !count( $ipChain ) ) {
+ if ( $ipChain === [] ) {
return [];
}
$conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
}
- if ( !count( $conds ) ) {
+ if ( $conds === [] ) {
return [];
}
* @return Block|null The "best" block from the list
*/
public static function chooseBlock( array $blocks, array $ipChain ) {
- if ( !count( $blocks ) ) {
+ if ( $blocks === [] ) {
return null;
} elseif ( count( $blocks ) == 1 ) {
return $blocks[0];
* @param User|string $user Local User object or username string
*/
public function setBlocker( $user ) {
- // FIXME: Push this into getTargetActor() or whatever to reuse
if ( is_string( $user ) ) {
$user = User::newFromName( $user, false );
}
/**
* Get block information used in different block error messages
*
+ * @since 1.33
* @param IContextSource $context
* @return array
*/
* Getting the restrictions will perform a database query if the restrictions
* are not already loaded.
*
+ * @since 1.33
* @return Restriction[]
*/
public function getRestrictions() {
/**
* Set Restrictions.
*
+ * @since 1.33
* @param Restriction[] $restrictions
- *
* @return self
*/
public function setRestrictions( array $restrictions ) {
}
/**
- * Checks if a block prevents an edit on a given article
+ * Checks if a block applies to a particular title
+ *
+ * This check does not consider whether `$this->prevents( 'editownusertalk' )`
+ * returns false, as the identity of the user making the hypothetical edit
+ * isn't known here (particularly in the case of IP hardblocks, range
+ * blocks, and auto-blocks).
*
- * @param \Title $title
+ * @param Title $title
* @return bool
*/
- public function preventsEdit( \Title $title ) {
- $blocked = $this->isSitewide();
-
- // user talk page has its own rules
- // This check happens before partial blocks because the flag
- // to allow user to edit their user talk page could be
- // overwritten by a partial block restriction (E.g. user talk namespace)
- $user = $this->getTarget();
-
- // Not all blocked `$user`s are self::TYPE_USER
- // FIXME: Push this into getTargetActor() or whatever to reuse
- if ( is_string( $user ) ) {
- $user = User::newFromName( $user, false );
- }
-
- if ( $title->equals( $user->getTalkPage() ) ) {
- $blocked = $this->prevents( 'editownusertalk' );
+ public function appliesToTitle( Title $title ) {
+ if ( $this->isSitewide() ) {
+ return true;
}
- if ( !$this->isSitewide() ) {
- $restrictions = $this->getRestrictions();
- foreach ( $restrictions as $restriction ) {
- if ( $restriction->matches( $title ) ) {
- $blocked = true;
- }
+ $restrictions = $this->getRestrictions();
+ foreach ( $restrictions as $restriction ) {
+ if ( $restriction->matches( $title ) ) {
+ return true;
}
}
- return $blocked;
+ return false;
}
}