X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fblock%2FCompositeBlock.php;h=6f49f170ee47181a2bac1f86e8f8b4dd322c9f75;hp=e0f69dda8ad3e4dfb50bed9c798a96b781870cc4;hb=54c93f1d384cd5accd2db2ebbb911e4d627c2980;hpb=7388b7b62b842ef1e80faa677656a26a90803ece diff --git a/includes/block/CompositeBlock.php b/includes/block/CompositeBlock.php index e0f69dda8a..6f49f170ee 100644 --- a/includes/block/CompositeBlock.php +++ b/includes/block/CompositeBlock.php @@ -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 ); @@ -120,12 +121,40 @@ class CompositeBlock extends AbstractBlock { return $maxExpiry; } + /** + * Get the IDs for the original blocks, ignoring any that are null + * + * @return int[] + */ + protected function getIds() { + $ids = []; + foreach ( $this->originalBlocks as $block ) { + $id = $block->getId(); + if ( $id !== null ) { + $ids[] = $id; + } + } + return $ids; + } + /** * @inheritDoc */ public function getPermissionsError( IContextSource $context ) { $params = $this->getBlockErrorParams( $context ); + $ids = implode( ', ', array_map( function ( $id ) { + return '#' . $id; + }, $this->getIds() ) ); + if ( $ids === '' ) { + $idsMsg = $context->msg( 'blockedtext-composite-no-ids' )->plain(); + } else { + $idsMsg = $context->msg( 'blockedtext-composite-ids', [ $ids ] )->plain(); + } + + // TODO: Clean up error messages params so we don't have to do this (T227174) + $params[ 4 ] = $idsMsg; + $msg = 'blockedtext-composite'; array_unshift( $params, $msg ); @@ -135,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; } /**