125 'createAccount' =>
false,
126 'enableAutoblock' =>
false,
128 'blockEmail' =>
false,
129 'allowUsertalk' =>
false,
131 'systemBlock' =>
null,
134 if ( func_num_args() > 1 || !is_array(
$options ) ) {
136 array_slice( array_keys( $defaults ), 0, func_num_args() ),
139 wfDeprecated( __METHOD__ .
' with multiple arguments',
'1.26' );
146 if ( $this->target instanceof
User &&
$options[
'user'] ) {
147 # Needed for foreign users
148 $this->forcedTargetID =
$options[
'user'];
159 $this->mReason =
$options[
'reason'];
164 $this->mAuto = (bool)
$options[
'auto'];
165 $this->mHideName = (bool)
$options[
'hideName'];
169 # Prevention measures
170 $this->
prevents(
'sendemail', (
bool)$options[
'blockEmail'] );
171 $this->
prevents(
'editownusertalk', !$options[
'allowUsertalk'] );
172 $this->
prevents(
'createaccount', (
bool)$options[
'createAccount'] );
174 $this->mFromMaster =
false;
175 $this->systemBlockType =
$options[
'systemBlock'];
188 $blockQuery[
'tables'],
189 $blockQuery[
'fields'],
216 throw new BadMethodCallException(
217 'Cannot use ' . __METHOD__ .
' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
231 'ipb_create_account',
232 'ipb_enable_autoblock',
236 'ipb_allow_usertalk',
237 'ipb_parent_block_id',
238 ] + CommentStore::getStore()->getFields(
'ipb_reason' );
251 $commentQuery = CommentStore::getStore()->getJoin(
'ipb_reason' );
252 $actorQuery = ActorMigration::newMigration()->getJoin(
'ipb_by' );
254 'tables' => [
'ipblocks' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
261 'ipb_create_account',
262 'ipb_enable_autoblock',
266 'ipb_allow_usertalk',
267 'ipb_parent_block_id',
268 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
269 'joins' => $commentQuery[
'joins'] + $actorQuery[
'joins'],
283 (
string)$this->target == (
string)$block->target
284 && $this->type == $block->type
285 && $this->mAuto == $block->mAuto
287 && $this->prevents(
'createaccount' ) == $block->
prevents(
'createaccount' )
288 && $this->mExpiry == $block->mExpiry
290 && $this->mHideName == $block->mHideName
292 && $this->prevents(
'editownusertalk' ) == $block->
prevents(
'editownusertalk' )
293 && $this->mReason == $block->mReason
307 protected function newLoad( $vagueTarget =
null ) {
310 if ( $this->
type !==
null ) {
312 'ipb_address' => [ (
string)$this->target ],
315 $conds = [
'ipb_address' => [] ];
318 # Be aware that the != '' check is explicit, since empty values will be
319 # passed by some callers (T31116)
320 if ( $vagueTarget !=
'' ) {
324 # Slightly weird, but who are we to argue?
331 $conds = $db->makeList( $conds,
LIST_OR );
338 $conds = $db->makeList( $conds,
LIST_OR );
342 throw new MWException(
"Tried to load block with invalid type" );
348 $blockQuery[
'tables'], $blockQuery[
'fields'], $conds, __METHOD__, [], $blockQuery[
'joins']
351 # This result could contain a block on the user, a block on the IP, and a russian-doll
352 # set of rangeblocks. We want to choose the most specific one, so keep a leader board.
355 # Lower will be better
356 $bestBlockScore = 100;
358 # This is begging for $this = $bestBlock, but that's not allowed in PHP :(
359 $bestBlockPreventsEdit =
null;
361 foreach (
$res as $row ) {
364 # Don't use expired blocks
365 if ( $block->isExpired() ) {
369 # Don't use anon only blocks on users
370 if ( $this->
type == self::TYPE_USER && !$block->isHardblock() ) {
374 if ( $block->getType() == self::TYPE_RANGE ) {
375 # This is the number of bits that are allowed to vary in the block, give
376 # or take some floating point errors
377 $end = Wikimedia\base_convert( $block->getRangeEnd(), 16, 10 );
378 $start = Wikimedia\base_convert( $block->getRangeStart(), 16, 10 );
379 $size = log( $end - $start + 1, 2 );
381 # This has the nice property that a /32 block is ranked equally with a
382 # single-IP block, which is exactly what it is...
383 $score = self::TYPE_RANGE - 1 + ( $size / 128 );
386 $score = $block->getType();
389 if ( $score < $bestBlockScore ) {
390 $bestBlockScore = $score;
392 $bestBlockPreventsEdit = $block->prevents(
'edit' );
396 if ( $bestRow !==
null ) {
398 $this->
prevents(
'edit', $bestBlockPreventsEdit );
412 if ( $end ===
null ) {
415 # Per T16634, we want to include relevant active rangeblocks; for
416 # rangeblocks, we want to include larger ranges which enclose the given
417 # range. We know that all blocks must be smaller than $wgBlockCIDRLimit,
418 # so we can improve performance by filtering on a LIKE clause
421 $like =
$dbr->buildLike( $chunk,
$dbr->anyString() );
423 # Fairly hard to make a malicious SQL statement out of hex characters,
424 # but stranger things have happened...
425 $safeStart =
$dbr->addQuotes( $start );
426 $safeEnd =
$dbr->addQuotes( $end );
428 return $dbr->makeList(
430 "ipb_range_start $like",
431 "ipb_range_start <= $safeStart",
432 "ipb_range_end >= $safeEnd",
446 if ( substr( $hex, 0, 3 ) ==
'v6-' ) {
447 return 'v6-' . substr( substr( $hex, 3 ), 0, floor(
$wgBlockCIDRLimit[
'IPv6'] / 4 ) );
461 $row->ipb_by, $row->ipb_by_text, isset( $row->ipb_by_actor ) ? $row->ipb_by_actor : null
464 $this->mTimestamp =
wfTimestamp( TS_MW, $row->ipb_timestamp );
465 $this->mAuto = $row->ipb_auto;
466 $this->mHideName = $row->ipb_deleted;
467 $this->mId = (int)$row->ipb_id;
468 $this->mParentBlockId = $row->ipb_parent_block_id;
472 $this->mExpiry = $db->decodeExpiry( $row->ipb_expiry );
473 $this->mReason = CommentStore::getStore()
475 ->getCommentLegacy( $db,
'ipb_reason', $row )->text;
480 $this->
prevents(
'createaccount', $row->ipb_create_account );
481 $this->
prevents(
'sendemail', $row->ipb_block_email );
482 $this->
prevents(
'editownusertalk', !$row->ipb_allow_usertalk );
502 public function delete() {
507 if ( !$this->
getId() ) {
508 throw new MWException(
"Block::delete() requires that the mId member be filled\n" );
512 $dbw->delete(
'ipblocks', [
'ipb_parent_block_id' => $this->
getId() ], __METHOD__ );
513 $dbw->delete(
'ipblocks', [
'ipb_id' => $this->
getId() ], __METHOD__ );
515 return $dbw->affectedRows() > 0;
530 throw new MWException(
'Cannot insert a system block into the database' );
533 throw new MWException(
'Cannot insert a block without a blocker set' );
536 wfDebug(
"Block::insert; timestamp {$this->mTimestamp}\n" );
538 if ( $dbw ===
null ) {
546 $dbw->insert(
'ipblocks', $row, __METHOD__, [
'IGNORE' ] );
547 $affected = $dbw->affectedRows();
548 $this->mId = $dbw->insertId();
550 # Don't collide with expired blocks.
551 # Do this after trying to insert to avoid locking.
553 # T96428: The ipb_address index uses a prefix on a field, so
554 # use a standard SELECT + DELETE to avoid annoying gap locks.
555 $ids = $dbw->selectFieldValues(
'ipblocks',
558 'ipb_address' => $row[
'ipb_address'],
559 'ipb_user' => $row[
'ipb_user'],
560 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() )
565 $dbw->delete(
'ipblocks', [
'ipb_id' => $ids ], __METHOD__ );
566 $dbw->insert(
'ipblocks', $row, __METHOD__, [
'IGNORE' ] );
567 $affected = $dbw->affectedRows();
568 $this->mId = $dbw->insertId();
575 if ( $wgBlockDisablesLogin && $this->target instanceof
User ) {
577 $this->target->setToken();
578 $this->target->saveSettings();
581 return [
'id' =>
$this->mId,
'autoIds' => $auto_ipd_ids ];
595 wfDebug(
"Block::update; timestamp {$this->mTimestamp}\n" );
598 $dbw->startAtomic( __METHOD__ );
603 [
'ipb_id' => $this->
getId() ],
607 $affected = $dbw->affectedRows();
614 [
'ipb_parent_block_id' => $this->
getId() ],
621 [
'ipb_parent_block_id' => $this->
getId() ],
626 $dbw->endAtomic( __METHOD__ );
630 return [
'id' =>
$this->mId,
'autoIds' => $auto_ipd_ids ];
644 if ( $this->forcedTargetID ) {
647 $uid = $this->target instanceof
User ? $this->target->
getId() : 0;
651 'ipb_address' => (
string)$this->target,
653 'ipb_timestamp' => $dbw->
timestamp( $this->mTimestamp ),
656 'ipb_create_account' => $this->
prevents(
'createaccount' ),
658 'ipb_expiry' => $expiry,
661 'ipb_deleted' => intval( $this->mHideName ),
662 'ipb_block_email' => $this->
prevents(
'sendemail' ),
663 'ipb_allow_usertalk' => !$this->
prevents(
'editownusertalk' ),
665 ] + CommentStore::getStore()->insert( $dbw,
'ipb_reason', $this->mReason )
666 + ActorMigration::newMigration()->getInsertValues( $dbw,
'ipb_by', $this->
getBlocker() );
677 'ipb_create_account' => $this->
prevents(
'createaccount' ),
678 'ipb_deleted' => (int)$this->mHideName,
679 'ipb_allow_usertalk' => !$this->
prevents(
'editownusertalk' ),
680 ] + CommentStore::getStore()->insert( $dbw,
'ipb_reason', $this->mReason )
681 + ActorMigration::newMigration()->getInsertValues( $dbw,
'ipb_by', $this->
getBlocker() );
692 # If autoblock is enabled, autoblock the LAST IP(s) used
696 $continue = Hooks::run(
697 'PerformRetroactiveAutoblock', [ $this, &$blockIds ] );
727 $rcQuery = ActorMigration::newMigration()->getWhere(
$dbr,
'rc_user',
$target,
false );
729 $options = [
'ORDER BY' =>
'rc_timestamp DESC' ];
735 [
'recentchanges' ] + $rcQuery[
'tables'],
743 if ( !
$res->numRows() ) {
744 # No results, don't autoblock anything
745 wfDebug(
"No IP found to retroactively autoblock\n" );
747 foreach (
$res as $row ) {
768 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
770 $cache->makeKey(
'ip-autoblock',
'whitelist' ),
772 function ( $curValue, &$ttl, array &$setOpts ) {
775 return explode(
"\n",
776 wfMessage(
'autoblock_whitelist' )->inContentLanguage()->
plain() );
780 wfDebug(
"Checking the autoblock whitelist..\n" );
784 if ( substr(
$line, 0, 1 ) !==
'*' ) {
788 $wlEntry = substr(
$line, 1 );
789 $wlEntry = trim( $wlEntry );
791 wfDebug(
"Checking $ip against $wlEntry..." );
793 # Is the IP in this range?
794 if ( IP::isInRange( $ip, $wlEntry ) ) {
795 wfDebug(
" IP $ip matches $wlEntry, not autoblocking\n" );
812 # If autoblocks are disabled, go away.
817 # Don't autoblock for system blocks
819 throw new MWException(
'Cannot autoblock from a system block' );
822 # Check for presence on the autoblock whitelist.
823 if ( self::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
829 # Allow hooks to cancel the autoblock.
830 if ( !Hooks::run(
'AbortAutoblock', [ $autoblockIP, &$block ] ) ) {
831 wfDebug(
"Autoblock aborted by hook.\n" );
835 # It's okay to autoblock. Go ahead and insert/update the block...
837 # Do not add a *new* block if the IP is already blocked.
840 # Check if the block is an autoblock and would exceed the user block
841 # if renewed. If so, do nothing, otherwise prolong the block time...
842 if ( $ipblock->mAuto &&
843 $this->mExpiry > self::getAutoblockExpiry( $ipblock->mTimestamp )
845 # Reset block timestamp to now and its expiry to
846 # $wgAutoblockExpiry in the future
847 $ipblock->updateTimestamp();
852 # Make a new block object with the desired properties.
853 $autoblock =
new Block;
854 wfDebug(
"Autoblocking {$this->getTarget()}@" . $autoblockIP .
"\n" );
855 $autoblock->setTarget( $autoblockIP );
856 $autoblock->setBlocker( $this->
getBlocker() );
858 ->inContentLanguage()->plain();
860 $autoblock->mTimestamp = $timestamp;
861 $autoblock->mAuto = 1;
862 $autoblock->prevents(
'createaccount', $this->
prevents(
'createaccount' ) );
863 # Continue suppressing the name if needed
865 $autoblock->prevents(
'editownusertalk', $this->
prevents(
'editownusertalk' ) );
868 if ( $this->mExpiry ==
'infinity' ) {
869 # Original block was indefinite, start an autoblock now
872 # If the user is already blocked with an expiry date, we don't
873 # want to pile on top of that.
874 $autoblock->mExpiry = min( $this->mExpiry, self::getAutoblockExpiry( $timestamp ) );
877 # Insert the block...
878 $status = $autoblock->insert();
890 wfDebug(
"Block::deleteIfExpired() -- deleting\n" );
894 wfDebug(
"Block::deleteIfExpired() -- not expired\n" );
907 wfDebug(
"Block::isExpired() checking current " . $timestamp .
" vs $this->mExpiry\n" );
909 if ( !$this->mExpiry ) {
928 if ( $this->mAuto ) {
933 $dbw->update(
'ipblocks',
935 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
936 'ipb_expiry' => $dbw->timestamp( $this->mExpiry ),
939 'ipb_id' => $this->getId(),
952 switch ( $this->
type ) {
956 return IP::toHex( $this->target );
958 list( $start, ) = IP::parseRange( $this->target );
961 throw new MWException(
"Block with invalid type" );
971 switch ( $this->
type ) {
975 return IP::toHex( $this->target );
977 list( , $end ) = IP::parseRange( $this->target );
980 throw new MWException(
"Block with invalid type" );
1032 return wfSetVar( $this->mFromMaster, $x );
1043 # You can't *not* hardblock a user
1044 return $this->
getType() == self::TYPE_USER
1056 # You can't put an autoblock on an IP or range as we don't have any history to
1057 # look over to get more IPs from
1058 return $this->
getType() == self::TYPE_USER
1073 switch ( $action ) {
1075 # For now... <evil laugh>
1078 case 'createaccount':
1084 case 'editownusertalk':
1106 if ( $this->mAuto ) {
1107 return Html::rawElement(
1109 [
'class' =>
'mw-autoblockid' ],
1113 return htmlspecialchars( $this->
getTarget() );
1147 $dbw->
delete(
'ipblocks', [
'ipb_id' => $ids ],
$fname );
1173 public static function newFromTarget( $specificTarget, $vagueTarget =
null, $fromMaster =
false ) {
1175 if (
$type == self::TYPE_ID ||
$type == self::TYPE_AUTO ) {
1178 } elseif (
$target ===
null && $vagueTarget ==
'' ) {
1179 # We're not going to find anything useful here
1180 # Be aware that the == '' check is explicit, since empty values will be
1181 # passed by some callers (T31116)
1184 } elseif ( in_array(
1186 [ self::TYPE_USER, self::TYPE_IP, self::TYPE_RANGE,
null ] )
1188 $block =
new Block();
1189 $block->fromMaster( $fromMaster );
1191 if (
$type !==
null ) {
1195 if ( $block->newLoad( $vagueTarget ) ) {
1213 if ( !count( $ipChain ) ) {
1218 $proxyLookup = MediaWikiServices::getInstance()->getProxyLookup();
1219 foreach ( array_unique( $ipChain ) as $ipaddr ) {
1220 # Discard invalid IP addresses. Since XFF can be spoofed and we do not
1221 # necessarily trust the header given to us, make sure that we are only
1222 # checking for blocks on well-formatted IP addresses (IPv4 and IPv6).
1223 # Do not treat private IP spaces as special as it may be desirable for wikis
1224 # to block those IP ranges in order to stop misbehaving proxies that spoof XFF.
1225 if ( !IP::isValid( $ipaddr ) ) {
1228 # Don't check trusted IPs (includes local squids which will be in every request)
1229 if ( $proxyLookup->isTrustedProxy( $ipaddr ) ) {
1232 # Check both the original IP (to check against single blocks), as well as build
1233 # the clause to check for rangeblocks for the given IP.
1234 $conds[
'ipb_address'][] = $ipaddr;
1238 if ( !count( $conds ) ) {
1242 if ( $fromMaster ) {
1247 $conds = $db->makeList( $conds,
LIST_OR );
1249 $conds = [ $conds,
'ipb_anon_only' => 0 ];
1252 $rows = $db->select(
1253 $blockQuery[
'tables'],
1254 array_merge( [
'ipb_range_start',
'ipb_range_end' ], $blockQuery[
'fields'] ),
1258 $blockQuery[
'joins']
1262 foreach (
$rows as $row ) {
1264 if ( !$block->isExpired() ) {
1294 if ( !count( $blocks ) ) {
1296 } elseif ( count( $blocks ) == 1 ) {
1302 usort( $blocks,
function (
Block $a,
Block $b ) {
1303 $aWeight = (int)$a->isHardblock() . (int)$a->prevents(
'createaccount' );
1304 $bWeight = (int)$b->isHardblock() . (int)$b->prevents(
'createaccount' );
1305 return strcmp( $bWeight, $aWeight );
1308 $blocksListExact = [
1310 'disable_create' =>
false,
1314 $blocksListRange = [
1316 'disable_create' =>
false,
1320 $ipChain = array_reverse( $ipChain );
1323 foreach ( $blocks as $block ) {
1326 if ( !$block->isHardblock() && $blocksListExact[
'hard'] ) {
1328 } elseif ( !$block->prevents(
'createaccount' ) && $blocksListExact[
'disable_create'] ) {
1332 foreach ( $ipChain as $checkip ) {
1333 $checkipHex = IP::toHex( $checkip );
1334 if ( (
string)$block->getTarget() === $checkip ) {
1335 if ( $block->isHardblock() ) {
1336 $blocksListExact[
'hard'] = $blocksListExact[
'hard'] ?: $block;
1337 } elseif ( $block->prevents(
'createaccount' ) ) {
1338 $blocksListExact[
'disable_create'] = $blocksListExact[
'disable_create'] ?: $block;
1339 } elseif ( $block->mAuto ) {
1340 $blocksListExact[
'auto'] = $blocksListExact[
'auto'] ?: $block;
1342 $blocksListExact[
'other'] = $blocksListExact[
'other'] ?: $block;
1346 } elseif ( array_filter( $blocksListExact ) == []
1347 && $block->getRangeStart() <= $checkipHex
1348 && $block->getRangeEnd() >= $checkipHex
1350 if ( $block->isHardblock() ) {
1351 $blocksListRange[
'hard'] = $blocksListRange[
'hard'] ?: $block;
1352 } elseif ( $block->prevents(
'createaccount' ) ) {
1353 $blocksListRange[
'disable_create'] = $blocksListRange[
'disable_create'] ?: $block;
1354 } elseif ( $block->mAuto ) {
1355 $blocksListRange[
'auto'] = $blocksListRange[
'auto'] ?: $block;
1357 $blocksListRange[
'other'] = $blocksListRange[
'other'] ?: $block;
1364 if ( array_filter( $blocksListExact ) == [] ) {
1365 $blocksList = &$blocksListRange;
1367 $blocksList = &$blocksListExact;
1370 $chosenBlock =
null;
1371 if ( $blocksList[
'hard'] ) {
1372 $chosenBlock = $blocksList[
'hard'];
1373 } elseif ( $blocksList[
'disable_create'] ) {
1374 $chosenBlock = $blocksList[
'disable_create'];
1375 } elseif ( $blocksList[
'other'] ) {
1376 $chosenBlock = $blocksList[
'other'];
1377 } elseif ( $blocksList[
'auto'] ) {
1378 $chosenBlock = $blocksList[
'auto'];
1380 throw new MWException(
"Proxy block found, but couldn't be classified." );
1383 return $chosenBlock;
1396 # We may have been through this before
1403 } elseif (
$target ===
null ) {
1404 return [
null, null ];
1409 if ( IP::isValid(
$target ) ) {
1410 # We can still create a User if it's an IP address, but we need to turn
1411 # off validation checking (which would exclude IP addresses)
1417 } elseif ( IP::isValidRange(
$target ) ) {
1418 # Can't create a User from an IP range
1422 # Consider the possibility that this is not a username at all
1423 # but actually an old subpage (bug #29797)
1424 if ( strpos(
$target,
'/' ) !==
false ) {
1425 # An old subpage, drill down to the user behind it
1430 if ( $userObj instanceof
User ) {
1431 # Note that since numbers are valid usernames, a $target of "12345" will be
1432 # considered a User. If you want to pass a block ID, prepend a hash "#12345",
1433 # since hash characters are not valid in usernames or titles generally.
1436 } elseif ( preg_match(
'/^#\d+$/',
$target ) ) {
1437 # Autoblock reference in the form "#12345"
1442 return [
null, null ];
1507 if ( is_string( $user ) ) {
1512 throw new InvalidArgumentException(
1513 'Blocker must be a local user or a name that cannot be a local user'
1517 $this->blocker =
$user;
1539 $expiryValue = DateTime::createFromFormat(
'YmdHis',
$expiryTime )->format(
'U' );
1540 $cookieOptions = [
'httpOnly' =>
false ];
1542 $response->
setCookie(
'BlockID', $cookieValue, $expiryValue, $cookieOptions );
1553 $response->clearCookie(
'BlockID', [
'httpOnly' =>
false ] );
1567 $id = $this->
getId();
1568 $secretKey = $config->get(
'SecretKey' );
1569 if ( !$secretKey ) {
1574 $cookieValue = $id .
'!' . $hmac;
1575 return $cookieValue;
1590 $bangPos = strpos( $cookieValue,
'!' );
1591 $id = ( $bangPos ===
false ) ? $cookieValue : substr( $cookieValue, 0, $bangPos );
1594 $secretKey = $config->get(
'SecretKey' );
1595 if ( !$secretKey ) {
1599 $storedHmac = substr( $cookieValue, $bangPos + 1 );
1601 if ( $calculatedHmac === $storedHmac ) {
1619 $link =
"[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
1625 if ( $reason ==
'' ) {
1626 $reason =
$context->msg(
'blockednoreason' )->text();
1638 ?
'systemblockedtext'
1639 : ( $this->mAuto ?
'autoblockedtext' :
'blockedtext' ),
1645 $lang->formatExpiry( $this->mExpiry ),
1647 $lang->userTimeAndDate( $this->mTimestamp,
$context->getUser() ),
$wgAutoblockExpiry
Number of seconds before autoblock entries expire.
$wgBlockCIDRLimit
Limits on the possible sizes of range blocks.
$wgPutIPinRC
Log IP addresses in the recentchanges table; can be accessed only by extensions (e....
$wgBlockDisablesLogin
If true, blocked users will not be allowed to login.
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfReadOnly()
Check whether the wiki is in read-only mode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Deferrable Update for closure/callback updates that should use auto-commit mode.
int $forcedTargetID
Hack for foreign blocking (CentralAuth)
static selectFields()
Return the list of ipblocks fields that should be selected to create a new block.
setCookie(WebResponse $response)
Set the 'BlockID' cookie to this block's ID and expiry time.
getPermissionsError(IContextSource $context)
Get the key and parameters for the corresponding error message.
static clearCookie(WebResponse $response)
Unset the 'BlockID' cookie.
insert( $dbw=null)
Insert a block into the block table.
static getRangeCond( $start, $end=null)
Get a set of SQL conditions which will select rangeblocks encompassing a given range.
newLoad( $vagueTarget=null)
Load a block from the database which affects the already-set $this->target: 1) A block directly on th...
update()
Update a block in the DB with new parameters.
prevents( $action, $x=null)
Get/set whether the Block prevents a given action.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new block object.
static newFromRow( $row)
Create a new Block object from a database row.
getDatabaseArray(IDatabase $dbw)
Get an array suitable for passing to $dbw->insert() or $dbw->update()
isHardblock( $x=null)
Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range)
isValid()
Is the block address valid (i.e.
setBlocker( $user)
Set the user who implemented (or will implement) this block.
getRedactedName()
Get the block name, but with autoblocked IPs hidden as per standard privacy policy.
isExpired()
Has the block expired?
static newFromID( $id)
Load a blocked user from their block id.
static getAutoblockExpiry( $timestamp)
Get a timestamp of the expiry for autoblocks.
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
getRangeEnd()
Get the IP address at the end of the range in Hex form.
getAutoblockUpdateArray(IDatabase $dbw)
static getIpFragment( $hex)
Get the component of an IP address which is certain to be the same between an IP address and a rangeb...
static parseTarget( $target)
From an existing Block, get the target and the type of target.
string null $systemBlockType
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest Block.
getSystemBlockType()
Get the system block type, if any.
initFromRow( $row)
Given a database row from the ipblocks table, initialize member variables.
static isWhitelistedFromAutoblocks( $ip)
Checks whether a given IP is on the autoblock whitelist.
getType()
Get the type of target for this particular block.
__construct( $options=[])
Create a new block with specified parameters on a user, IP or IP range.
getBy()
Get the user id of the blocking sysop.
setTarget( $target)
Set the target for this block, and update $this->type accordingly.
updateTimestamp()
Update the timestamp on autoblocks.
fromMaster( $x=null)
Get/set a flag determining whether the master is used for reads.
doAutoblock( $autoblockIP)
Autoblocks the given IP, referring to this Block.
deleteIfExpired()
Check if a block has expired.
doRetroactiveAutoblock()
Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
static getIdFromCookieValue( $cookieValue)
Get the stored ID from the 'BlockID' cookie.
getTargetAndType()
Get the target and target type for this particular Block.
getTarget()
Get the target for this particular Block.
static purgeExpired()
Purge expired blocks from the ipblocks table.
getRangeStart()
Get the IP address at the start of the range in Hex form.
getCookieValue()
Get the BlockID cookie's value for this block.
getByName()
Get the username of the blocking sysop.
equals(Block $block)
Check if two blocks are effectively equal.
static defaultRetroactiveAutoblock(Block $block, array &$blockIds)
Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
getBlocker()
Get the user who implemented this block.
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
int $type
Block::TYPE_ constant.
static hmac( $data, $key, $raw=true)
Generate an acceptably unstable one-way-hmac of some text making use of the best hash algorithm that ...
static getMain()
Get the RequestContext object associated with the main request.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getName()
Get the user name, or the IP of an anonymous user.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
isAllowed( $action='')
Internal mechanics of testing a permission.
getId()
Get the user's ID.
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
static newFromId( $id)
Static factory method for creation from a given user ID.
static isUsableName( $name)
Usernames which fail to pass this function will be blocked from user login and new account registrati...
getUserPage()
Get this user's personal page title.
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
setCookie( $name, $value, $expire=0, $options=[])
Set the browser cookie.
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
when a variable name is used in a function
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action or null $user:User who performed the tagging when the tagging is subsequent to the action or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
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
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation 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 "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
usually copyright or history_copyright This message must be in HTML not wikitext & $link
this hook is for auditing only $response
processing should stop and the error should be shown to the user * false
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 local account $user
const MIGRATION_WRITE_BOTH
Interface for objects which can provide a MediaWiki context on request.
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 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
if(!isset( $args[0])) $lang