MediaWiki  master
DatabaseBlock.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Block;
24 
25 use ActorMigration;
26 use CommentStore;
27 use Hooks;
28 use Html;
34 use MWException;
35 use RequestContext;
36 use stdClass;
37 use Title;
38 use User;
39 use WebResponse;
40 use Wikimedia\IPUtils;
43 
57  public $mAuto;
58 
64 
66  private $mId;
67 
69  private $mFromMaster;
70 
72  private $forcedTargetID;
73 
75  private $isHardblock;
76 
78  private $isAutoblocking;
79 
81  private $restrictions;
82 
84  private $blocker;
85 
106  public function __construct( array $options = [] ) {
107  parent::__construct( $options );
108 
109  $defaults = [
110  'user' => null,
111  'auto' => false,
112  'expiry' => '',
113  'anonOnly' => false,
114  'createAccount' => false,
115  'enableAutoblock' => false,
116  'blockEmail' => false,
117  'allowUsertalk' => false,
118  'sitewide' => true,
119  'by' => null,
120  'byText' => '',
121  ];
122 
123  $options += $defaults;
124 
125  if ( $this->target instanceof User && $options['user'] ) {
126  # Needed for foreign users
127  $this->forcedTargetID = $options['user'];
128  }
129 
130  if ( $options['by'] ) {
131  # Local user
132  $this->setBlocker( User::newFromId( $options['by'] ) );
133  } else {
134  # Foreign user
135  $this->setBlocker( $options['byText'] );
136  }
137 
138  $this->setExpiry( wfGetDB( DB_REPLICA )->decodeExpiry( $options['expiry'] ) );
139 
140  # Boolean settings
141  $this->mAuto = (bool)$options['auto'];
142  $this->isHardblock( !$options['anonOnly'] );
143  $this->isAutoblocking( (bool)$options['enableAutoblock'] );
144  $this->isSitewide( (bool)$options['sitewide'] );
145  $this->isEmailBlocked( (bool)$options['blockEmail'] );
146  $this->isCreateAccountBlocked( (bool)$options['createAccount'] );
147  $this->isUsertalkEditAllowed( (bool)$options['allowUsertalk'] );
148 
149  $this->mFromMaster = false;
150  }
151 
158  public static function newFromID( $id ) {
159  $dbr = wfGetDB( DB_REPLICA );
160  $blockQuery = self::getQueryInfo();
161  $res = $dbr->selectRow(
162  $blockQuery['tables'],
163  $blockQuery['fields'],
164  [ 'ipb_id' => $id ],
165  __METHOD__,
166  [],
167  $blockQuery['joins']
168  );
169  if ( $res ) {
170  return self::newFromRow( $res );
171  } else {
172  return null;
173  }
174  }
175 
185  public static function getQueryInfo() {
186  $commentQuery = CommentStore::getStore()->getJoin( 'ipb_reason' );
187  $actorQuery = ActorMigration::newMigration()->getJoin( 'ipb_by' );
188  return [
189  'tables' => [ 'ipblocks' ] + $commentQuery['tables'] + $actorQuery['tables'],
190  'fields' => [
191  'ipb_id',
192  'ipb_address',
193  'ipb_timestamp',
194  'ipb_auto',
195  'ipb_anon_only',
196  'ipb_create_account',
197  'ipb_enable_autoblock',
198  'ipb_expiry',
199  'ipb_deleted',
200  'ipb_block_email',
201  'ipb_allow_usertalk',
202  'ipb_parent_block_id',
203  'ipb_sitewide',
204  ] + $commentQuery['fields'] + $actorQuery['fields'],
205  'joins' => $commentQuery['joins'] + $actorQuery['joins'],
206  ];
207  }
208 
216  public function equals( DatabaseBlock $block ) {
217  return (
218  (string)$this->target == (string)$block->target
219  && $this->type == $block->type
220  && $this->mAuto == $block->mAuto
221  && $this->isHardblock() == $block->isHardblock()
222  && $this->isCreateAccountBlocked() == $block->isCreateAccountBlocked()
223  && $this->getExpiry() == $block->getExpiry()
224  && $this->isAutoblocking() == $block->isAutoblocking()
225  && $this->getHideName() == $block->getHideName()
226  && $this->isEmailBlocked() == $block->isEmailBlocked()
227  && $this->isUsertalkEditAllowed() == $block->isUsertalkEditAllowed()
228  && $this->getReasonComment()->text == $block->getReasonComment()->text
229  && $this->isSitewide() == $block->isSitewide()
230  // DatabaseBlock::getRestrictions() may perform a database query, so
231  // keep it at the end.
232  && $this->getBlockRestrictionStore()->equals(
233  $this->getRestrictions(), $block->getRestrictions()
234  )
235  );
236  }
237 
250  protected static function newLoad(
251  $specificTarget,
252  $specificType,
253  $fromMaster,
254  $vagueTarget = null
255  ) {
256  $db = wfGetDB( $fromMaster ? DB_MASTER : DB_REPLICA );
257 
258  if ( $specificType !== null ) {
259  $conds = [ 'ipb_address' => [ (string)$specificTarget ] ];
260  } else {
261  $conds = [ 'ipb_address' => [] ];
262  }
263 
264  # Be aware that the != '' check is explicit, since empty values will be
265  # passed by some callers (T31116)
266  if ( $vagueTarget != '' ) {
267  list( $target, $type ) = self::parseTarget( $vagueTarget );
268  switch ( $type ) {
269  case self::TYPE_USER:
270  # Slightly weird, but who are we to argue?
271  $conds['ipb_address'][] = (string)$target;
272  break;
273 
274  case self::TYPE_IP:
275  $conds['ipb_address'][] = (string)$target;
276  $conds['ipb_address'] = array_unique( $conds['ipb_address'] );
277  $conds[] = self::getRangeCond( IPUtils::toHex( $target ) );
278  $conds = $db->makeList( $conds, LIST_OR );
279  break;
280 
281  case self::TYPE_RANGE:
282  list( $start, $end ) = IPUtils::parseRange( $target );
283  $conds['ipb_address'][] = (string)$target;
284  $conds[] = self::getRangeCond( $start, $end );
285  $conds = $db->makeList( $conds, LIST_OR );
286  break;
287 
288  default:
289  throw new MWException( "Tried to load block with invalid type" );
290  }
291  }
292 
293  $blockQuery = self::getQueryInfo();
294  $res = $db->select(
295  $blockQuery['tables'],
296  $blockQuery['fields'],
297  $conds,
298  __METHOD__,
299  [],
300  $blockQuery['joins']
301  );
302 
303  $blocks = [];
304  $blockIds = [];
305  $autoBlocks = [];
306  foreach ( $res as $row ) {
307  $block = self::newFromRow( $row );
308 
309  # Don't use expired blocks
310  if ( $block->isExpired() ) {
311  continue;
312  }
313 
314  # Don't use anon only blocks on users
315  if ( $specificType == self::TYPE_USER && !$block->isHardblock() ) {
316  continue;
317  }
318 
319  // Check for duplicate autoblocks
320  if ( $block->getType() === self::TYPE_AUTO ) {
321  $autoBlocks[] = $block;
322  } else {
323  $blocks[] = $block;
324  $blockIds[] = $block->getId();
325  }
326  }
327 
328  // Only add autoblocks that aren't duplicates
329  foreach ( $autoBlocks as $block ) {
330  if ( !in_array( $block->mParentBlockId, $blockIds ) ) {
331  $blocks[] = $block;
332  }
333  }
334 
335  return $blocks;
336  }
337 
350  protected static function chooseMostSpecificBlock( array $blocks ) {
351  if ( count( $blocks ) === 1 ) {
352  return $blocks[0];
353  }
354 
355  # This result could contain a block on the user, a block on the IP, and a russian-doll
356  # set of rangeblocks. We want to choose the most specific one, so keep a leader board.
357  $bestBlock = null;
358 
359  # Lower will be better
360  $bestBlockScore = 100;
361  foreach ( $blocks as $block ) {
362  if ( $block->getType() == self::TYPE_RANGE ) {
363  # This is the number of bits that are allowed to vary in the block, give
364  # or take some floating point errors
365  $target = $block->getTarget();
366  $max = IPUtils::isIPv6( $target ) ? 128 : 32;
367  list( $network, $bits ) = IPUtils::parseCIDR( $target );
368  $size = $max - $bits;
369 
370  # Rank a range block covering a single IP equally with a single-IP block
371  $score = self::TYPE_RANGE - 1 + ( $size / $max );
372 
373  } else {
374  $score = $block->getType();
375  }
376 
377  if ( $score < $bestBlockScore ) {
378  $bestBlockScore = $score;
379  $bestBlock = $block;
380  }
381  }
382 
383  return $bestBlock;
384  }
385 
392  public static function getRangeCond( $start, $end = null ) {
393  if ( $end === null ) {
394  $end = $start;
395  }
396  # Per T16634, we want to include relevant active rangeblocks; for
397  # rangeblocks, we want to include larger ranges which enclose the given
398  # range. We know that all blocks must be smaller than $wgBlockCIDRLimit,
399  # so we can improve performance by filtering on a LIKE clause
400  $chunk = self::getIpFragment( $start );
401  $dbr = wfGetDB( DB_REPLICA );
402  $like = $dbr->buildLike( $chunk, $dbr->anyString() );
403 
404  # Fairly hard to make a malicious SQL statement out of hex characters,
405  # but stranger things have happened...
406  $safeStart = $dbr->addQuotes( $start );
407  $safeEnd = $dbr->addQuotes( $end );
408 
409  return $dbr->makeList(
410  [
411  "ipb_range_start $like",
412  "ipb_range_start <= $safeStart",
413  "ipb_range_end >= $safeEnd",
414  ],
415  LIST_AND
416  );
417  }
418 
425  protected static function getIpFragment( $hex ) {
426  global $wgBlockCIDRLimit;
427  if ( substr( $hex, 0, 3 ) == 'v6-' ) {
428  return 'v6-' . substr( substr( $hex, 3 ), 0, floor( $wgBlockCIDRLimit['IPv6'] / 4 ) );
429  } else {
430  return substr( $hex, 0, floor( $wgBlockCIDRLimit['IPv4'] / 4 ) );
431  }
432  }
433 
439  protected function initFromRow( $row ) {
440  $this->setTarget( $row->ipb_address );
441 
442  $this->setTimestamp( wfTimestamp( TS_MW, $row->ipb_timestamp ) );
443  $this->mAuto = (bool)$row->ipb_auto;
444  $this->setHideName( (bool)$row->ipb_deleted );
445  $this->mId = (int)$row->ipb_id;
446  $this->mParentBlockId = (int)$row->ipb_parent_block_id;
447 
449  $row->ipb_by, $row->ipb_by_text, $row->ipb_by_actor ?? null
450  ) );
451 
452  // I wish I didn't have to do this
453  $db = wfGetDB( DB_REPLICA );
454  $this->setExpiry( $db->decodeExpiry( $row->ipb_expiry ) );
455  $this->setReason(
457  // Legacy because $row may have come from self::selectFields()
458  ->getCommentLegacy( $db, 'ipb_reason', $row )
459  );
460 
461  $this->isHardblock( !$row->ipb_anon_only );
462  $this->isAutoblocking( (bool)$row->ipb_enable_autoblock );
463  $this->isSitewide( (bool)$row->ipb_sitewide );
464 
465  $this->isCreateAccountBlocked( (bool)$row->ipb_create_account );
466  $this->isEmailBlocked( (bool)$row->ipb_block_email );
467  $this->isUsertalkEditAllowed( (bool)$row->ipb_allow_usertalk );
468  }
469 
475  public static function newFromRow( $row ) {
476  $block = new DatabaseBlock;
477  $block->initFromRow( $row );
478  return $block;
479  }
480 
488  public function delete() {
490  ->getDatabaseBlockStore()
491  ->deleteBlock( $this );
492  }
493 
503  public function insert( IDatabase $dbw = null ) {
505  ->getDatabaseBlockStore()
506  ->insertBlock( $this, $dbw );
507  }
508 
517  public function update() {
519  ->getDatabaseBlockStore()
520  ->updateBlock( $this );
521  }
522 
530  public static function isWhitelistedFromAutoblocks( $ip ) {
531  // Try to get the autoblock_whitelist from the cache, as it's faster
532  // than getting the msg raw and explode()'ing it.
533  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
534  $lines = $cache->getWithSetCallback(
535  $cache->makeKey( 'ip-autoblock', 'whitelist' ),
536  $cache::TTL_DAY,
537  function ( $curValue, &$ttl, array &$setOpts ) {
539 
540  return explode( "\n",
541  wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
542  }
543  );
544 
545  wfDebug( "Checking the autoblock whitelist.." );
546 
547  foreach ( $lines as $line ) {
548  # List items only
549  if ( substr( $line, 0, 1 ) !== '*' ) {
550  continue;
551  }
552 
553  $wlEntry = substr( $line, 1 );
554  $wlEntry = trim( $wlEntry );
555 
556  wfDebug( "Checking $ip against $wlEntry..." );
557 
558  # Is the IP in this range?
559  if ( IPUtils::isInRange( $ip, $wlEntry ) ) {
560  wfDebug( " IP $ip matches $wlEntry, not autoblocking" );
561  return true;
562  } else {
563  wfDebug( " No match" );
564  }
565  }
566 
567  return false;
568  }
569 
576  public function doAutoblock( $autoblockIP ) {
577  # If autoblocks are disabled, go away.
578  if ( !$this->isAutoblocking() ) {
579  return false;
580  }
581 
582  # Check for presence on the autoblock whitelist.
583  if ( self::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
584  return false;
585  }
586 
587  # Allow hooks to cancel the autoblock.
588  if ( !Hooks::runner()->onAbortAutoblock( $autoblockIP, $this ) ) {
589  wfDebug( "Autoblock aborted by hook." );
590  return false;
591  }
592 
593  # It's okay to autoblock. Go ahead and insert/update the block...
594 
595  # Do not add a *new* block if the IP is already blocked.
596  $ipblock = self::newFromTarget( $autoblockIP );
597  if ( $ipblock ) {
598  # Check if the block is an autoblock and would exceed the user block
599  # if renewed. If so, do nothing, otherwise prolong the block time...
600  if ( $ipblock->mAuto && // @todo Why not compare $ipblock->mExpiry?
601  $this->getExpiry() > self::getAutoblockExpiry( $ipblock->getTimestamp() )
602  ) {
603  # Reset block timestamp to now and its expiry to
604  # $wgAutoblockExpiry in the future
605  $ipblock->updateTimestamp();
606  }
607  return false;
608  }
609 
610  # Make a new block object with the desired properties.
611  $autoblock = new DatabaseBlock;
612  wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP );
613  $autoblock->setTarget( $autoblockIP );
614  $autoblock->setBlocker( $this->getBlocker() );
615  $autoblock->setReason(
616  wfMessage(
617  'autoblocker',
618  (string)$this->getTarget(),
619  $this->getReasonComment()->text
620  )->inContentLanguage()->plain()
621  );
622  $timestamp = wfTimestampNow();
623  $autoblock->setTimestamp( $timestamp );
624  $autoblock->mAuto = true;
625  $autoblock->isCreateAccountBlocked( $this->isCreateAccountBlocked() );
626  # Continue suppressing the name if needed
627  $autoblock->setHideName( $this->getHideName() );
628  $autoblock->isUsertalkEditAllowed( $this->isUsertalkEditAllowed() );
629  $autoblock->mParentBlockId = $this->mId;
630  $autoblock->isSitewide( $this->isSitewide() );
631  $autoblock->setRestrictions( $this->getRestrictions() );
632 
633  if ( $this->getExpiry() == 'infinity' ) {
634  # Original block was indefinite, start an autoblock now
635  $autoblock->setExpiry( self::getAutoblockExpiry( $timestamp ) );
636  } else {
637  # If the user is already blocked with an expiry date, we don't
638  # want to pile on top of that.
639  $autoblock->setExpiry( min( $this->getExpiry(), self::getAutoblockExpiry( $timestamp ) ) );
640  }
641 
642  # Insert the block...
643  $status = MediaWikiServices::getInstance()->getDatabaseBlockStore()->insertBlock(
644  $autoblock
645  );
646  return $status
647  ? $status['id']
648  : false;
649  }
650 
657  public function deleteIfExpired() {
658  wfDeprecated( __METHOD__, '1.35' );
659  if ( $this->isExpired() ) {
660  wfDebug( __METHOD__ . " -- deleting" );
661  $this->delete();
662  $retVal = true;
663  } else {
664  wfDebug( __METHOD__ . " -- not expired" );
665  $retVal = false;
666  }
667 
668  return $retVal;
669  }
670 
675  public function isExpired() {
676  $timestamp = wfTimestampNow();
677  wfDebug( __METHOD__ . " checking current " . $timestamp . " vs $this->mExpiry" );
678 
679  if ( !$this->getExpiry() ) {
680  return false;
681  } else {
682  return $timestamp > $this->getExpiry();
683  }
684  }
685 
689  public function updateTimestamp() {
690  if ( $this->mAuto ) {
691  $this->setTimestamp( wfTimestamp() );
692  $this->setExpiry( self::getAutoblockExpiry( $this->getTimestamp() ) );
693 
694  $dbw = wfGetDB( DB_MASTER );
695  $dbw->update( 'ipblocks',
696  [ /* SET */
697  'ipb_timestamp' => $dbw->timestamp( $this->getTimestamp() ),
698  'ipb_expiry' => $dbw->timestamp( $this->getExpiry() ),
699  ],
700  [ /* WHERE */
701  'ipb_id' => $this->getId(),
702  ],
703  __METHOD__
704  );
705  }
706  }
707 
713  public function getRangeStart() {
714  switch ( $this->type ) {
715  case self::TYPE_USER:
716  return '';
717  case self::TYPE_IP:
718  return IPUtils::toHex( $this->target );
719  case self::TYPE_RANGE:
720  list( $start, /*...*/ ) = IPUtils::parseRange( $this->target );
721  return $start;
722  default:
723  throw new MWException( "Block with invalid type" );
724  }
725  }
726 
732  public function getRangeEnd() {
733  switch ( $this->type ) {
734  case self::TYPE_USER:
735  return '';
736  case self::TYPE_IP:
737  return IPUtils::toHex( $this->target );
738  case self::TYPE_RANGE:
739  list( /*...*/, $end ) = IPUtils::parseRange( $this->target );
740  return $end;
741  default:
742  throw new MWException( "Block with invalid type" );
743  }
744  }
745 
750  public function getReason() {
751  if ( $this->getType() === self::TYPE_AUTO ) {
752  return $this->reason->message->inContentLanguage()->plain();
753  }
754  return $this->reason->text;
755  }
756 
760  public function getId() {
761  return $this->mId;
762  }
763 
771  public function setId( $blockId ) {
772  $this->mId = (int)$blockId;
773 
774  if ( is_array( $this->restrictions ) ) {
775  $this->restrictions = $this->getBlockRestrictionStore()->setBlockId(
776  $blockId, $this->restrictions
777  );
778  }
779 
780  return $this;
781  }
782 
787  public function getParentBlockId() {
788  return $this->mParentBlockId;
789  }
790 
798  public function fromMaster( $x = null ) {
799  wfDeprecated( __METHOD__, '1.35' );
800  return wfSetVar( $this->mFromMaster, $x );
801  }
802 
808  public function isHardblock( $x = null ) {
809  wfSetVar( $this->isHardblock, $x );
810 
811  # You can't *not* hardblock a user
812  return $this->getType() == self::TYPE_USER
813  ? true
815  }
816 
821  public function isAutoblocking( $x = null ) {
822  wfSetVar( $this->isAutoblocking, $x );
823 
824  # You can't put an autoblock on an IP or range as we don't have any history to
825  # look over to get more IPs from
826  return $this->getType() == self::TYPE_USER
827  ? $this->isAutoblocking
828  : false;
829  }
830 
835  public function getRedactedName() {
836  if ( $this->mAuto ) {
837  return Html::element(
838  'span',
839  [ 'class' => 'mw-autoblockid' ],
840  wfMessage( 'autoblockid', $this->mId )->text()
841  );
842  } else {
843  return htmlspecialchars( $this->getTarget() );
844  }
845  }
846 
853  public static function getAutoblockExpiry( $timestamp ) {
854  global $wgAutoblockExpiry;
855 
856  return wfTimestamp( TS_MW, (int)wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
857  }
858 
864  public static function purgeExpired() {
865  MediaWikiServices::getInstance()->getDatabaseBlockStore()->purgeExpiredBlocks();
866  }
867 
888  public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
889  $blocks = self::newListFromTarget( $specificTarget, $vagueTarget, $fromMaster );
890  return self::chooseMostSpecificBlock( $blocks );
891  }
892 
902  public static function newListFromTarget(
903  $specificTarget,
904  $vagueTarget = null,
905  $fromMaster = false
906  ) {
907  list( $target, $type ) = self::parseTarget( $specificTarget );
908  if ( $type == self::TYPE_ID || $type == self::TYPE_AUTO ) {
909  $block = self::newFromID( $target );
910  return $block ? [ $block ] : [];
911  } elseif ( $target === null && $vagueTarget == '' ) {
912  # We're not going to find anything useful here
913  # Be aware that the == '' check is explicit, since empty values will be
914  # passed by some callers (T31116)
915  return [];
916  } elseif ( in_array(
917  $type,
918  [ self::TYPE_USER, self::TYPE_IP, self::TYPE_RANGE, null ] )
919  ) {
920  return self::newLoad( $target, $type, $fromMaster, $vagueTarget );
921  }
922  return [];
923  }
924 
935  public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
936  if ( $ipChain === [] ) {
937  return [];
938  }
939 
940  $conds = [];
941  $proxyLookup = MediaWikiServices::getInstance()->getProxyLookup();
942  foreach ( array_unique( $ipChain ) as $ipaddr ) {
943  # Discard invalid IP addresses. Since XFF can be spoofed and we do not
944  # necessarily trust the header given to us, make sure that we are only
945  # checking for blocks on well-formatted IP addresses (IPv4 and IPv6).
946  # Do not treat private IP spaces as special as it may be desirable for wikis
947  # to block those IP ranges in order to stop misbehaving proxies that spoof XFF.
948  if ( !IPUtils::isValid( $ipaddr ) ) {
949  continue;
950  }
951  # Don't check trusted IPs (includes local CDNs which will be in every request)
952  if ( $proxyLookup->isTrustedProxy( $ipaddr ) ) {
953  continue;
954  }
955  # Check both the original IP (to check against single blocks), as well as build
956  # the clause to check for rangeblocks for the given IP.
957  $conds['ipb_address'][] = $ipaddr;
958  $conds[] = self::getRangeCond( IPUtils::toHex( $ipaddr ) );
959  }
960 
961  if ( $conds === [] ) {
962  return [];
963  }
964 
965  if ( $fromMaster ) {
966  $db = wfGetDB( DB_MASTER );
967  } else {
968  $db = wfGetDB( DB_REPLICA );
969  }
970  $conds = $db->makeList( $conds, LIST_OR );
971  if ( !$isAnon ) {
972  $conds = [ $conds, 'ipb_anon_only' => 0 ];
973  }
974  $blockQuery = self::getQueryInfo();
975  $rows = $db->select(
976  $blockQuery['tables'],
977  array_merge( [ 'ipb_range_start', 'ipb_range_end' ], $blockQuery['fields'] ),
978  $conds,
979  __METHOD__,
980  [],
981  $blockQuery['joins']
982  );
983 
984  $blocks = [];
985  foreach ( $rows as $row ) {
986  $block = self::newFromRow( $row );
987  if ( !$block->isExpired() ) {
988  $blocks[] = $block;
989  }
990  }
991 
992  return $blocks;
993  }
994 
1018  public static function chooseBlock( array $blocks, array $ipChain ) {
1019  wfDeprecated( __METHOD__, '1.35' );
1020  if ( $blocks === [] ) {
1021  return null;
1022  } elseif ( count( $blocks ) == 1 ) {
1023  return $blocks[0];
1024  }
1025 
1026  // Sort hard blocks before soft ones and secondarily sort blocks
1027  // that disable account creation before those that don't.
1028  usort( $blocks, function ( DatabaseBlock $a, DatabaseBlock $b ) {
1029  $aWeight = (int)$a->isHardblock() . (int)$a->appliesToRight( 'createaccount' );
1030  $bWeight = (int)$b->isHardblock() . (int)$b->appliesToRight( 'createaccount' );
1031  return strcmp( $bWeight, $aWeight ); // highest weight first
1032  } );
1033 
1034  $blocksListExact = [
1035  'hard' => false,
1036  'disable_create' => false,
1037  'other' => false,
1038  'auto' => false
1039  ];
1040  $blocksListRange = [
1041  'hard' => false,
1042  'disable_create' => false,
1043  'other' => false,
1044  'auto' => false
1045  ];
1046  $ipChain = array_reverse( $ipChain );
1047 
1048  foreach ( $blocks as $block ) {
1049  // Stop searching if we have already have a "better" block. This
1050  // is why the order of the blocks matters
1051  if ( !$block->isHardblock() && $blocksListExact['hard'] ) {
1052  break;
1053  } elseif ( !$block->appliesToRight( 'createaccount' ) && $blocksListExact['disable_create'] ) {
1054  break;
1055  }
1056 
1057  foreach ( $ipChain as $checkip ) {
1058  $checkipHex = IPUtils::toHex( $checkip );
1059  if ( (string)$block->getTarget() === $checkip ) {
1060  if ( $block->isHardblock() ) {
1061  $blocksListExact['hard'] = $blocksListExact['hard'] ?: $block;
1062  } elseif ( $block->appliesToRight( 'createaccount' ) ) {
1063  $blocksListExact['disable_create'] = $blocksListExact['disable_create'] ?: $block;
1064  } elseif ( $block->mAuto ) {
1065  $blocksListExact['auto'] = $blocksListExact['auto'] ?: $block;
1066  } else {
1067  $blocksListExact['other'] = $blocksListExact['other'] ?: $block;
1068  }
1069  // We found closest exact match in the ip list, so go to the next block
1070  break;
1071  } elseif ( array_filter( $blocksListExact ) == []
1072  && $block->getRangeStart() <= $checkipHex
1073  && $block->getRangeEnd() >= $checkipHex
1074  ) {
1075  if ( $block->isHardblock() ) {
1076  $blocksListRange['hard'] = $blocksListRange['hard'] ?: $block;
1077  } elseif ( $block->appliesToRight( 'createaccount' ) ) {
1078  $blocksListRange['disable_create'] = $blocksListRange['disable_create'] ?: $block;
1079  } elseif ( $block->mAuto ) {
1080  $blocksListRange['auto'] = $blocksListRange['auto'] ?: $block;
1081  } else {
1082  $blocksListRange['other'] = $blocksListRange['other'] ?: $block;
1083  }
1084  break;
1085  }
1086  }
1087  }
1088 
1089  if ( array_filter( $blocksListExact ) == [] ) {
1090  $blocksList = &$blocksListRange;
1091  } else {
1092  $blocksList = &$blocksListExact;
1093  }
1094 
1095  $chosenBlock = null;
1096  if ( $blocksList['hard'] ) {
1097  $chosenBlock = $blocksList['hard'];
1098  } elseif ( $blocksList['disable_create'] ) {
1099  $chosenBlock = $blocksList['disable_create'];
1100  } elseif ( $blocksList['other'] ) {
1101  $chosenBlock = $blocksList['other'];
1102  } elseif ( $blocksList['auto'] ) {
1103  $chosenBlock = $blocksList['auto'];
1104  } else {
1105  throw new MWException( "Proxy block found, but couldn't be classified." );
1106  }
1107 
1108  return $chosenBlock;
1109  }
1110 
1117  public function getType() {
1118  return $this->mAuto
1119  ? self::TYPE_AUTO
1120  : parent::getType();
1121  }
1122 
1131  public function setCookie( WebResponse $response ) {
1132  wfDeprecated( __METHOD__, '1.34' );
1133  MediaWikiServices::getInstance()->getBlockManager()->setBlockCookie( $this, $response );
1134  }
1135 
1143  public static function clearCookie( WebResponse $response ) {
1144  wfDeprecated( __METHOD__, '1.34' );
1145  MediaWikiServices::getInstance()->getBlockManager()->clearBlockCookie( $response );
1146  }
1147 
1158  public function getCookieValue() {
1159  wfDeprecated( __METHOD__, '1.34' );
1160  return MediaWikiServices::getInstance()->getBlockManager()->getCookieValue( $this );
1161  }
1162 
1172  public static function getIdFromCookieValue( $cookieValue ) {
1173  wfDeprecated( __METHOD__, '1.34' );
1174  return MediaWikiServices::getInstance()->getBlockManager()->getIdFromCookieValue( $cookieValue );
1175  }
1176 
1180  public function getIdentifier() {
1181  return $this->getId();
1182  }
1183 
1193  public function getRestrictions() {
1194  if ( $this->restrictions === null ) {
1195  // If the block id has not been set, then do not attempt to load the
1196  // restrictions.
1197  if ( !$this->mId ) {
1198  return [];
1199  }
1200  $this->restrictions = $this->getBlockRestrictionStore()->loadByBlockId( $this->mId );
1201  }
1202 
1203  return $this->restrictions;
1204  }
1205 
1212  public function getRawRestrictions() : ?array {
1213  return $this->restrictions;
1214  }
1215 
1223  public function setRestrictions( array $restrictions ) {
1224  $this->restrictions = array_filter( $restrictions, function ( $restriction ) {
1225  return $restriction instanceof Restriction;
1226  } );
1227 
1228  return $this;
1229  }
1230 
1234  public function appliesToTitle( Title $title ) {
1235  if ( $this->isSitewide() ) {
1236  return true;
1237  }
1238 
1239  $restrictions = $this->getRestrictions();
1240  foreach ( $restrictions as $restriction ) {
1241  if ( $restriction->matches( $title ) ) {
1242  return true;
1243  }
1244  }
1245 
1246  return false;
1247  }
1248 
1252  public function appliesToNamespace( $ns ) {
1253  if ( $this->isSitewide() ) {
1254  return true;
1255  }
1256 
1257  // Blocks do not apply to virtual namespaces.
1258  if ( $ns < 0 ) {
1259  return false;
1260  }
1261 
1262  $restriction = $this->findRestriction( NamespaceRestriction::TYPE, $ns );
1263 
1264  return (bool)$restriction;
1265  }
1266 
1270  public function appliesToPage( $pageId ) {
1271  if ( $this->isSitewide() ) {
1272  return true;
1273  }
1274 
1275  // If the pageId is not over zero, the block cannot apply to it.
1276  if ( $pageId <= 0 ) {
1277  return false;
1278  }
1279 
1280  $restriction = $this->findRestriction( PageRestriction::TYPE, $pageId );
1281 
1282  return (bool)$restriction;
1283  }
1284 
1292  private function findRestriction( $type, $value ) {
1293  $restrictions = $this->getRestrictions();
1294  foreach ( $restrictions as $restriction ) {
1295  if ( $restriction->getType() !== $type ) {
1296  continue;
1297  }
1298 
1299  if ( $restriction->getValue() === $value ) {
1300  return $restriction;
1301  }
1302  }
1303 
1304  return null;
1305  }
1306 
1312  public function shouldTrackWithCookie( $isAnon ) {
1313  wfDeprecated( __METHOD__, '1.34' );
1314  $config = RequestContext::getMain()->getConfig();
1315  switch ( $this->getType() ) {
1316  case self::TYPE_IP:
1317  case self::TYPE_RANGE:
1318  return $isAnon && $config->get( 'CookieSetOnIpBlock' );
1319  case self::TYPE_USER:
1320  return !$isAnon && $config->get( 'CookieSetOnAutoblock' ) && $this->isAutoblocking();
1321  default:
1322  return false;
1323  }
1324  }
1325 
1332  return MediaWikiServices::getInstance()->getBlockRestrictionStore();
1333  }
1334 
1338  public function getBy() {
1339  return ( $this->blocker ) ? $this->blocker->getId() : 0;
1340  }
1341 
1345  public function getByName() {
1346  return ( $this->blocker ) ? $this->blocker->getName() : '';
1347  }
1348 
1354  public function getBlocker() {
1355  return $this->blocker;
1356  }
1357 
1364  public function getForcedTargetID() : ?int {
1365  return $this->forcedTargetID;
1366  }
1367 
1373  public function setBlocker( $user ) {
1374  if ( is_string( $user ) ) {
1375  $user = User::newFromName( $user, false );
1376  }
1377 
1378  if ( $user->isAnon() &&
1379  MediaWikiServices::getInstance()->getUserNameUtils()->isUsable( $user->getName() )
1380  ) {
1381  // Temporarily log some block details to debug T192964
1382  $logger = LoggerFactory::getInstance( 'BlockManager' );
1383  $logger->warning(
1384  'Blocker is neither a local user nor an invalid username',
1385  [
1386  'blocker' => (string)$user,
1387  'blockId' => $this->getId(),
1388  ]
1389  );
1390  throw new \InvalidArgumentException(
1391  'Blocker must be a local user or a name that cannot be a local user'
1392  );
1393  }
1394 
1395  $this->blocker = $user;
1396  }
1397 }
1398 
1402 class_alias( DatabaseBlock::class, 'Block' );
MediaWiki\Block\DatabaseBlock\setBlocker
setBlocker( $user)
Set the user who implemented (or will implement) this block.
Definition: DatabaseBlock.php:1373
MediaWiki\Block\DatabaseBlock\getIpFragment
static getIpFragment( $hex)
Get the component of an IP address which is certain to be the same between an IP address and a rangeb...
Definition: DatabaseBlock.php:425
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:50
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:579
MediaWiki\Block\DatabaseBlock\setCookie
setCookie(WebResponse $response)
Set the 'BlockID' cookie to this block's ID and expiry time.
Definition: DatabaseBlock.php:1131
MediaWiki\Block\AbstractBlock\$target
User string null $target
Definition: AbstractBlock.php:76
MediaWiki\Block\DatabaseBlock\equals
equals(DatabaseBlock $block)
Check if two blocks are effectively equal.
Definition: DatabaseBlock.php:216
MediaWiki\Block
Definition: AbstractBlock.php:21
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:160
MediaWiki\Block\DatabaseBlock\getCookieValue
getCookieValue()
Get the BlockID cookie's value for this block.
Definition: DatabaseBlock.php:1158
MediaWiki\Block\DatabaseBlock\chooseBlock
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest block.
Definition: DatabaseBlock.php:1018
MediaWiki\Block\DatabaseBlock\initFromRow
initFromRow( $row)
Given a database row from the ipblocks table, initialize member variables.
Definition: DatabaseBlock.php:439
wfSetVar
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
Definition: GlobalFunctions.php:1550
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
MediaWiki\Block\DatabaseBlock\getRangeStart
getRangeStart()
Get the IP address at the start of the range in Hex form.
Definition: DatabaseBlock.php:713
MediaWiki\Block\DatabaseBlock\$mParentBlockId
int $mParentBlockId
Definition: DatabaseBlock.php:63
true
return true
Definition: router.php:90
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1815
$wgAutoblockExpiry
$wgAutoblockExpiry
Number of seconds before autoblock entries expire.
Definition: DefaultSettings.php:5404
MediaWiki\Block\DatabaseBlock\shouldTrackWithCookie
shouldTrackWithCookie( $isAnon)
Definition: DatabaseBlock.php:1312
MediaWiki\Block\DatabaseBlock\getType
getType()
Get the type of target for this particular block.int|null AbstractBlock::TYPE_ constant,...
Definition: DatabaseBlock.php:1117
MediaWiki\Block\Restriction\NamespaceRestriction\TYPE
const TYPE
Definition: NamespaceRestriction.php:30
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:229
MediaWiki\Block\DatabaseBlock\getBlocker
getBlocker()
Get the user who implemented this block.
Definition: DatabaseBlock.php:1354
MediaWiki\Block\DatabaseBlock\__construct
__construct(array $options=[])
Create a new block with specified option parameters on a user, IP or IP range.
Definition: DatabaseBlock.php:106
MediaWiki\Block\AbstractBlock\TYPE_AUTO
const TYPE_AUTO
Definition: AbstractBlock.php:92
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:542
MediaWiki\Block\DatabaseBlock\appliesToNamespace
appliesToNamespace( $ns)
Checks if a block applies to a particular namespace.1.33bool
Definition: DatabaseBlock.php:1252
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1220
MediaWiki\Block\DatabaseBlock\getByName
getByName()
Get the username of the blocking sysop.string
Definition: DatabaseBlock.php:1345
ActorMigration
This class handles the logic for the actor table migration and should always be used in lieu of direc...
Definition: ActorMigration.php:39
$res
$res
Definition: testCompression.php:57
MediaWiki\Block\DatabaseBlock\getRawRestrictions
getRawRestrictions()
Get restrictions without loading from database if not yet loaded.
Definition: DatabaseBlock.php:1212
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:140
LIST_AND
const LIST_AND
Definition: Defines.php:48
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:54
MediaWiki\Block\DatabaseBlock\deleteIfExpired
deleteIfExpired()
Check if a block has expired.
Definition: DatabaseBlock.php:657
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:192
MediaWiki\Block\AbstractBlock\TYPE_RANGE
const TYPE_RANGE
Definition: AbstractBlock.php:91
MediaWiki\Block\DatabaseBlock\appliesToPage
appliesToPage( $pageId)
Checks if a block applies to a particular page.This check does not consider whether $this->isUsertalk...
Definition: DatabaseBlock.php:1270
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:52
MediaWiki\Block\DatabaseBlock\setRestrictions
setRestrictions(array $restrictions)
Set Restrictions.
Definition: DatabaseBlock.php:1223
LIST_OR
const LIST_OR
Definition: Defines.php:51
MediaWiki\Block\DatabaseBlock\getForcedTargetID
getForcedTargetID()
Get the forcedTargetID if set.
Definition: DatabaseBlock.php:1364
MWException
MediaWiki exception.
Definition: MWException.php:29
MediaWiki\Block\DatabaseBlock\getBlocksForIPList
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
Definition: DatabaseBlock.php:935
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1027
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
MediaWiki\Block\DatabaseBlock\$blocker
User $blocker
Definition: DatabaseBlock.php:84
Wikimedia\Rdbms\Database\getCacheSetOptions
static getCacheSetOptions(IDatabase $db1, IDatabase $db2=null)
Merge the result of getSessionLagStatus() for several DBs using the most pessimistic values to estima...
Definition: Database.php:4923
MediaWiki\Block\DatabaseBlock\$mFromMaster
bool $mFromMaster
Definition: DatabaseBlock.php:69
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
MediaWiki\Block\DatabaseBlock\purgeExpired
static purgeExpired()
Purge expired blocks from the ipblocks table.
Definition: DatabaseBlock.php:864
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2475
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:242
MediaWiki\Block\DatabaseBlock\newFromRow
static newFromRow( $row)
Create a new DatabaseBlock object from a database row.
Definition: DatabaseBlock.php:475
MediaWiki\Block\Restriction\Restriction
Definition: Restriction.php:25
MediaWiki\Block\AbstractBlock\getReasonComment
getReasonComment()
Get the reason for creating the block.
Definition: AbstractBlock.php:173
MediaWiki\Block\DatabaseBlock\$forcedTargetID
int $forcedTargetID
Hack for foreign blocking (CentralAuth)
Definition: DatabaseBlock.php:72
MediaWiki\Block\Restriction\PageRestriction\TYPE
const TYPE
Definition: PageRestriction.php:30
MediaWiki\Block\DatabaseBlock\isWhitelistedFromAutoblocks
static isWhitelistedFromAutoblocks( $ip)
Checks whether a given IP is on the autoblock whitelist.
Definition: DatabaseBlock.php:530
MediaWiki\Block\AbstractBlock\TYPE_IP
const TYPE_IP
Definition: AbstractBlock.php:90
MediaWiki\Block\DatabaseBlock\getRangeEnd
getRangeEnd()
Get the IP address at the end of the range in Hex form.
Definition: DatabaseBlock.php:732
$title
$title
Definition: testCompression.php:38
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1844
RequestContext
Group all the pieces relevant to the context of a request into one instance @newable.
Definition: RequestContext.php:39
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:630
MediaWiki\Block\DatabaseBlock\isExpired
isExpired()
Has the block expired?
Definition: DatabaseBlock.php:675
MediaWiki\Block\AbstractBlock\isSitewide
isSitewide( $x=null)
Indicates that the block is a sitewide block.
Definition: AbstractBlock.php:216
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWiki\Block\DatabaseBlock\getIdFromCookieValue
static getIdFromCookieValue( $cookieValue)
Get the stored ID from the 'BlockID' cookie.
Definition: DatabaseBlock.php:1172
MediaWiki\Block\DatabaseBlock\fromMaster
fromMaster( $x=null)
Get/set a flag determining whether the master is used for reads.
Definition: DatabaseBlock.php:798
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:910
MediaWiki\Block\DatabaseBlock\getRangeCond
static getRangeCond( $start, $end=null)
Get a set of SQL conditions which will select rangeblocks encompassing a given range.
Definition: DatabaseBlock.php:392
MediaWiki\Block\DatabaseBlock\getBlockRestrictionStore
getBlockRestrictionStore()
Get a BlockRestrictionStore instance.
Definition: DatabaseBlock.php:1331
MediaWiki\Block\DatabaseBlock\getRedactedName
getRedactedName()
Get the block name, but with autoblocked IPs hidden as per standard privacy policy.
Definition: DatabaseBlock.php:835
MediaWiki\Block\DatabaseBlock\isAutoblocking
isAutoblocking( $x=null)
Definition: DatabaseBlock.php:821
MediaWiki\Block\AbstractBlock\setTimestamp
setTimestamp( $timestamp)
Set the timestamp indicating when the block was created.
Definition: AbstractBlock.php:500
MediaWiki\Block\DatabaseBlock\getBy
getBy()
Get the user id of the blocking sysop.int (0 for foreign users)
Definition: DatabaseBlock.php:1338
MediaWiki\Block\AbstractBlock\parseTarget
static parseTarget( $target)
From an existing block, get the target and the type of target.
Definition: AbstractBlock.php:381
MediaWiki\Block\AbstractBlock\TYPE_USER
const TYPE_USER
Definition: AbstractBlock.php:89
MediaWiki\Block\DatabaseBlock\getIdentifier
getIdentifier()
Get the information that identifies this block, such that a user could look up everything that can be...
Definition: DatabaseBlock.php:1180
MediaWiki\Block\DatabaseBlock\getParentBlockId
getParentBlockId()
Definition: DatabaseBlock.php:787
MediaWiki\Block\DatabaseBlock\$isAutoblocking
bool $isAutoblocking
Definition: DatabaseBlock.php:78
MediaWiki\Block\DatabaseBlock\newLoad
static newLoad( $specificTarget, $specificType, $fromMaster, $vagueTarget=null)
Load blocks from the database which target the specific target exactly, or which cover the vague targ...
Definition: DatabaseBlock.php:250
MediaWiki\Block\DatabaseBlock\getReason
getReason()
Get the reason given for creating the block, as a string.Deprecated, since this gives the caller no c...
Definition: DatabaseBlock.php:750
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
$line
$line
Definition: mcc.php:119
MediaWiki\Block\AbstractBlock\setExpiry
setExpiry( $expiry)
Set the block expiry time.
Definition: AbstractBlock.php:480
MediaWiki\Block\DatabaseBlock\clearCookie
static clearCookie(WebResponse $response)
Unset the 'BlockID' cookie.
Definition: DatabaseBlock.php:1143
MediaWiki\Block\AbstractBlock\getExpiry
getExpiry()
Get the block expiry time.
Definition: AbstractBlock.php:470
MediaWiki\Block\DatabaseBlock\update
update()
Update a block in the DB with new parameters.
Definition: DatabaseBlock.php:517
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:454
$lines
if(!file_exists( $CREDITS)) $lines
Definition: updateCredits.php:49
MediaWiki\Block\Restriction\NamespaceRestriction
Definition: NamespaceRestriction.php:25
MediaWiki\Block\AbstractBlock\getTimestamp
getTimestamp()
Get the timestamp indicating when the block was created.
Definition: AbstractBlock.php:490
MediaWiki\Block\DatabaseBlock\getId
getId()
Get the block ID.int|null
Definition: DatabaseBlock.php:760
Title
Represents a title within MediaWiki.
Definition: Title.php:41
$wgBlockCIDRLimit
$wgBlockCIDRLimit
Limits on the possible sizes of range blocks.
Definition: DefaultSettings.php:5429
MediaWiki\Block\DatabaseBlock\setId
setId( $blockId)
Set the block ID.
Definition: DatabaseBlock.php:771
MediaWiki\Block\AbstractBlock\appliesToRight
appliesToRight( $right)
Determine whether the block prevents a given right.
Definition: AbstractBlock.php:270
$cache
$cache
Definition: mcc.php:33
MediaWiki\Block\DatabaseBlock\chooseMostSpecificBlock
static chooseMostSpecificBlock(array $blocks)
Choose the most specific block from some combination of user, IP and IP range blocks.
Definition: DatabaseBlock.php:350
MediaWiki\Block\Restriction\PageRestriction
Definition: PageRestriction.php:25
MediaWiki\Block\AbstractBlock\setReason
setReason( $reason)
Set the reason for creating the block.
Definition: AbstractBlock.php:183
MediaWiki\Block\DatabaseBlock\getRestrictions
getRestrictions()
Get Restrictions.
Definition: DatabaseBlock.php:1193
MediaWiki\$config
Config $config
Definition: MediaWiki.php:42
MediaWiki\Block\DatabaseBlock\updateTimestamp
updateTimestamp()
Update the timestamp on autoblocks.
Definition: DatabaseBlock.php:689
MediaWiki\Block\DatabaseBlock\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new block object.
Definition: DatabaseBlock.php:185
MediaWiki\Block\DatabaseBlock\doAutoblock
doAutoblock( $autoblockIP)
Autoblocks the given IP, referring to this block.
Definition: DatabaseBlock.php:576
MediaWiki\Block\DatabaseBlock\findRestriction
findRestriction( $type, $value)
Find Restriction by type and value.
Definition: DatabaseBlock.php:1292
MediaWiki\Block\DatabaseBlock\newFromTarget
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing block object if possible.
Definition: DatabaseBlock.php:888
MediaWiki\Block\DatabaseBlock\getAutoblockExpiry
static getAutoblockExpiry( $timestamp)
Get a timestamp of the expiry for autoblocks.
Definition: DatabaseBlock.php:853
MediaWiki\Block\AbstractBlock\getHideName
getHideName()
Get whether the block hides the target's username.
Definition: AbstractBlock.php:193
MediaWiki\Block\AbstractBlock\$type
int null $type
AbstractBlock::TYPE_ constant.
Definition: AbstractBlock.php:82
MediaWiki\Block\AbstractBlock
Definition: AbstractBlock.php:38
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
MediaWiki\Block\DatabaseBlock\$mAuto
bool $mAuto
Definition: DatabaseBlock.php:57
MediaWiki\Block\AbstractBlock\setTarget
setTarget( $target)
Set the target for this block, and update $this->type accordingly.
Definition: AbstractBlock.php:508
WebResponse
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
Definition: WebResponse.php:30
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
MediaWiki\Block\DatabaseBlock\$isHardblock
bool $isHardblock
Definition: DatabaseBlock.php:75
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:56
MediaWiki\Block\DatabaseBlock\insert
insert(IDatabase $dbw=null)
Insert a block into the block table.
Definition: DatabaseBlock.php:503
MediaWiki\Block\DatabaseBlock\appliesToTitle
appliesToTitle(Title $title)
Checks if a block applies to a particular title.This check does not consider whether $this->isUsertal...
Definition: DatabaseBlock.php:1234
MediaWiki\Block\AbstractBlock\getTarget
getTarget()
Get the target for this particular block.
Definition: AbstractBlock.php:460
MediaWiki\Block\DatabaseBlock\isHardblock
isHardblock( $x=null)
Get/set whether the block is a hardblock (affects logged-in users on a given IP/range)
Definition: DatabaseBlock.php:808
MediaWiki\Block\DatabaseBlock\newListFromTarget
static newListFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
This is similar to DatabaseBlock::newFromTarget, but it returns all the relevant blocks.
Definition: DatabaseBlock.php:902
MediaWiki\Block\DatabaseBlock\$restrictions
Restriction[] $restrictions
Definition: DatabaseBlock.php:81
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:255
MediaWiki\Block\DatabaseBlock\$mId
int $mId
Definition: DatabaseBlock.php:66
Hooks
Hooks class.
Definition: Hooks.php:38
MediaWiki\Block\BlockRestrictionStore
Definition: BlockRestrictionStore.php:34
MediaWiki\Block\DatabaseBlock\newFromID
static newFromID( $id)
Load a block from the block id.
Definition: DatabaseBlock.php:158
Html
This class is a collection of static functions that serve two purposes:
Definition: Html.php:49