MediaWiki  1.34.0
CompositeBlock.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Block;
24 
25 use IContextSource;
26 use Title;
27 
38  private $originalBlocks;
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() {
107  return $this->originalBlocks;
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 }
MediaWiki\Block\CompositeBlock\appliesToPasswordReset
appliesToPasswordReset()
Check if the block prevents a user from resetting their password.1.33 bool The block blocks password ...
Definition: CompositeBlock.php:222
MediaWiki\Block
Definition: AbstractBlock.php:21
MediaWiki\Block\CompositeBlock\getExpiry
getExpiry()
Get the block expiry time.1.19 string
Definition: CompositeBlock.php:113
MediaWiki\Block\AbstractBlock\isCreateAccountBlocked
isCreateAccountBlocked( $x=null)
Get or set the flag indicating whether this block blocks the target from creating an account.
Definition: AbstractBlock.php:216
MediaWiki\Block\CompositeBlock\$originalBlocks
AbstractBlock[] $originalBlocks
Definition: CompositeBlock.php:38
MediaWiki\Block\CompositeBlock\appliesToPage
appliesToPage( $pageId)
Checks if a block applies to a particular page.This check does not consider whether $this->isUsertalk...
Definition: CompositeBlock.php:215
MediaWiki\Block\CompositeBlock\appliesToUsertalk
appliesToUsertalk(Title $usertalk=null)
Determine whether the block allows the user to edit their own user talk page.This is done separately ...
Definition: CompositeBlock.php:194
MediaWiki\Block\CompositeBlock\getIds
getIds()
Get the IDs for the original blocks, ignoring any that are null.
Definition: CompositeBlock.php:129
MessageLocalizer\msg
msg( $key,... $params)
This is the method for getting translated interface messages.
MediaWiki\Block\CompositeBlock
Multiple Block class.
Definition: CompositeBlock.php:36
MediaWiki\Block\AbstractBlock\isEmailBlocked
isEmailBlocked( $x=null)
Get or set the flag indicating whether this block blocks the target from sending emails.
Definition: AbstractBlock.php:229
$title
$title
Definition: testCompression.php:34
MediaWiki\Block\CompositeBlock\appliesToNamespace
appliesToNamespace( $ns)
Checks if a block applies to a particular namespace.1.33bool
Definition: CompositeBlock.php:208
MediaWiki\Block\AbstractBlock\isSitewide
isSitewide( $x=null)
Indicates that the block is a sitewide block.
Definition: AbstractBlock.php:203
MediaWiki\Block\CompositeBlock\appliesToTitle
appliesToTitle(Title $title)
Checks if a block applies to a particular title.This check does not consider whether $this->isUsertal...
Definition: CompositeBlock.php:201
MediaWiki\Block\CompositeBlock\getPermissionsError
getPermissionsError(IContextSource $context)
Get the key and parameters for the corresponding error message.1.22 array
Definition: CompositeBlock.php:143
MediaWiki\Block\CompositeBlock\getOriginalBlocks
getOriginalBlocks()
Get the original blocks from which this block is composed.
Definition: CompositeBlock.php:106
MediaWiki\Block\CompositeBlock\methodReturnsValue
methodReturnsValue( $method, $value,... $params)
Determine whether any original blocks have a particular method returning a particular value.
Definition: CompositeBlock.php:91
MediaWiki\Block\AbstractBlock\getBlockErrorParams
getBlockErrorParams(IContextSource $context)
Get block information used in different block error messages.
Definition: AbstractBlock.php:534
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
Title
Represents a title within MediaWiki.
Definition: Title.php:42
MediaWiki\Block\CompositeBlock\appliesToRight
appliesToRight( $right)
Determine whether the block prevents a given right.A right may be blacklisted or whitelisted,...
Definition: CompositeBlock.php:175
MediaWiki\Block\AbstractBlock
Definition: AbstractBlock.php:34
MediaWiki\$context
IContextSource $context
Definition: MediaWiki.php:38
MediaWiki\Block\AbstractBlock\setHideName
setHideName( $hideName)
Set whether ths block hides the target's username.
Definition: AbstractBlock.php:190
MediaWiki\Block\AbstractBlock\isUsertalkEditAllowed
isUsertalkEditAllowed( $x=null)
Get or set the flag indicating whether this block blocks the target from editing their own user talk ...
Definition: AbstractBlock.php:242
MediaWiki\Block\CompositeBlock\propHasValue
propHasValue( $prop, $value)
Determine whether any original blocks have a particular property set to a particular value.
Definition: CompositeBlock.php:73
MediaWiki\Block\CompositeBlock\__construct
__construct(array $options=[])
Create a new block with specified parameters on a user, IP or IP range.
Definition: CompositeBlock.php:47