Remove Target/User validation from Block::appliesToUsertalk()
authorDavid Barratt <dbarratt@wikimedia.org>
Mon, 25 Feb 2019 18:35:35 +0000 (13:35 -0500)
committerDavid Barratt <dbarratt@wikimedia.org>
Mon, 25 Feb 2019 20:22:21 +0000 (15:22 -0500)
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

includes/Block.php

index 1a54394..09f6d9f 100644 (file)
@@ -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;