MediaWiki  1.23.15
Block.php
Go to the documentation of this file.
1 <?php
22 class Block {
24 
25  protected
28 
33 
35  protected $target;
36 
38  protected $forcedTargetID;
39 
41  protected $type;
42 
44  protected $blocker;
45 
47  protected $isHardblock = true;
48 
50  protected $isAutoblocking = true;
51 
52  # TYPE constants
53  const TYPE_USER = 1;
54  const TYPE_IP = 2;
55  const TYPE_RANGE = 3;
56  const TYPE_AUTO = 4;
57  const TYPE_ID = 5;
58 
64  function __construct( $address = '', $user = 0, $by = 0, $reason = '',
65  $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
66  $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byText = ''
67  ) {
68  if ( $timestamp === 0 ) {
70  }
71 
72  if ( count( func_get_args() ) > 0 ) {
73  # Soon... :D
74  # wfDeprecated( __METHOD__ . " with arguments" );
75  }
76 
77  $this->setTarget( $address );
78  if ( $this->target instanceof User && $user ) {
79  $this->forcedTargetID = $user; // needed for foreign users
80  }
81  if ( $by ) { // local user
82  $this->setBlocker( User::newFromID( $by ) );
83  } else { // foreign user
84  $this->setBlocker( $byText );
85  }
86  $this->mReason = $reason;
87  $this->mTimestamp = wfTimestamp( TS_MW, $timestamp );
88  $this->mAuto = $auto;
89  $this->isHardblock( !$anonOnly );
90  $this->prevents( 'createaccount', $createAccount );
91  if ( $expiry == 'infinity' || $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) {
92  $this->mExpiry = 'infinity';
93  } else {
94  $this->mExpiry = wfTimestamp( TS_MW, $expiry );
95  }
96  $this->isAutoblocking( $enableAutoblock );
97  $this->mHideName = $hideName;
98  $this->prevents( 'sendemail', $blockEmail );
99  $this->prevents( 'editownusertalk', !$allowUsertalk );
100 
101  $this->mFromMaster = false;
102  }
103 
110  public static function newFromID( $id ) {
111  $dbr = wfGetDB( DB_SLAVE );
112  $res = $dbr->selectRow(
113  'ipblocks',
114  self::selectFields(),
115  array( 'ipb_id' => $id ),
116  __METHOD__
117  );
118  if ( $res ) {
119  return self::newFromRow( $res );
120  } else {
121  return null;
122  }
123  }
124 
130  public static function selectFields() {
131  return array(
132  'ipb_id',
133  'ipb_address',
134  'ipb_by',
135  'ipb_by_text',
136  'ipb_reason',
137  'ipb_timestamp',
138  'ipb_auto',
139  'ipb_anon_only',
140  'ipb_create_account',
141  'ipb_enable_autoblock',
142  'ipb_expiry',
143  'ipb_deleted',
144  'ipb_block_email',
145  'ipb_allow_usertalk',
146  'ipb_parent_block_id',
147  );
148  }
149 
158  public function equals( Block $block ) {
159  return (
160  (string)$this->target == (string)$block->target
161  && $this->type == $block->type
162  && $this->mAuto == $block->mAuto
163  && $this->isHardblock() == $block->isHardblock()
164  && $this->prevents( 'createaccount' ) == $block->prevents( 'createaccount' )
165  && $this->mExpiry == $block->mExpiry
166  && $this->isAutoblocking() == $block->isAutoblocking()
167  && $this->mHideName == $block->mHideName
168  && $this->prevents( 'sendemail' ) == $block->prevents( 'sendemail' )
169  && $this->prevents( 'editownusertalk' ) == $block->prevents( 'editownusertalk' )
170  && $this->mReason == $block->mReason
171  );
172  }
173 
184  protected function newLoad( $vagueTarget = null ) {
185  $db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
186 
187  if ( $this->type !== null ) {
188  $conds = array(
189  'ipb_address' => array( (string)$this->target ),
190  );
191  } else {
192  $conds = array( 'ipb_address' => array() );
193  }
194 
195  # Be aware that the != '' check is explicit, since empty values will be
196  # passed by some callers (bug 29116)
197  if ( $vagueTarget != '' ) {
198  list( $target, $type ) = self::parseTarget( $vagueTarget );
199  switch ( $type ) {
200  case self::TYPE_USER:
201  # Slightly weird, but who are we to argue?
202  $conds['ipb_address'][] = (string)$target;
203  break;
204 
205  case self::TYPE_IP:
206  $conds['ipb_address'][] = (string)$target;
207  $conds[] = self::getRangeCond( IP::toHex( $target ) );
208  $conds = $db->makeList( $conds, LIST_OR );
209  break;
210 
211  case self::TYPE_RANGE:
212  list( $start, $end ) = IP::parseRange( $target );
213  $conds['ipb_address'][] = (string)$target;
214  $conds[] = self::getRangeCond( $start, $end );
215  $conds = $db->makeList( $conds, LIST_OR );
216  break;
217 
218  default:
219  throw new MWException( "Tried to load block with invalid type" );
220  }
221  }
222 
223  $res = $db->select( 'ipblocks', self::selectFields(), $conds, __METHOD__ );
224 
225  # This result could contain a block on the user, a block on the IP, and a russian-doll
226  # set of rangeblocks. We want to choose the most specific one, so keep a leader board.
227  $bestRow = null;
228 
229  # Lower will be better
230  $bestBlockScore = 100;
231 
232  # This is begging for $this = $bestBlock, but that's not allowed in PHP :(
233  $bestBlockPreventsEdit = null;
234 
235  foreach ( $res as $row ) {
236  $block = self::newFromRow( $row );
237 
238  # Don't use expired blocks
239  if ( $block->deleteIfExpired() ) {
240  continue;
241  }
242 
243  # Don't use anon only blocks on users
244  if ( $this->type == self::TYPE_USER && !$block->isHardblock() ) {
245  continue;
246  }
247 
248  if ( $block->getType() == self::TYPE_RANGE ) {
249  # This is the number of bits that are allowed to vary in the block, give
250  # or take some floating point errors
251  $end = wfBaseconvert( $block->getRangeEnd(), 16, 10 );
252  $start = wfBaseconvert( $block->getRangeStart(), 16, 10 );
253  $size = log( $end - $start + 1, 2 );
254 
255  # This has the nice property that a /32 block is ranked equally with a
256  # single-IP block, which is exactly what it is...
257  $score = self::TYPE_RANGE - 1 + ( $size / 128 );
258 
259  } else {
260  $score = $block->getType();
261  }
262 
263  if ( $score < $bestBlockScore ) {
264  $bestBlockScore = $score;
265  $bestRow = $row;
266  $bestBlockPreventsEdit = $block->prevents( 'edit' );
267  }
268  }
269 
270  if ( $bestRow !== null ) {
271  $this->initFromRow( $bestRow );
272  $this->prevents( 'edit', $bestBlockPreventsEdit );
273  return true;
274  } else {
275  return false;
276  }
277  }
278 
285  public static function getRangeCond( $start, $end = null ) {
286  if ( $end === null ) {
287  $end = $start;
288  }
289  # Per bug 14634, we want to include relevant active rangeblocks; for
290  # rangeblocks, we want to include larger ranges which enclose the given
291  # range. We know that all blocks must be smaller than $wgBlockCIDRLimit,
292  # so we can improve performance by filtering on a LIKE clause
293  $chunk = self::getIpFragment( $start );
294  $dbr = wfGetDB( DB_SLAVE );
295  $like = $dbr->buildLike( $chunk, $dbr->anyString() );
296 
297  # Fairly hard to make a malicious SQL statement out of hex characters,
298  # but stranger things have happened...
299  $safeStart = $dbr->addQuotes( $start );
300  $safeEnd = $dbr->addQuotes( $end );
301 
302  return $dbr->makeList(
303  array(
304  "ipb_range_start $like",
305  "ipb_range_start <= $safeStart",
306  "ipb_range_end >= $safeEnd",
307  ),
308  LIST_AND
309  );
310  }
311 
318  protected static function getIpFragment( $hex ) {
319  global $wgBlockCIDRLimit;
320  if ( substr( $hex, 0, 3 ) == 'v6-' ) {
321  return 'v6-' . substr( substr( $hex, 3 ), 0, floor( $wgBlockCIDRLimit['IPv6'] / 4 ) );
322  } else {
323  return substr( $hex, 0, floor( $wgBlockCIDRLimit['IPv4'] / 4 ) );
324  }
325  }
326 
332  protected function initFromRow( $row ) {
333  $this->setTarget( $row->ipb_address );
334  if ( $row->ipb_by ) { // local user
335  $this->setBlocker( User::newFromID( $row->ipb_by ) );
336  } else { // foreign user
337  $this->setBlocker( $row->ipb_by_text );
338  }
339 
340  $this->mReason = $row->ipb_reason;
341  $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
342  $this->mAuto = $row->ipb_auto;
343  $this->mHideName = $row->ipb_deleted;
344  $this->mId = $row->ipb_id;
345  $this->mParentBlockId = $row->ipb_parent_block_id;
346 
347  // I wish I didn't have to do this
348  $db = wfGetDB( DB_SLAVE );
349  if ( $row->ipb_expiry == $db->getInfinity() ) {
350  $this->mExpiry = 'infinity';
351  } else {
352  $this->mExpiry = wfTimestamp( TS_MW, $row->ipb_expiry );
353  }
354 
355  $this->isHardblock( !$row->ipb_anon_only );
356  $this->isAutoblocking( $row->ipb_enable_autoblock );
357 
358  $this->prevents( 'createaccount', $row->ipb_create_account );
359  $this->prevents( 'sendemail', $row->ipb_block_email );
360  $this->prevents( 'editownusertalk', !$row->ipb_allow_usertalk );
361  }
362 
368  public static function newFromRow( $row ) {
369  $block = new Block;
370  $block->initFromRow( $row );
371  return $block;
372  }
373 
380  public function delete() {
381  if ( wfReadOnly() ) {
382  return false;
383  }
384 
385  if ( !$this->getId() ) {
386  throw new MWException( "Block::delete() requires that the mId member be filled\n" );
387  }
388 
389  $dbw = wfGetDB( DB_MASTER );
390  $dbw->delete( 'ipblocks', array( 'ipb_parent_block_id' => $this->getId() ), __METHOD__ );
391  $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->getId() ), __METHOD__ );
392 
393  return $dbw->affectedRows() > 0;
394  }
395 
404  public function insert( $dbw = null ) {
405  global $wgBlockDisablesLogin;
406  wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
407 
408  if ( $dbw === null ) {
409  $dbw = wfGetDB( DB_MASTER );
410  }
411 
412  # Don't collide with expired blocks
414 
415  $row = $this->getDatabaseArray();
416  $row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" );
417 
418  $dbw->insert(
419  'ipblocks',
420  $row,
421  __METHOD__,
422  array( 'IGNORE' )
423  );
424  $affected = $dbw->affectedRows();
425  $this->mId = $dbw->insertId();
426 
427  if ( $affected ) {
428  if ( $wgBlockDisablesLogin && $this->target instanceof User ) {
429  // Change user login token to force them to be logged out.
430  $this->target->setToken();
431  $this->target->saveSettings();
432  }
433  $auto_ipd_ids = $this->doRetroactiveAutoblock();
434  return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
435  }
436 
437  return false;
438  }
439 
447  public function update() {
448  wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
449  $dbw = wfGetDB( DB_MASTER );
450 
451  $dbw->startAtomic( __METHOD__ );
452 
453  $dbw->update(
454  'ipblocks',
455  $this->getDatabaseArray( $dbw ),
456  array( 'ipb_id' => $this->getId() ),
457  __METHOD__
458  );
459 
460  $affected = $dbw->affectedRows();
461 
462  if ( $this->isAutoblocking() ) {
463  // update corresponding autoblock(s) (bug 48813)
464  $dbw->update(
465  'ipblocks',
466  $this->getAutoblockUpdateArray(),
467  array( 'ipb_parent_block_id' => $this->getId() ),
468  __METHOD__
469  );
470  } else {
471  // autoblock no longer required, delete corresponding autoblock(s)
472  $dbw->delete(
473  'ipblocks',
474  array( 'ipb_parent_block_id' => $this->getId() ),
475  __METHOD__
476  );
477  }
478 
479  $dbw->endAtomic( __METHOD__ );
480 
481  if ( $affected ) {
482  $auto_ipd_ids = $this->doRetroactiveAutoblock();
483  return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
484  }
485 
486  return false;
487  }
488 
494  protected function getDatabaseArray( $db = null ) {
495  if ( !$db ) {
496  $db = wfGetDB( DB_SLAVE );
497  }
498  $expiry = $db->encodeExpiry( $this->mExpiry );
499 
500  if ( $this->forcedTargetID ) {
501  $uid = $this->forcedTargetID;
502  } else {
503  $uid = $this->target instanceof User ? $this->target->getID() : 0;
504  }
505 
506  $a = array(
507  'ipb_address' => (string)$this->target,
508  'ipb_user' => $uid,
509  'ipb_by' => $this->getBy(),
510  'ipb_by_text' => $this->getByName(),
511  'ipb_reason' => $this->mReason,
512  'ipb_timestamp' => $db->timestamp( $this->mTimestamp ),
513  'ipb_auto' => $this->mAuto,
514  'ipb_anon_only' => !$this->isHardblock(),
515  'ipb_create_account' => $this->prevents( 'createaccount' ),
516  'ipb_enable_autoblock' => $this->isAutoblocking(),
517  'ipb_expiry' => $expiry,
518  'ipb_range_start' => $this->getRangeStart(),
519  'ipb_range_end' => $this->getRangeEnd(),
520  'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite
521  'ipb_block_email' => $this->prevents( 'sendemail' ),
522  'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
523  'ipb_parent_block_id' => $this->mParentBlockId
524  );
525 
526  return $a;
527  }
528 
532  protected function getAutoblockUpdateArray() {
533  return array(
534  'ipb_by' => $this->getBy(),
535  'ipb_by_text' => $this->getByName(),
536  'ipb_reason' => $this->mReason,
537  'ipb_create_account' => $this->prevents( 'createaccount' ),
538  'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite
539  'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
540  );
541  }
542 
549  protected function doRetroactiveAutoblock() {
550  $blockIds = array();
551  # If autoblock is enabled, autoblock the LAST IP(s) used
552  if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) {
553  wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" );
554 
555  $continue = wfRunHooks(
556  'PerformRetroactiveAutoblock', array( $this, &$blockIds ) );
557 
558  if ( $continue ) {
559  self::defaultRetroactiveAutoblock( $this, $blockIds );
560  }
561  }
562  return $blockIds;
563  }
564 
573  protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
574  global $wgPutIPinRC;
575 
576  // No IPs are in recentchanges table, so nothing to select
577  if ( !$wgPutIPinRC ) {
578  return;
579  }
580 
581  $dbr = wfGetDB( DB_SLAVE );
582 
583  $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
584  $conds = array( 'rc_user_text' => (string)$block->getTarget() );
585 
586  // Just the last IP used.
587  $options['LIMIT'] = 1;
588 
589  $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
590  __METHOD__, $options );
591 
592  if ( !$res->numRows() ) {
593  # No results, don't autoblock anything
594  wfDebug( "No IP found to retroactively autoblock\n" );
595  } else {
596  foreach ( $res as $row ) {
597  if ( $row->rc_ip ) {
598  $id = $block->doAutoblock( $row->rc_ip );
599  if ( $id ) {
600  $blockIds[] = $id;
601  }
602  }
603  }
604  }
605  }
606 
614  public static function isWhitelistedFromAutoblocks( $ip ) {
615  global $wgMemc;
616 
617  // Try to get the autoblock_whitelist from the cache, as it's faster
618  // than getting the msg raw and explode()'ing it.
619  $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
620  $lines = $wgMemc->get( $key );
621  if ( !$lines ) {
622  $lines = explode( "\n", wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
623  $wgMemc->set( $key, $lines, 3600 * 24 );
624  }
625 
626  wfDebug( "Checking the autoblock whitelist..\n" );
627 
628  foreach ( $lines as $line ) {
629  # List items only
630  if ( substr( $line, 0, 1 ) !== '*' ) {
631  continue;
632  }
633 
634  $wlEntry = substr( $line, 1 );
635  $wlEntry = trim( $wlEntry );
636 
637  wfDebug( "Checking $ip against $wlEntry..." );
638 
639  # Is the IP in this range?
640  if ( IP::isInRange( $ip, $wlEntry ) ) {
641  wfDebug( " IP $ip matches $wlEntry, not autoblocking\n" );
642  return true;
643  } else {
644  wfDebug( " No match\n" );
645  }
646  }
647 
648  return false;
649  }
650 
657  public function doAutoblock( $autoblockIP ) {
658  # If autoblocks are disabled, go away.
659  if ( !$this->isAutoblocking() ) {
660  return false;
661  }
662 
663  # Check for presence on the autoblock whitelist.
664  if ( self::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
665  return false;
666  }
667 
668  # Allow hooks to cancel the autoblock.
669  if ( !wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) {
670  wfDebug( "Autoblock aborted by hook.\n" );
671  return false;
672  }
673 
674  # It's okay to autoblock. Go ahead and insert/update the block...
675 
676  # Do not add a *new* block if the IP is already blocked.
677  $ipblock = Block::newFromTarget( $autoblockIP );
678  if ( $ipblock ) {
679  # Check if the block is an autoblock and would exceed the user block
680  # if renewed. If so, do nothing, otherwise prolong the block time...
681  if ( $ipblock->mAuto && // @todo Why not compare $ipblock->mExpiry?
682  $this->mExpiry > Block::getAutoblockExpiry( $ipblock->mTimestamp )
683  ) {
684  # Reset block timestamp to now and its expiry to
685  # $wgAutoblockExpiry in the future
686  $ipblock->updateTimestamp();
687  }
688  return false;
689  }
690 
691  # Make a new block object with the desired properties.
692  $autoblock = new Block;
693  wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" );
694  $autoblock->setTarget( $autoblockIP );
695  $autoblock->setBlocker( $this->getBlocker() );
696  $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )
697  ->inContentLanguage()->plain();
699  $autoblock->mTimestamp = $timestamp;
700  $autoblock->mAuto = 1;
701  $autoblock->prevents( 'createaccount', $this->prevents( 'createaccount' ) );
702  # Continue suppressing the name if needed
703  $autoblock->mHideName = $this->mHideName;
704  $autoblock->prevents( 'editownusertalk', $this->prevents( 'editownusertalk' ) );
705  $autoblock->mParentBlockId = $this->mId;
706 
707  if ( $this->mExpiry == 'infinity' ) {
708  # Original block was indefinite, start an autoblock now
709  $autoblock->mExpiry = Block::getAutoblockExpiry( $timestamp );
710  } else {
711  # If the user is already blocked with an expiry date, we don't
712  # want to pile on top of that.
713  $autoblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( $timestamp ) );
714  }
715 
716  # Insert the block...
717  $status = $autoblock->insert();
718  return $status
719  ? $status['id']
720  : false;
721  }
722 
727  public function deleteIfExpired() {
728  wfProfileIn( __METHOD__ );
729 
730  if ( $this->isExpired() ) {
731  wfDebug( "Block::deleteIfExpired() -- deleting\n" );
732  $this->delete();
733  $retVal = true;
734  } else {
735  wfDebug( "Block::deleteIfExpired() -- not expired\n" );
736  $retVal = false;
737  }
738 
739  wfProfileOut( __METHOD__ );
740  return $retVal;
741  }
742 
747  public function isExpired() {
749  wfDebug( "Block::isExpired() checking current " . $timestamp . " vs $this->mExpiry\n" );
750 
751  if ( !$this->mExpiry ) {
752  return false;
753  } else {
754  return $timestamp > $this->mExpiry;
755  }
756  }
757 
762  public function isValid() {
763  return $this->getTarget() != null;
764  }
765 
769  public function updateTimestamp() {
770  if ( $this->mAuto ) {
771  $this->mTimestamp = wfTimestamp();
772  $this->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
773 
774  $dbw = wfGetDB( DB_MASTER );
775  $dbw->update( 'ipblocks',
776  array( /* SET */
777  'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
778  'ipb_expiry' => $dbw->timestamp( $this->mExpiry ),
779  ),
780  array( /* WHERE */
781  'ipb_id' => $this->getId()
782  ),
783  __METHOD__
784  );
785  }
786  }
787 
793  public function getRangeStart() {
794  switch ( $this->type ) {
795  case self::TYPE_USER:
796  return '';
797  case self::TYPE_IP:
798  return IP::toHex( $this->target );
799  case self::TYPE_RANGE:
800  list( $start, /*...*/ ) = IP::parseRange( $this->target );
801  return $start;
802  default:
803  throw new MWException( "Block with invalid type" );
804  }
805  }
806 
812  public function getRangeEnd() {
813  switch ( $this->type ) {
814  case self::TYPE_USER:
815  return '';
816  case self::TYPE_IP:
817  return IP::toHex( $this->target );
818  case self::TYPE_RANGE:
819  list( /*...*/, $end ) = IP::parseRange( $this->target );
820  return $end;
821  default:
822  throw new MWException( "Block with invalid type" );
823  }
824  }
825 
831  public function getBy() {
832  $blocker = $this->getBlocker();
833  return ( $blocker instanceof User )
834  ? $blocker->getId()
835  : 0;
836  }
837 
843  public function getByName() {
844  $blocker = $this->getBlocker();
845  return ( $blocker instanceof User )
846  ? $blocker->getName()
847  : (string)$blocker; // username
848  }
849 
854  public function getId() {
855  return $this->mId;
856  }
857 
864  public function fromMaster( $x = null ) {
865  return wfSetVar( $this->mFromMaster, $x );
866  }
867 
873  public function isHardblock( $x = null ) {
874  wfSetVar( $this->isHardblock, $x );
875 
876  # You can't *not* hardblock a user
877  return $this->getType() == self::TYPE_USER
878  ? true
880  }
881 
882  public function isAutoblocking( $x = null ) {
883  wfSetVar( $this->isAutoblocking, $x );
884 
885  # You can't put an autoblock on an IP or range as we don't have any history to
886  # look over to get more IPs from
887  return $this->getType() == self::TYPE_USER
888  ? $this->isAutoblocking
889  : false;
890  }
891 
898  public function prevents( $action, $x = null ) {
899  global $wgBlockDisablesLogin;
900  $res = null;
901  switch ( $action ) {
902  case 'edit':
903  # For now... <evil laugh>
904  $res = true;
905  break;
906  case 'createaccount':
907  $res = wfSetVar( $this->mCreateAccount, $x );
908  break;
909  case 'sendemail':
910  $res = wfSetVar( $this->mBlockEmail, $x );
911  break;
912  case 'editownusertalk':
913  $res = wfSetVar( $this->mDisableUsertalk, $x );
914  break;
915  case 'read':
916  $res = false;
917  break;
918  }
919  if ( !$res && $wgBlockDisablesLogin ) {
920  // If a block would disable login, then it should
921  // prevent any action that all users cannot do
922  $anon = new User;
923  $res = $anon->isAllowed( $action ) ? $res : true;
924  }
925 
926  return $res;
927  }
928 
933  public function getRedactedName() {
934  if ( $this->mAuto ) {
935  return Html::rawElement(
936  'span',
937  array( 'class' => 'mw-autoblockid' ),
938  wfMessage( 'autoblockid', $this->mId )
939  );
940  } else {
941  return htmlspecialchars( $this->getTarget() );
942  }
943  }
944 
951  public static function getAutoblockExpiry( $timestamp ) {
952  global $wgAutoblockExpiry;
953 
954  return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
955  }
956 
960  public static function purgeExpired() {
961  if ( wfReadOnly() ) {
962  return;
963  }
964 
965  $method = __METHOD__;
966  $dbw = wfGetDB( DB_MASTER );
967  $dbw->onTransactionIdle( function() use ( $dbw, $method ) {
968  $dbw->delete( 'ipblocks',
969  array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), $method );
970  } );
971  }
972 
993  public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
994 
995  list( $target, $type ) = self::parseTarget( $specificTarget );
996  if ( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ) {
997  return Block::newFromID( $target );
998 
999  } elseif ( $target === null && $vagueTarget == '' ) {
1000  # We're not going to find anything useful here
1001  # Be aware that the == '' check is explicit, since empty values will be
1002  # passed by some callers (bug 29116)
1003  return null;
1004 
1005  } elseif ( in_array(
1006  $type,
1008  ) {
1009  $block = new Block();
1010  $block->fromMaster( $fromMaster );
1011 
1012  if ( $type !== null ) {
1013  $block->setTarget( $target );
1014  }
1015 
1016  if ( $block->newLoad( $vagueTarget ) ) {
1017  return $block;
1018  }
1019  }
1020  return null;
1021  }
1022 
1033  public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
1034  if ( !count( $ipChain ) ) {
1035  return array();
1036  }
1037 
1038  wfProfileIn( __METHOD__ );
1039  $conds = array();
1040  foreach ( array_unique( $ipChain ) as $ipaddr ) {
1041  # Discard invalid IP addresses. Since XFF can be spoofed and we do not
1042  # necessarily trust the header given to us, make sure that we are only
1043  # checking for blocks on well-formatted IP addresses (IPv4 and IPv6).
1044  # Do not treat private IP spaces as special as it may be desirable for wikis
1045  # to block those IP ranges in order to stop misbehaving proxies that spoof XFF.
1046  if ( !IP::isValid( $ipaddr ) ) {
1047  continue;
1048  }
1049  # Don't check trusted IPs (includes local squids which will be in every request)
1050  if ( wfIsTrustedProxy( $ipaddr ) ) {
1051  continue;
1052  }
1053  # Check both the original IP (to check against single blocks), as well as build
1054  # the clause to check for rangeblocks for the given IP.
1055  $conds['ipb_address'][] = $ipaddr;
1056  $conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
1057  }
1058 
1059  if ( !count( $conds ) ) {
1060  wfProfileOut( __METHOD__ );
1061  return array();
1062  }
1063 
1064  if ( $fromMaster ) {
1065  $db = wfGetDB( DB_MASTER );
1066  } else {
1067  $db = wfGetDB( DB_SLAVE );
1068  }
1069  $conds = $db->makeList( $conds, LIST_OR );
1070  if ( !$isAnon ) {
1071  $conds = array( $conds, 'ipb_anon_only' => 0 );
1072  }
1073  $selectFields = array_merge(
1074  array( 'ipb_range_start', 'ipb_range_end' ),
1076  );
1077  $rows = $db->select( 'ipblocks',
1078  $selectFields,
1079  $conds,
1080  __METHOD__
1081  );
1082 
1083  $blocks = array();
1084  foreach ( $rows as $row ) {
1085  $block = self::newFromRow( $row );
1086  if ( !$block->deleteIfExpired() ) {
1087  $blocks[] = $block;
1088  }
1089  }
1090 
1091  wfProfileOut( __METHOD__ );
1092  return $blocks;
1093  }
1094 
1112  public static function chooseBlock( array $blocks, array $ipChain ) {
1113  if ( !count( $blocks ) ) {
1114  return null;
1115  } elseif ( count( $blocks ) == 1 ) {
1116  return $blocks[0];
1117  }
1118 
1119  wfProfileIn( __METHOD__ );
1120 
1121  // Sort hard blocks before soft ones and secondarily sort blocks
1122  // that disable account creation before those that don't.
1123  usort( $blocks, function( Block $a, Block $b ) {
1124  $aWeight = (int)$a->isHardblock() . (int)$a->prevents( 'createaccount' );
1125  $bWeight = (int)$b->isHardblock() . (int)$b->prevents( 'createaccount' );
1126  return strcmp( $bWeight, $aWeight ); // highest weight first
1127  } );
1128 
1129  $blocksListExact = array(
1130  'hard' => false,
1131  'disable_create' => false,
1132  'other' => false,
1133  'auto' => false
1134  );
1135  $blocksListRange = array(
1136  'hard' => false,
1137  'disable_create' => false,
1138  'other' => false,
1139  'auto' => false
1140  );
1141  $ipChain = array_reverse( $ipChain );
1142 
1143  foreach ( $blocks as $block ) {
1144  // Stop searching if we have already have a "better" block. This
1145  // is why the order of the blocks matters
1146  if ( !$block->isHardblock() && $blocksListExact['hard'] ) {
1147  break;
1148  } elseif ( !$block->prevents( 'createaccount' ) && $blocksListExact['disable_create'] ) {
1149  break;
1150  }
1151 
1152  foreach ( $ipChain as $checkip ) {
1153  $checkipHex = IP::toHex( $checkip );
1154  if ( (string)$block->getTarget() === $checkip ) {
1155  if ( $block->isHardblock() ) {
1156  $blocksListExact['hard'] = $blocksListExact['hard'] ?: $block;
1157  } elseif ( $block->prevents( 'createaccount' ) ) {
1158  $blocksListExact['disable_create'] = $blocksListExact['disable_create'] ?: $block;
1159  } elseif ( $block->mAuto ) {
1160  $blocksListExact['auto'] = $blocksListExact['auto'] ?: $block;
1161  } else {
1162  $blocksListExact['other'] = $blocksListExact['other'] ?: $block;
1163  }
1164  // We found closest exact match in the ip list, so go to the next Block
1165  break;
1166  } elseif ( array_filter( $blocksListExact ) == array()
1167  && $block->getRangeStart() <= $checkipHex
1168  && $block->getRangeEnd() >= $checkipHex
1169  ) {
1170  if ( $block->isHardblock() ) {
1171  $blocksListRange['hard'] = $blocksListRange['hard'] ?: $block;
1172  } elseif ( $block->prevents( 'createaccount' ) ) {
1173  $blocksListRange['disable_create'] = $blocksListRange['disable_create'] ?: $block;
1174  } elseif ( $block->mAuto ) {
1175  $blocksListRange['auto'] = $blocksListRange['auto'] ?: $block;
1176  } else {
1177  $blocksListRange['other'] = $blocksListRange['other'] ?: $block;
1178  }
1179  break;
1180  }
1181  }
1182  }
1183 
1184  if ( array_filter( $blocksListExact ) == array() ) {
1185  $blocksList = &$blocksListRange;
1186  } else {
1187  $blocksList = &$blocksListExact;
1188  }
1189 
1190  $chosenBlock = null;
1191  if ( $blocksList['hard'] ) {
1192  $chosenBlock = $blocksList['hard'];
1193  } elseif ( $blocksList['disable_create'] ) {
1194  $chosenBlock = $blocksList['disable_create'];
1195  } elseif ( $blocksList['other'] ) {
1196  $chosenBlock = $blocksList['other'];
1197  } elseif ( $blocksList['auto'] ) {
1198  $chosenBlock = $blocksList['auto'];
1199  } else {
1200  wfProfileOut( __METHOD__ );
1201  throw new MWException( "Proxy block found, but couldn't be classified." );
1202  }
1203 
1204  wfProfileOut( __METHOD__ );
1205  return $chosenBlock;
1206  }
1207 
1217  public static function parseTarget( $target ) {
1218  # We may have been through this before
1219  if ( $target instanceof User ) {
1220  if ( IP::isValid( $target->getName() ) ) {
1221  return array( $target, self::TYPE_IP );
1222  } else {
1223  return array( $target, self::TYPE_USER );
1224  }
1225  } elseif ( $target === null ) {
1226  return array( null, null );
1227  }
1228 
1229  $target = trim( $target );
1230 
1231  if ( IP::isValid( $target ) ) {
1232  # We can still create a User if it's an IP address, but we need to turn
1233  # off validation checking (which would exclude IP addresses)
1234  return array(
1237  );
1238 
1239  } elseif ( IP::isValidBlock( $target ) ) {
1240  # Can't create a User from an IP range
1242  }
1243 
1244  # Consider the possibility that this is not a username at all
1245  # but actually an old subpage (bug #29797)
1246  if ( strpos( $target, '/' ) !== false ) {
1247  # An old subpage, drill down to the user behind it
1248  $parts = explode( '/', $target );
1249  $target = $parts[0];
1250  }
1251 
1252  $userObj = User::newFromName( $target );
1253  if ( $userObj instanceof User ) {
1254  # Note that since numbers are valid usernames, a $target of "12345" will be
1255  # considered a User. If you want to pass a block ID, prepend a hash "#12345",
1256  # since hash characters are not valid in usernames or titles generally.
1257  return array( $userObj, Block::TYPE_USER );
1258 
1259  } elseif ( preg_match( '/^#\d+$/', $target ) ) {
1260  # Autoblock reference in the form "#12345"
1261  return array( substr( $target, 1 ), Block::TYPE_AUTO );
1262 
1263  } else {
1264  # WTF?
1265  return array( null, null );
1266  }
1267  }
1268 
1273  public function getType() {
1274  return $this->mAuto
1275  ? self::TYPE_AUTO
1276  : $this->type;
1277  }
1278 
1286  public function getTargetAndType() {
1287  return array( $this->getTarget(), $this->getType() );
1288  }
1289 
1296  public function getTarget() {
1297  return $this->target;
1298  }
1305  public function getExpiry() {
1306  return $this->mExpiry;
1307  }
1308 
1313  public function setTarget( $target ) {
1314  list( $this->target, $this->type ) = self::parseTarget( $target );
1315  }
1316 
1321  public function getBlocker() {
1322  return $this->blocker;
1323  }
1324 
1329  public function setBlocker( $user ) {
1330  $this->blocker = $user;
1331  }
1332 
1340  public function getPermissionsError( IContextSource $context ) {
1341  $blocker = $this->getBlocker();
1342  if ( $blocker instanceof User ) { // local user
1343  $blockerUserpage = $blocker->getUserPage();
1344  $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
1345  } else { // foreign user
1346  $link = $blocker;
1347  }
1348 
1349  $reason = $this->mReason;
1350  if ( $reason == '' ) {
1351  $reason = $context->msg( 'blockednoreason' )->text();
1352  }
1353 
1354  /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1355  * This could be a username, an IP range, or a single IP. */
1356  $intended = $this->getTarget();
1357 
1358  $lang = $context->getLanguage();
1359  return array(
1360  $this->mAuto ? 'autoblockedtext' : 'blockedtext',
1361  $link,
1362  $reason,
1363  $context->getRequest()->getIP(),
1364  $this->getByName(),
1365  $this->getId(),
1366  $lang->formatExpiry( $this->mExpiry ),
1367  (string)$intended,
1368  $lang->timeanddate( wfTimestamp( TS_MW, $this->mTimestamp ), true ),
1369  );
1370  }
1371 }
Block\prevents
prevents( $action, $x=null)
Get/set whether the Block prevents a given action.
Definition: Block.php:892
IP\toHex
static toHex( $ip)
Return a zero-padded upper case hexadecimal representation of an IP address.
Definition: IP.php:456
Block\isHardblock
isHardblock( $x=null)
Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range.
Definition: Block.php:867
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
Block\equals
equals(Block $block)
Check if two blocks are effectively equal.
Definition: Block.php:152
Block\$type
Integer $type
Block::TYPE_ constant.
Definition: Block.php:38
Block\getType
getType()
Get the type of target for this particular block.
Definition: Block.php:1267
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
User\getId
getId()
Get the user's ID.
Definition: User.php:1852
Block\$mReason
$mReason
Definition: Block.php:23
Block\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: Block.php:312
Block\isExpired
isExpired()
Has the block expired?
Definition: Block.php:741
Block\$mDisableUsertalk
$mDisableUsertalk
Definition: Block.php:26
Block\newFromID
static newFromID( $id)
Load a blocked user from their block id.
Definition: Block.php:104
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:2186
Block\TYPE_IP
const TYPE_IP
Definition: Block.php:48
$wgMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
Definition: globals.txt:25
Block\TYPE_RANGE
const TYPE_RANGE
Definition: Block.php:49
Block\getBy
getBy()
Get the user id of the blocking sysop.
Definition: Block.php:825
Block\chooseBlock
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest Block.
Definition: Block.php:1106
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3714
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
Block\update
update()
Update a block in the DB with new parameters.
Definition: Block.php:441
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
Block\getId
getId()
Get the block ID.
Definition: Block.php:848
Block\newFromTarget
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
Definition: Block.php:987
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1360
IContextSource\msg
msg()
Get a Message object with context set.
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
Block\isValid
isValid()
Is the block address valid (i.e.
Definition: Block.php:756
Block\initFromRow
initFromRow( $row)
Given a database row from the ipblocks table, initialize member variables.
Definition: Block.php:326
User\getUserPage
getUserPage()
Get this user's personal page title.
Definition: User.php:3673
Block\getRangeEnd
getRangeEnd()
Get the IP address at the end of the range in Hex form.
Definition: Block.php:806
Block\$isHardblock
Bool $isHardblock
Definition: Block.php:42
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2160
Block\getExpiry
getExpiry()
Definition: Block.php:1299
Block\deleteIfExpired
deleteIfExpired()
Check if a block has expired.
Definition: Block.php:721
Block\insert
insert( $dbw=null)
Insert a block into the block table.
Definition: Block.php:398
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1530
LIST_AND
const LIST_AND
Definition: Defines.php:203
Block\getRedactedName
getRedactedName()
Get the block name, but with autoblocked IPs hidden as per standard privacy policy.
Definition: Block.php:927
Block\newLoad
newLoad( $vagueTarget=null)
Load a block from the database which affects the already-set $this->target: 1) A block directly on th...
Definition: Block.php:178
Block\$mExpiry
$mExpiry
Definition: Block.php:23
$dbr
$dbr
Definition: testCompression.php:48
Block\$mFromMaster
$mFromMaster
Definition: Block.php:26
LIST_OR
const LIST_OR
Definition: Defines.php:206
MWException
MediaWiki exception.
Definition: MWException.php:26
wfMemcKey
wfMemcKey()
Get a cache key.
Definition: GlobalFunctions.php:3635
Block\parseTarget
static parseTarget( $target)
From an existing Block, get the target and the type of target.
Definition: Block.php:1211
Block\getRangeCond
static getRangeCond( $start, $end=null)
Get a set of SQL conditions which will select rangeblocks encompassing a given range.
Definition: Block.php:279
Block\doAutoblock
doAutoblock( $autoblockIP)
Autoblocks the given IP, referring to this Block.
Definition: Block.php:651
Block\TYPE_ID
const TYPE_ID
Definition: Block.php:51
Block\__construct
__construct( $address='', $user=0, $by=0, $reason='', $timestamp=0, $auto=0, $expiry='', $anonOnly=0, $createAccount=0, $enableAutoblock=0, $hideName=0, $blockEmail=0, $allowUsertalk=0, $byText='')
Constructor.
Definition: Block.php:58
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4066
Block\isWhitelistedFromAutoblocks
static isWhitelistedFromAutoblocks( $ip)
Checks whether a given IP is on the autoblock whitelist.
Definition: Block.php:608
$lines
$lines
Definition: router.php:65
Block\getAutoblockUpdateArray
getAutoblockUpdateArray()
Definition: Block.php:526
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
IP\isInRange
static isInRange( $addr, $range)
Determine if a given IPv4/IPv6 address is in a given CIDR network.
Definition: IP.php:717
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2561
Block\isAutoblocking
isAutoblocking( $x=null)
Definition: Block.php:876
$allowUsertalk
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks this Boolean value will be checked to determine if the password was valid return false to implement your own hashing method this String will be used as the hash which may be added to this hook is run right before returning the options to the caller which means it s potentially called dozens or hundreds of times You may want to cache the results of non trivial operations in your hook function for this reason change this to override email change this to override email authentication timestamp whether or not the user is blocked from that page & $allowUsertalk
Definition: hooks.txt:2708
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Block\getBlocksForIPList
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
Definition: Block.php:1027
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
Block\getTargetAndType
getTargetAndType()
Get the target and target type for this particular Block.
Definition: Block.php:1280
$line
$line
Definition: cdb.php:57
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2478
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
Block\doRetroactiveAutoblock
doRetroactiveAutoblock()
Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
Definition: Block.php:543
Block\$mCreateAccount
$mCreateAccount
Definition: Block.php:26
$size
$size
Definition: RandomTest.php:75
Block\$isAutoblocking
Bool $isAutoblocking
Definition: Block.php:44
Block\updateTimestamp
updateTimestamp()
Update the timestamp on autoblocks.
Definition: Block.php:763
IP\parseRange
static parseRange( $range)
Given a string range in a number of formats, return the start and end of the range in hexadecimal.
Definition: IP.php:574
Block\getBlocker
getBlocker()
Get the user who implemented this block.
Definition: Block.php:1315
Block\setBlocker
setBlocker( $user)
Set the user who implemented (or will implement) this block.
Definition: Block.php:1323
Block\$blocker
User $blocker
Definition: Block.php:40
Block\fromMaster
fromMaster( $x=null)
Get/set a flag determining whether the master is used for reads.
Definition: Block.php:858
Block\getTarget
getTarget()
Get the target for this particular Block.
Definition: Block.php:1290
Block\purgeExpired
static purgeExpired()
Purge expired blocks from the ipblocks table.
Definition: Block.php:954
Block\TYPE_AUTO
const TYPE_AUTO
Definition: Block.php:50
IP\isValid
static isValid( $ip)
Validate an IP address.
Definition: IP.php:108
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
wfIsTrustedProxy
wfIsTrustedProxy( $ip)
Checks if an IP is a trusted proxy provider.
Definition: GlobalFunctions.php:4221
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
Block\TYPE_USER
const TYPE_USER
Definition: Block.php:47
Block\$mHideName
$mHideName
Definition: Block.php:23
Block\$target
User String $target
Definition: Block.php:34
IP\sanitizeIP
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:135
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
type
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:22
Block\selectFields
static selectFields()
Return the list of ipblocks fields that should be selected to create a new block.
Definition: Block.php:124
TS_UNIX
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: GlobalFunctions.php:2473
Block\$mBlockEmail
$mBlockEmail
Definition: Block.php:26
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Block
Definition: Block.php:22
User
User
Definition: All_system_messages.txt:425
Block\getRangeStart
getRangeStart()
Get the IP address at the start of the range in Hex form.
Definition: Block.php:787
Block\getPermissionsError
getPermissionsError(IContextSource $context)
Get the key and parameters for the corresponding error message.
Definition: Block.php:1334
IContextSource\getRequest
getRequest()
Get the WebRequest object.
Block\getDatabaseArray
getDatabaseArray( $db=null)
Get an array suitable for passing to $dbw->insert() or $dbw->update()
Definition: Block.php:488
Block\getByName
getByName()
Get the username of the blocking sysop.
Definition: Block.php:837
Block\$mParentBlockId
$mParentBlockId
Definition: Block.php:26
Block\$mAuto
$mAuto
Definition: Block.php:23
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:121
Block\newFromRow
static newFromRow( $row)
Create a new Block object from a database row.
Definition: Block.php:362
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
IP\isValidBlock
static isValidBlock( $ipblock)
Validate an IP Block (valid address WITH a valid prefix).
Definition: IP.php:121
$res
$res
Definition: database.txt:21
Block\$mTimestamp
$mTimestamp
Definition: Block.php:23
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:1876
Block\defaultRetroactiveAutoblock
static defaultRetroactiveAutoblock(Block $block, array &$blockIds)
Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
Definition: Block.php:567
IP\sanitizeRange
static sanitizeRange( $range)
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111....
Definition: IP.php:773
Block\$forcedTargetID
Integer $forcedTargetID
Hack for foreign blocking (CentralAuth) *.
Definition: Block.php:36
Block\setTarget
setTarget( $target)
Set the target for this block, and update $this->type accordingly.
Definition: Block.php:1307
Block\$mId
$mId
Definition: Block.php:26
IContextSource\getLanguage
getLanguage()
Get the Language object.
Block\getAutoblockExpiry
static getAutoblockExpiry( $timestamp)
Get a timestamp of the expiry for autoblocks.
Definition: Block.php:945