Add some @since tags to ParserOutput::SUPPORTS_ constants
[lhc/web/wiklou.git] / includes / block / BlockManager.php
index 60ae2f8..41ff893 100644 (file)
@@ -202,12 +202,17 @@ class BlockManager {
                        ] );
                }
 
+               // Filter out any duplicated blocks, e.g. from the cookie
+               $blocks = $this->getUniqueBlocks( $blocks );
+
                if ( count( $blocks ) > 0 ) {
                        if ( count( $blocks ) === 1 ) {
                                $block = $blocks[ 0 ];
                        } else {
                                $block = new CompositeBlock( [
                                        'address' => $ip,
+                                       'byText' => 'MediaWiki default',
+                                       'reason' => wfMessage( 'blockedtext-composite-reason' )->plain(),
                                        'originalBlocks' => $blocks,
                                ] );
                        }
@@ -217,6 +222,28 @@ class BlockManager {
                return null;
        }
 
+       /**
+        * Given a list of blocks, return a list blocks where each block either has a
+        * unique ID or has ID null.
+        *
+        * @param AbstractBlock[] $blocks
+        * @return AbstractBlock[]
+        */
+       private function getUniqueBlocks( $blocks ) {
+               $blockIds = [];
+               $uniqueBlocks = [];
+               foreach ( $blocks as $block ) {
+                       $id = $block->getId();
+                       if ( $id === null ) {
+                               $uniqueBlocks[] = $block;
+                       } elseif ( !isset( $blockIds[$id] ) ) {
+                               $uniqueBlocks[] = $block;
+                               $blockIds[$block->getId()] = true;
+                       }
+               }
+               return $uniqueBlocks;
+       }
+
        /**
         * Try to load a block from an ID given in a cookie value.
         *