From: David Barratt Date: Mon, 25 Feb 2019 18:35:35 +0000 (-0500) Subject: Remove Target/User validation from Block::appliesToUsertalk() X-Git-Tag: 1.34.0-rc.0~2722^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=680565ed3fba3c20987ee318947c30e582a51e6c;p=lhc%2Fweb%2Fwiklou.git Remove Target/User validation from Block::appliesToUsertalk() This fixes a regression in I0e131696419211319082cb454f4f05297e55d22e where an IP block that also blocks logged in users from editing, throws an exception. The target/user validation in Block::appliesToUsertalk() does not work well when an IP block prevents logged in users from editing. This case throws a validation error, when in reality it should make a judgement. This change means that the method will now trust whatever is passed into it as the current user's talk page. Bug: T211578 Change-Id: I3bb27cf7bec8421d31aa4de28a0e658365bb5bf2 --- diff --git a/includes/Block.php b/includes/Block.php index 1a54394ee1..09f6d9f631 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -1912,18 +1912,18 @@ class Block { * 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 * @param Title|null $usertalk The user's user talk page. If null, * and if the target is a User, the target's userpage is used * @return bool The user can edit their talk page */ public function appliesToUsertalk( Title $usertalk = null ) { - $target = $this->target; - $targetIsUser = $target instanceof User; - $targetName = $targetIsUser ? $target->getName() : $target; - if ( !$usertalk ) { - if ( $targetIsUser ) { + if ( $this->target instanceof User ) { $usertalk = $this->target->getTalkPage(); } else { throw new InvalidArgumentException( @@ -1938,28 +1938,6 @@ class Block { ); } - switch ( $this->type ) { - case self::TYPE_USER: - case self::TYPE_IP: - if ( $usertalk->getText() !== $targetName ) { - throw new InvalidArgumentException( - '$usertalk must be a talk page for the block target' - ); - } - break; - case self::TYPE_RANGE: - if ( !IP::isInRange( $usertalk->getText(), $target ) ) { - throw new InvalidArgumentException( - '$usertalk must be a talk page for an IP within the block target range' - ); - } - break; - default: - throw new LogicException( - 'Cannot determine validity of $usertalk for this type of block' - ); - } - if ( !$this->isSitewide() ) { if ( $this->appliesToPage( $usertalk->getArticleID() ) ) { return true;