Merge "Use MediaWiki\SuppressWarnings around trigger_error('') instead @"
[lhc/web/wiklou.git] / includes / Block.php
index befc50c..ec8cae8 100644 (file)
@@ -766,10 +766,11 @@ class Block {
                        return;
                }
 
-               $target = $block->getTarget();
-               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 );
@@ -1167,7 +1168,12 @@ class Block {
                                $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;
@@ -1794,32 +1800,28 @@ class Block {
        }
 
        /**
-        * 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 it's 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();
-               if ( $title->equals( $user->getTalkPage() ) ) {
-                       $blocked = $this->prevents( 'editownusertalk' );
-               }
-
-               if ( !$this->isSitewide() ) {
-                       $restrictions = $this->getRestrictions();
-                       foreach ( $restrictions as $restriction ) {
-                               if ( $restriction->matches( $title ) ) {
-                                       $blocked = true;
-                               }
+       public function appliesToTitle( Title $title ) {
+               if ( $this->isSitewide() ) {
+                       return true;
+               }
+
+               $restrictions = $this->getRestrictions();
+               foreach ( $restrictions as $restriction ) {
+                       if ( $restriction->matches( $title ) ) {
+                               return true;
                        }
                }
 
-               return $blocked;
+               return false;
        }
 }