Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / block / CompositeBlock.php
index 45a6301..6f49f17 100644 (file)
@@ -40,8 +40,9 @@ class CompositeBlock extends AbstractBlock {
        /**
         * Create a new block with specified parameters on a user, IP or IP range.
         *
-        * @param array $options Parameters of the block:
-        *     originalBlocks Block[] Blocks that this block is composed from
+        * @param array $options Parameters of the block, with options supported by
+        *  `AbstractBlock::__construct`, and also:
+        *  - originalBlocks: (Block[]) Blocks that this block is composed from
         */
        public function __construct( array $options = [] ) {
                parent::__construct( $options );
@@ -163,9 +164,28 @@ class CompositeBlock extends AbstractBlock {
 
        /**
         * @inheritDoc
+        *
+        * Determines whether the CompositeBlock applies to a right by checking
+        * whether the original blocks apply to that right. Each block can report
+        * true (applies), false (does not apply) or null (unsure). Then:
+        * - If any original blocks apply, this block applies
+        * - If no original blocks apply but any are unsure, this block is unsure
+        * - If all blocks do not apply, this block does not apply
         */
        public function appliesToRight( $right ) {
-               return $this->methodReturnsValue( __FUNCTION__, true, $right );
+               $isUnsure = false;
+
+               foreach ( $this->originalBlocks as $block ) {
+                       $appliesToRight = $block->appliesToRight( $right );
+
+                       if ( $appliesToRight ) {
+                               return true;
+                       } elseif ( $appliesToRight === null ) {
+                               $isUnsure = true;
+                       }
+               }
+
+               return $isUnsure ? null : false;
        }
 
        /**