MediaWiki  master
CompositeBlock.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Block;
24 
25 use Title;
26 
37  private $originalBlocks;
38 
46  public function __construct( array $options = [] ) {
47  parent::__construct( $options );
48 
49  $defaults = [
50  'originalBlocks' => [],
51  ];
52 
53  $options += $defaults;
54 
55  $this->originalBlocks = $options[ 'originalBlocks' ];
56 
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 ) );
62  }
63 
72  private function propHasValue( $prop, $value ) {
73  foreach ( $this->originalBlocks as $block ) {
74  if ( $block->$prop == $value ) {
75  return true;
76  }
77  }
78  return false;
79  }
80 
90  private function methodReturnsValue( $method, $value, ...$params ) {
91  foreach ( $this->originalBlocks as $block ) {
92  if ( $block->$method( ...$params ) == $value ) {
93  return true;
94  }
95  }
96  return false;
97  }
98 
105  public function getOriginalBlocks() {
106  return $this->originalBlocks;
107  }
108 
112  public function getExpiry() {
113  $maxExpiry = null;
114  foreach ( $this->originalBlocks as $block ) {
115  $expiry = $block->getExpiry();
116  if ( $maxExpiry === null || $expiry === '' || $expiry > $maxExpiry ) {
117  $maxExpiry = $expiry;
118  }
119  }
120  return $maxExpiry;
121  }
122 
126  public function getIdentifier() {
127  $identifier = [];
128  foreach ( $this->originalBlocks as $block ) {
129  $identifier[] = $block->getIdentifier();
130  }
131  return $identifier;
132  }
133 
144  public function appliesToRight( $right ) {
145  $isUnsure = false;
146 
147  foreach ( $this->originalBlocks as $block ) {
148  $appliesToRight = $block->appliesToRight( $right );
149 
150  if ( $appliesToRight ) {
151  return true;
152  } elseif ( $appliesToRight === null ) {
153  $isUnsure = true;
154  }
155  }
156 
157  return $isUnsure ? null : false;
158  }
159 
163  public function appliesToUsertalk( Title $usertalk = null ) {
164  return $this->methodReturnsValue( __FUNCTION__, true, $usertalk );
165  }
166 
170  public function appliesToTitle( Title $title ) {
171  return $this->methodReturnsValue( __FUNCTION__, true, $title );
172  }
173 
177  public function appliesToNamespace( $ns ) {
178  return $this->methodReturnsValue( __FUNCTION__, true, $ns );
179  }
180 
184  public function appliesToPage( $pageId ) {
185  return $this->methodReturnsValue( __FUNCTION__, true, $pageId );
186  }
187 
191  public function appliesToPasswordReset() {
192  return $this->methodReturnsValue( __FUNCTION__, true );
193  }
194 
198  public function getBy() {
199  return 0;
200  }
201 
205  public function getByName() {
206  return '';
207  }
208 }
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:191
MediaWiki\Block
Definition: AbstractBlock.php:21
MediaWiki\Block\CompositeBlock\getExpiry
getExpiry()
Get the block expiry time.1.19 string
Definition: CompositeBlock.php:112
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:226
MediaWiki\Block\CompositeBlock\getBy
getBy()
Get the user id of the blocking sysop.int (0 for foreign users)
Definition: CompositeBlock.php:198
MediaWiki\Block\CompositeBlock\$originalBlocks
AbstractBlock[] $originalBlocks
Definition: CompositeBlock.php:37
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:184
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:163
MediaWiki\Block\CompositeBlock
Multiple Block class.
Definition: CompositeBlock.php:35
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:239
$title
$title
Definition: testCompression.php:36
MediaWiki\Block\CompositeBlock\appliesToNamespace
appliesToNamespace( $ns)
Checks if a block applies to a particular namespace.1.33bool
Definition: CompositeBlock.php:177
MediaWiki\Block\AbstractBlock\isSitewide
isSitewide( $x=null)
Indicates that the block is a sitewide block.
Definition: AbstractBlock.php:213
MediaWiki\Block\CompositeBlock\getByName
getByName()
Get the username of the blocking sysop.string
Definition: CompositeBlock.php:205
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:170
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:126
MediaWiki\Block\CompositeBlock\getOriginalBlocks
getOriginalBlocks()
Get the original blocks from which this block is composed.
Definition: CompositeBlock.php:105
MediaWiki\Block\CompositeBlock\methodReturnsValue
methodReturnsValue( $method, $value,... $params)
Determine whether any original blocks have a particular method returning a particular value.
Definition: CompositeBlock.php:90
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:144
MediaWiki\Block\AbstractBlock
Definition: AbstractBlock.php:36
MediaWiki\Block\AbstractBlock\setHideName
setHideName( $hideName)
Set whether ths block hides the target's username.
Definition: AbstractBlock.php:200
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:252
MediaWiki\Block\CompositeBlock\propHasValue
propHasValue( $prop, $value)
Determine whether any original blocks have a particular property set to a particular value.
Definition: CompositeBlock.php:72
MediaWiki\Block\CompositeBlock\__construct
__construct(array $options=[])
Create a new block with specified parameters on a user, IP or IP range.
Definition: CompositeBlock.php:46