MediaWiki  master
CompositeBlock.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Block;
24 
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->isHardblock( $this->propHasValue( 'isHardblock', true ) );
60  $this->isSitewide( $this->propHasValue( 'isSitewide', true ) );
61  $this->isEmailBlocked( $this->propHasValue( 'mBlockEmail', true ) );
62  $this->isCreateAccountBlocked( $this->propHasValue( 'blockCreateAccount', true ) );
63  $this->isUsertalkEditAllowed( !$this->propHasValue( 'allowUsertalk', false ) );
64  }
65 
74  private function propHasValue( $prop, $value ) {
75  foreach ( $this->originalBlocks as $block ) {
76  if ( $block->$prop == $value ) {
77  return true;
78  }
79  }
80  return false;
81  }
82 
92  private function methodReturnsValue( $method, $value, ...$params ) {
93  foreach ( $this->originalBlocks as $block ) {
94  if ( $block->$method( ...$params ) == $value ) {
95  return true;
96  }
97  }
98  return false;
99  }
100 
107  public function getOriginalBlocks() {
108  return $this->originalBlocks;
109  }
110 
114  public function getExpiry(): string {
115  $maxExpiry = null;
116  foreach ( $this->originalBlocks as $block ) {
117  $expiry = $block->getExpiry();
118  if ( $maxExpiry === null || $expiry === '' || $expiry > $maxExpiry ) {
119  $maxExpiry = $expiry;
120  }
121  }
122  return $maxExpiry ?? '';
123  }
124 
128  public function getIdentifier() {
129  $identifier = [];
130  foreach ( $this->originalBlocks as $block ) {
131  $identifier[] = $block->getIdentifier();
132  }
133  return $identifier;
134  }
135 
146  public function appliesToRight( $right ) {
147  $isUnsure = false;
148 
149  foreach ( $this->originalBlocks as $block ) {
150  $appliesToRight = $block->appliesToRight( $right );
151 
152  if ( $appliesToRight ) {
153  return true;
154  } elseif ( $appliesToRight === null ) {
155  $isUnsure = true;
156  }
157  }
158 
159  return $isUnsure ? null : false;
160  }
161 
165  public function appliesToUsertalk( Title $usertalk = null ) {
166  return $this->methodReturnsValue( __FUNCTION__, true, $usertalk );
167  }
168 
172  public function appliesToTitle( Title $title ) {
173  return $this->methodReturnsValue( __FUNCTION__, true, $title );
174  }
175 
179  public function appliesToNamespace( $ns ) {
180  return $this->methodReturnsValue( __FUNCTION__, true, $ns );
181  }
182 
186  public function appliesToPage( $pageId ) {
187  return $this->methodReturnsValue( __FUNCTION__, true, $pageId );
188  }
189 
193  public function appliesToPasswordReset() {
194  return $this->methodReturnsValue( __FUNCTION__, true );
195  }
196 
200  public function getBy() {
201  return 0;
202  }
203 
207  public function getByName() {
208  return '';
209  }
210 
214  public function getBlocker(): ?UserIdentity {
215  return null;
216  }
217 }
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:193
MediaWiki\Block
Definition: AbstractBlock.php:21
MediaWiki\Block\CompositeBlock\getExpiry
getExpiry()
Get the block expiry time.1.19 string
Definition: CompositeBlock.php:114
MediaWiki\Block\CompositeBlock\getBy
getBy()
Get the user id of the blocking sysop.int (0 for foreign users)
Definition: CompositeBlock.php:200
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:186
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:165
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\Block\CompositeBlock
Multiple Block class.
Definition: CompositeBlock.php:36
MediaWiki\Block\Block\isSitewide
isSitewide()
Indicates that the block is a sitewide block.
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:223
$title
$title
Definition: testCompression.php:38
MediaWiki\Block\CompositeBlock\appliesToNamespace
appliesToNamespace( $ns)
Checks if a block applies to a particular namespace.1.33bool
Definition: CompositeBlock.php:179
MediaWiki\Block\CompositeBlock\getByName
getByName()
Get the username of the blocking sysop.string
Definition: CompositeBlock.php:207
MediaWiki\Block\Block\isHardblock
isHardblock()
Returns whether the block is a hardblock (affects logged-in users on a given IP/range)
MediaWiki\Block\CompositeBlock\getBlocker
getBlocker()
Get the user who applied this block.UserIdentity|null user identity or null. May be an external user.
Definition: CompositeBlock.php:214
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:172
MediaWiki\Block\CompositeBlock\getIdentifier
getIdentifier()
Get the information that identifies this block, such that a user could look up everything that can be...
Definition: CompositeBlock.php:128
MediaWiki\Block\CompositeBlock\getOriginalBlocks
getOriginalBlocks()
Get the original blocks from which this block is composed.
Definition: CompositeBlock.php:107
MediaWiki\Block\CompositeBlock\methodReturnsValue
methodReturnsValue( $method, $value,... $params)
Determine whether any original blocks have a particular method returning a particular value.
Definition: CompositeBlock.php:92
Title
Represents a title within MediaWiki.
Definition: Title.php:47
MediaWiki\Block\Block\isCreateAccountBlocked
isCreateAccountBlocked()
Get the flag indicating whether this block blocks the target from creating an account.
MediaWiki\Block\CompositeBlock\appliesToRight
appliesToRight( $right)
Determine whether the block prevents a given right.A right may be allowed or disallowed by default,...
Definition: CompositeBlock.php:146
MediaWiki\Block\AbstractBlock
Definition: AbstractBlock.php:37
MediaWiki\Block\AbstractBlock\setHideName
setHideName( $hideName)
Set whether ths block hides the target's username.
Definition: AbstractBlock.php:184
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:236
MediaWiki\Block\CompositeBlock\propHasValue
propHasValue( $prop, $value)
Determine whether any original blocks have a particular property set to a particular value.
Definition: CompositeBlock.php:74
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