Merge "WebInstallerOutput: Add getLanguage()"
[lhc/web/wiklou.git] / includes / Block.php
index 39f2b29..7138301 100644 (file)
@@ -766,11 +766,11 @@ class Block {
                        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 );
@@ -1132,6 +1132,7 @@ class Block {
         * prohibited from editing any page on the site (other than their own talk
         * page).
         *
+        * @since 1.33
         * @param null|bool $x
         * @return bool
         */
@@ -1168,7 +1169,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;
@@ -1301,7 +1307,7 @@ class Block {
         * @since 1.22
         */
        public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
-               if ( !count( $ipChain ) ) {
+               if ( $ipChain === [] ) {
                        return [];
                }
 
@@ -1326,7 +1332,7 @@ class Block {
                        $conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
                }
 
-               if ( !count( $conds ) ) {
+               if ( $conds === [] ) {
                        return [];
                }
 
@@ -1382,7 +1388,7 @@ class Block {
         * @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];
@@ -1595,7 +1601,6 @@ class Block {
         * @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 );
                }
@@ -1724,6 +1729,7 @@ class Block {
        /**
         * Get block information used in different block error messages
         *
+        * @since 1.33
         * @param IContextSource $context
         * @return array
         */
@@ -1765,6 +1771,7 @@ class Block {
         * Getting the restrictions will perform a database query if the restrictions
         * are not already loaded.
         *
+        * @since 1.33
         * @return Restriction[]
         */
        public function getRestrictions() {
@@ -1783,8 +1790,8 @@ class Block {
        /**
         * Set Restrictions.
         *
+        * @since 1.33
         * @param Restriction[] $restrictions
-        *
         * @return self
         */
        public function setRestrictions( array $restrictions ) {
@@ -1796,39 +1803,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 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;
        }
 }