MediaWiki REL1_34
CompositeBlock.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Block;
24
26use Title;
27
39
47 public function __construct( array $options = [] ) {
48 parent::__construct( $options );
49
50 $defaults = [
51 'originalBlocks' => [],
52 ];
53
54 $options += $defaults;
55
56 $this->originalBlocks = $options[ 'originalBlocks' ];
57
58 $this->setHideName( $this->propHasValue( 'mHideName', true ) );
59 $this->isSitewide( $this->propHasValue( 'isSitewide', true ) );
60 $this->isEmailBlocked( $this->propHasValue( 'mBlockEmail', true ) );
61 $this->isCreateAccountBlocked( $this->propHasValue( 'blockCreateAccount', true ) );
62 $this->isUsertalkEditAllowed( !$this->propHasValue( 'allowUsertalk', false ) );
63 }
64
73 private function propHasValue( $prop, $value ) {
74 foreach ( $this->originalBlocks as $block ) {
75 if ( $block->$prop == $value ) {
76 return true;
77 }
78 }
79 return false;
80 }
81
91 private function methodReturnsValue( $method, $value, ...$params ) {
92 foreach ( $this->originalBlocks as $block ) {
93 if ( $block->$method( ...$params ) == $value ) {
94 return true;
95 }
96 }
97 return false;
98 }
99
106 public function getOriginalBlocks() {
108 }
109
113 public function getExpiry() {
114 $maxExpiry = null;
115 foreach ( $this->originalBlocks as $block ) {
116 $expiry = $block->getExpiry();
117 if ( $maxExpiry === null || $expiry === '' || $expiry > $maxExpiry ) {
118 $maxExpiry = $expiry;
119 }
120 }
121 return $maxExpiry;
122 }
123
129 protected function getIds() {
130 $ids = [];
131 foreach ( $this->originalBlocks as $block ) {
132 $id = $block->getId();
133 if ( $id !== null ) {
134 $ids[] = $id;
135 }
136 }
137 return $ids;
138 }
139
144 $params = $this->getBlockErrorParams( $context );
145
146 $ids = implode( ', ', array_map( function ( $id ) {
147 return '#' . $id;
148 }, $this->getIds() ) );
149 if ( $ids === '' ) {
150 $idsMsg = $context->msg( 'blockedtext-composite-no-ids' )->plain();
151 } else {
152 $idsMsg = $context->msg( 'blockedtext-composite-ids', [ $ids ] )->plain();
153 }
154
155 // TODO: Clean up error messages params so we don't have to do this (T227174)
156 $params[ 4 ] = $idsMsg;
157
158 $msg = 'blockedtext-composite';
159
160 array_unshift( $params, $msg );
161
162 return $params;
163 }
164
175 public function appliesToRight( $right ) {
176 $isUnsure = false;
177
178 foreach ( $this->originalBlocks as $block ) {
179 $appliesToRight = $block->appliesToRight( $right );
180
181 if ( $appliesToRight ) {
182 return true;
183 } elseif ( $appliesToRight === null ) {
184 $isUnsure = true;
185 }
186 }
187
188 return $isUnsure ? null : false;
189 }
190
194 public function appliesToUsertalk( Title $usertalk = null ) {
195 return $this->methodReturnsValue( __FUNCTION__, true, $usertalk );
196 }
197
201 public function appliesToTitle( Title $title ) {
202 return $this->methodReturnsValue( __FUNCTION__, true, $title );
203 }
204
208 public function appliesToNamespace( $ns ) {
209 return $this->methodReturnsValue( __FUNCTION__, true, $ns );
210 }
211
215 public function appliesToPage( $pageId ) {
216 return $this->methodReturnsValue( __FUNCTION__, true, $pageId );
217 }
218
222 public function appliesToPasswordReset() {
223 return $this->methodReturnsValue( __FUNCTION__, true );
224 }
225
226}
isUsertalkEditAllowed( $x=null)
Get or set the flag indicating whether this block blocks the target from editing their own user talk ...
setHideName( $hideName)
Set whether ths block hides the target's username.
isCreateAccountBlocked( $x=null)
Get or set the flag indicating whether this block blocks the target from creating an account.
getBlockErrorParams(IContextSource $context)
Get block information used in different block error messages.
isEmailBlocked( $x=null)
Get or set the flag indicating whether this block blocks the target from sending emails.
isSitewide( $x=null)
Indicates that the block is a sitewide block.
getPermissionsError(IContextSource $context)
Get the key and parameters for the corresponding error message.1.22 array
appliesToNamespace( $ns)
Checks if a block applies to a particular namespace.1.33bool
getExpiry()
Get the block expiry time.1.19 string
getIds()
Get the IDs for the original blocks, ignoring any that are null.
methodReturnsValue( $method, $value,... $params)
Determine whether any original blocks have a particular method returning a particular value.
propHasValue( $prop, $value)
Determine whether any original blocks have a particular property set to a particular value.
getOriginalBlocks()
Get the original blocks from which this block is composed.
appliesToRight( $right)
Determine whether the block prevents a given right.A right may be blacklisted or whitelisted,...
appliesToPage( $pageId)
Checks if a block applies to a particular page.This check does not consider whether $this->isUsertalk...
appliesToUsertalk(Title $usertalk=null)
Determine whether the block allows the user to edit their own user talk page.This is done separately ...
appliesToPasswordReset()
Check if the block prevents a user from resetting their password.1.33 bool The block blocks password ...
__construct(array $options=[])
Create a new block with specified parameters on a user, IP or IP range.
appliesToTitle(Title $title)
Checks if a block applies to a particular title.This check does not consider whether $this->isUsertal...
Represents a title within MediaWiki.
Definition Title.php:42
Interface for objects which can provide a MediaWiki context on request.
$context
Definition load.php:45