] );
}
+ // 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,
] );
}
return null;
}
+ /**
+ * Given a list of blocks, return a list of unique blocks.
+ *
+ * This usually means that each block has a unique ID. For a block with ID null,
+ * if it's an autoblock, it will be filtered out if the parent block is present;
+ * if not, it is assumed to be a unique system block, and kept.
+ *
+ * @param AbstractBlock[] $blocks
+ * @return AbstractBlock[]
+ */
+ private function getUniqueBlocks( $blocks ) {
+ $systemBlocks = [];
+ $databaseBlocks = [];
+
+ foreach ( $blocks as $block ) {
+ if ( $block instanceof SystemBlock ) {
+ $systemBlocks[] = $block;
+ } elseif ( $block->getType() === DatabaseBlock::TYPE_AUTO ) {
+ if ( !isset( $databaseBlocks[$block->getParentBlockId()] ) ) {
+ $databaseBlocks[$block->getParentBlockId()] = $block;
+ }
+ } else {
+ $databaseBlocks[$block->getId()] = $block;
+ }
+ }
+
+ return array_merge( $systemBlocks, $databaseBlocks );
+ }
+
/**
* Try to load a block from an ID given in a cookie value.
*