3 * Class for blocks composed from multiple blocks.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Block
;
29 * Multiple Block class.
31 * Multiple blocks exist to enforce restrictions from more than one block, if several
32 * blocks apply to a user/IP. Multiple blocks are created temporarily on enforcement.
36 class CompositeBlock
extends AbstractBlock
{
37 /** @var AbstractBlock[] */
38 private $originalBlocks;
41 * Create a new block with specified parameters on a user, IP or IP range.
43 * @param array $options Parameters of the block:
44 * originalBlocks Block[] Blocks that this block is composed from
46 function __construct( $options = [] ) {
47 parent
::__construct( $options );
50 'originalBlocks' => [],
53 $options +
= $defaults;
55 $this->originalBlocks
= $options[ 'originalBlocks' ];
57 $this->setHideName( $this->propHasValue( 'mHideName', true ) );
58 $this->isSitewide( $this->propHasValue( 'isSitewide', true ) );
59 $this->isEmailBlocked( $this->propHasValue( 'mBlockEmail', true ) );
60 $this->isCreateAccountBlocked( $this->propHasValue( 'blockCreateAccount', true ) );
61 $this->isUsertalkEditAllowed( !$this->propHasValue( 'allowUsertalk', false ) );
65 * Determine whether any original blocks have a particular property set to a
70 * @return bool At least one block has the property set to the value
72 private function propHasValue( $prop, $value ) {
73 foreach ( $this->originalBlocks
as $block ) {
74 if ( $block->$prop == $value ) {
82 * Determine whether any original blocks have a particular method returning a
85 * @param string $method
87 * @param mixed ...$params
88 * @return bool At least one block has the method returning the value
90 private function methodReturnsValue( $method, $value, ...$params ) {
91 foreach ( $this->originalBlocks
as $block ) {
92 if ( $block->$method( ...$params ) == $value ) {
100 * Get the original blocks from which this block is composed
103 * @return AbstractBlock[]
105 public function getOriginalBlocks() {
106 return $this->originalBlocks
;
112 public function getExpiry() {
114 foreach ( $this->originalBlocks
as $block ) {
115 $expiry = $block->getExpiry();
116 if ( $maxExpiry === null ||
$expiry === '' ||
$expiry > $maxExpiry ) {
117 $maxExpiry = $expiry;
126 public function getPermissionsError( IContextSource
$context ) {
127 $params = $this->getBlockErrorParams( $context );
129 $msg = 'blockedtext-composite';
131 array_unshift( $params, $msg );
139 public function appliesToRight( $right ) {
140 return $this->methodReturnsValue( __FUNCTION__
, true, $right );
146 public function appliesToUsertalk( Title
$usertalk = null ) {
147 return $this->methodReturnsValue( __FUNCTION__
, true, $usertalk );
153 public function appliesToTitle( Title
$title ) {
154 return $this->methodReturnsValue( __FUNCTION__
, true, $title );
160 public function appliesToNamespace( $ns ) {
161 return $this->methodReturnsValue( __FUNCTION__
, true, $ns );
167 public function appliesToPage( $pageId ) {
168 return $this->methodReturnsValue( __FUNCTION__
, true, $pageId );
174 public function appliesToPasswordReset() {
175 return $this->methodReturnsValue( __FUNCTION__
, true );