Go to the documentation of this file.
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 self::selectFields(),
214 'ipb_create_account',
215 'ipb_enable_autoblock',
219 'ipb_allow_usertalk',
220 'ipb_parent_block_id',
234 (
string)$this->target == (
string)$block->target
235 && $this->type == $block->type
236 && $this->mAuto == $block->mAuto
238 && $this->
prevents(
'createaccount' ) == $block->
prevents(
'createaccount' )
239 && $this->mExpiry == $block->mExpiry
241 && $this->mHideName == $block->mHideName
243 && $this->
prevents(
'editownusertalk' ) == $block->
prevents(
'editownusertalk' )
244 && $this->mReason == $block->mReason
258 protected function newLoad( $vagueTarget =
null ) {
261 if ( $this->
type !==
null ) {
263 'ipb_address' => [ (
string)$this->target ],
266 $conds = [
'ipb_address' => [] ];
269 # Be aware that the != '' check is explicit, since empty values will be
270 # passed by some callers (T31116)
271 if ( $vagueTarget !=
'' ) {
275 # Slightly weird, but who are we to argue?
282 $conds = $db->makeList( $conds,
LIST_OR );
289 $conds = $db->makeList( $conds,
LIST_OR );
293 throw new MWException(
"Tried to load block with invalid type" );
297 $res = $db->select(
'ipblocks', self::selectFields(), $conds, __METHOD__ );
299 # This result could contain a block on the user, a block on the IP, and a russian-doll
300 # set of rangeblocks. We want to choose the most specific one, so keep a leader board.
303 # Lower will be better
304 $bestBlockScore = 100;
306 # This is begging for $this = $bestBlock, but that's not allowed in PHP :(
307 $bestBlockPreventsEdit =
null;
309 foreach (
$res as $row ) {
312 # Don't use expired blocks
313 if ( $block->isExpired() ) {
317 # Don't use anon only blocks on users
318 if ( $this->
type == self::TYPE_USER && !$block->isHardblock() ) {
323 # This is the number of bits that are allowed to vary in the block, give
324 # or take some floating point errors
325 $end = Wikimedia\base_convert( $block->getRangeEnd(), 16, 10 );
326 $start = Wikimedia\base_convert( $block->getRangeStart(), 16, 10 );
327 $size = log( $end - $start + 1, 2 );
329 # This has the nice property that a /32 block is ranked equally with a
330 # single-IP block, which is exactly what it is...
331 $score = self::TYPE_RANGE - 1 + ( $size / 128 );
334 $score = $block->getType();
337 if ( $score < $bestBlockScore ) {
338 $bestBlockScore = $score;
340 $bestBlockPreventsEdit = $block->prevents(
'edit' );
344 if ( $bestRow !==
null ) {
346 $this->
prevents(
'edit', $bestBlockPreventsEdit );
360 if ( $end ===
null ) {
363 # Per T16634, we want to include relevant active rangeblocks; for
364 # rangeblocks, we want to include larger ranges which enclose the given
365 # range. We know that all blocks must be smaller than $wgBlockCIDRLimit,
366 # so we can improve performance by filtering on a LIKE clause
369 $like =
$dbr->buildLike( $chunk,
$dbr->anyString() );
371 # Fairly hard to make a malicious SQL statement out of hex characters,
372 # but stranger things have happened...
373 $safeStart =
$dbr->addQuotes( $start );
374 $safeEnd =
$dbr->addQuotes( $end );
376 return $dbr->makeList(
378 "ipb_range_start $like",
379 "ipb_range_start <= $safeStart",
380 "ipb_range_end >= $safeEnd",
394 if ( substr( $hex, 0, 3 ) ==
'v6-' ) {
395 return 'v6-' . substr( substr( $hex, 3 ), 0, floor( $wgBlockCIDRLimit[
'IPv6'] / 4 ) );
397 return substr( $hex, 0, floor( $wgBlockCIDRLimit[
'IPv4'] / 4 ) );
408 if ( $row->ipb_by ) {
414 $this->mReason = $row->ipb_reason;
415 $this->mTimestamp =
wfTimestamp( TS_MW, $row->ipb_timestamp );
416 $this->mAuto = $row->ipb_auto;
417 $this->mHideName = $row->ipb_deleted;
418 $this->mId = (int)$row->ipb_id;
419 $this->mParentBlockId = $row->ipb_parent_block_id;
427 $this->
prevents(
'createaccount', $row->ipb_create_account );
428 $this->
prevents(
'sendemail', $row->ipb_block_email );
429 $this->
prevents(
'editownusertalk', !$row->ipb_allow_usertalk );
449 public function delete() {
454 if ( !$this->
getId() ) {
455 throw new MWException(
"Block::delete() requires that the mId member be filled\n" );
459 $dbw->delete(
'ipblocks', [
'ipb_parent_block_id' => $this->
getId() ], __METHOD__ );
460 $dbw->delete(
'ipblocks', [
'ipb_id' => $this->
getId() ], __METHOD__ );
462 return $dbw->affectedRows() > 0;
474 global $wgBlockDisablesLogin;
477 throw new MWException(
'Cannot insert a system block into the database' );
480 wfDebug(
"Block::insert; timestamp {$this->mTimestamp}\n" );
482 if ( $dbw ===
null ) {
486 # Periodic purge via commit hooks
487 if ( mt_rand( 0, 9 ) == 0 ) {
492 $row[
'ipb_id'] = $dbw->nextSequenceValue(
"ipblocks_ipb_id_seq" );
494 $dbw->insert(
'ipblocks', $row, __METHOD__, [
'IGNORE' ] );
495 $affected = $dbw->affectedRows();
496 $this->mId = $dbw->insertId();
498 # Don't collide with expired blocks.
499 # Do this after trying to insert to avoid locking.
501 # T96428: The ipb_address index uses a prefix on a field, so
502 # use a standard SELECT + DELETE to avoid annoying gap locks.
503 $ids = $dbw->selectFieldValues(
'ipblocks',
506 'ipb_address' => $row[
'ipb_address'],
507 'ipb_user' => $row[
'ipb_user'],
508 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() )
513 $dbw->delete(
'ipblocks', [
'ipb_id' => $ids ], __METHOD__ );
514 $dbw->insert(
'ipblocks', $row, __METHOD__, [
'IGNORE' ] );
515 $affected = $dbw->affectedRows();
516 $this->mId = $dbw->insertId();
523 if ( $wgBlockDisablesLogin && $this->target instanceof
User ) {
525 $this->target->setToken();
526 $this->target->saveSettings();
529 return [
'id' =>
$this->mId,
'autoIds' => $auto_ipd_ids ];
543 wfDebug(
"Block::update; timestamp {$this->mTimestamp}\n" );
546 $dbw->startAtomic( __METHOD__ );
551 [
'ipb_id' => $this->
getId() ],
555 $affected = $dbw->affectedRows();
562 [
'ipb_parent_block_id' => $this->
getId() ],
569 [
'ipb_parent_block_id' => $this->
getId() ],
574 $dbw->endAtomic( __METHOD__ );
578 return [
'id' =>
$this->mId,
'autoIds' => $auto_ipd_ids ];
593 $expiry = $db->encodeExpiry( $this->mExpiry );
595 if ( $this->forcedTargetID ) {
598 $uid = $this->target instanceof
User ? $this->target->
getId() : 0;
602 'ipb_address' => (
string)$this->target,
604 'ipb_by' => $this->
getBy(),
607 'ipb_timestamp' => $db->timestamp( $this->mTimestamp ),
610 'ipb_create_account' => $this->
prevents(
'createaccount' ),
612 'ipb_expiry' => $expiry,
615 'ipb_deleted' => intval( $this->mHideName ),
616 'ipb_block_email' => $this->
prevents(
'sendemail' ),
617 'ipb_allow_usertalk' => !$this->
prevents(
'editownusertalk' ),
629 'ipb_by' => $this->
getBy(),
632 'ipb_create_account' => $this->
prevents(
'createaccount' ),
633 'ipb_deleted' => (int)$this->mHideName,
634 'ipb_allow_usertalk' => !$this->
prevents(
'editownusertalk' ),
646 # If autoblock is enabled, autoblock the LAST IP(s) used
651 'PerformRetroactiveAutoblock', [ $this, &$blockIds ] );
671 if ( !$wgPutIPinRC ) {
677 $options = [
'ORDER BY' =>
'rc_timestamp DESC' ];
683 $res =
$dbr->select(
'recentchanges', [
'rc_ip' ], $conds,
686 if ( !
$res->numRows() ) {
687 # No results, don't autoblock anything
688 wfDebug(
"No IP found to retroactively autoblock\n" );
690 foreach (
$res as $row ) {
711 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
713 wfMemcKey(
'ipb',
'autoblock',
'whitelist' ),
715 function ( $curValue, &$ttl,
array &$setOpts ) {
718 return explode(
"\n",
719 wfMessage(
'autoblock_whitelist' )->inContentLanguage()->
plain() );
723 wfDebug(
"Checking the autoblock whitelist..\n" );
727 if ( substr(
$line, 0, 1 ) !==
'*' ) {
731 $wlEntry = substr(
$line, 1 );
732 $wlEntry = trim( $wlEntry );
734 wfDebug(
"Checking $ip against $wlEntry..." );
736 # Is the IP in this range?
738 wfDebug(
" IP $ip matches $wlEntry, not autoblocking\n" );
755 # If autoblocks are disabled, go away.
760 # Don't autoblock for system blocks
762 throw new MWException(
'Cannot autoblock from a system block' );
765 # Check for presence on the autoblock whitelist.
766 if ( self::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
772 # Allow hooks to cancel the autoblock.
773 if ( !
Hooks::run(
'AbortAutoblock', [ $autoblockIP, &$block ] ) ) {
774 wfDebug(
"Autoblock aborted by hook.\n" );
778 # It's okay to autoblock. Go ahead and insert/update the block...
780 # Do not add a *new* block if the IP is already blocked.
783 # Check if the block is an autoblock and would exceed the user block
784 # if renewed. If so, do nothing, otherwise prolong the block time...
785 if ( $ipblock->mAuto &&
788 # Reset block timestamp to now and its expiry to
789 # $wgAutoblockExpiry in the future
790 $ipblock->updateTimestamp();
795 # Make a new block object with the desired properties.
796 $autoblock =
new Block;
797 wfDebug(
"Autoblocking {$this->getTarget()}@" . $autoblockIP .
"\n" );
798 $autoblock->setTarget( $autoblockIP );
799 $autoblock->setBlocker( $this->
getBlocker() );
801 ->inContentLanguage()->plain();
803 $autoblock->mTimestamp = $timestamp;
804 $autoblock->mAuto = 1;
805 $autoblock->prevents(
'createaccount', $this->
prevents(
'createaccount' ) );
806 # Continue suppressing the name if needed
808 $autoblock->prevents(
'editownusertalk', $this->
prevents(
'editownusertalk' ) );
811 if ( $this->mExpiry ==
'infinity' ) {
812 # Original block was indefinite, start an autoblock now
815 # If the user is already blocked with an expiry date, we don't
816 # want to pile on top of that.
820 # Insert the block...
821 $status = $autoblock->insert();
834 wfDebug(
"Block::deleteIfExpired() -- deleting\n" );
838 wfDebug(
"Block::deleteIfExpired() -- not expired\n" );
851 wfDebug(
"Block::isExpired() checking current " . $timestamp .
" vs $this->mExpiry\n" );
853 if ( !$this->mExpiry ) {
872 if ( $this->mAuto ) {
877 $dbw->update(
'ipblocks',
879 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
880 'ipb_expiry' => $dbw->timestamp( $this->mExpiry ),
883 'ipb_id' => $this->
getId(),
896 switch ( $this->
type ) {
905 throw new MWException(
"Block with invalid type" );
915 switch ( $this->
type ) {
924 throw new MWException(
"Block with invalid type" );
975 return wfSetVar( $this->mFromMaster, $x );
986 # You can't *not* hardblock a user
987 return $this->
getType() == self::TYPE_USER
999 # You can't put an autoblock on an IP or range as we don't have any history to
1000 # look over to get more IPs from
1001 return $this->
getType() == self::TYPE_USER
1014 global $wgBlockDisablesLogin;
1016 switch ( $action ) {
1018 # For now... <evil laugh>
1021 case 'createaccount':
1027 case 'editownusertalk':
1034 if ( !
$res && $wgBlockDisablesLogin ) {
1038 $res = $anon->isAllowed( $action ) ?
$res :
true;
1049 if ( $this->mAuto ) {
1052 [
'class' =>
'mw-autoblockid' ],
1056 return htmlspecialchars( $this->
getTarget() );
1067 global $wgAutoblockExpiry;
1113 public static function newFromTarget( $specificTarget, $vagueTarget =
null, $fromMaster =
false ) {
1119 } elseif (
$target ===
null && $vagueTarget ==
'' ) {
1120 # We're not going to find anything useful here
1121 # Be aware that the == '' check is explicit, since empty values will be
1122 # passed by some callers (T31116)
1125 } elseif ( in_array(
1129 $block =
new Block();
1130 $block->fromMaster( $fromMaster );
1132 if (
$type !==
null ) {
1136 if ( $block->newLoad( $vagueTarget ) ) {
1154 if ( !
count( $ipChain ) ) {
1159 $proxyLookup = MediaWikiServices::getInstance()->getProxyLookup();
1160 foreach ( array_unique( $ipChain )
as $ipaddr ) {
1161 # Discard invalid IP addresses. Since XFF can be spoofed and we do not
1162 # necessarily trust the header given to us, make sure that we are only
1163 # checking for blocks on well-formatted IP addresses (IPv4 and IPv6).
1164 # Do not treat private IP spaces as special as it may be desirable for wikis
1165 # to block those IP ranges in order to stop misbehaving proxies that spoof XFF.
1169 # Don't check trusted IPs (includes local squids which will be in every request)
1170 if ( $proxyLookup->isTrustedProxy( $ipaddr ) ) {
1173 # Check both the original IP (to check against single blocks), as well as build
1174 # the clause to check for rangeblocks for the given IP.
1175 $conds[
'ipb_address'][] = $ipaddr;
1179 if ( !
count( $conds ) ) {
1183 if ( $fromMaster ) {
1188 $conds = $db->makeList( $conds,
LIST_OR );
1190 $conds = [ $conds,
'ipb_anon_only' => 0 ];
1192 $selectFields = array_merge(
1193 [
'ipb_range_start',
'ipb_range_end' ],
1196 $rows = $db->select(
'ipblocks',
1203 foreach ( $rows
as $row ) {
1205 if ( !$block->isExpired() ) {
1235 if ( !
count( $blocks ) ) {
1237 } elseif (
count( $blocks ) == 1 ) {
1243 usort( $blocks,
function (
Block $a,
Block $b ) {
1246 return strcmp( $bWeight, $aWeight );
1249 $blocksListExact = [
1251 'disable_create' =>
false,
1255 $blocksListRange = [
1257 'disable_create' =>
false,
1261 $ipChain = array_reverse( $ipChain );
1264 foreach ( $blocks
as $block ) {
1267 if ( !$block->isHardblock() && $blocksListExact[
'hard'] ) {
1269 } elseif ( !$block->prevents(
'createaccount' ) && $blocksListExact[
'disable_create'] ) {
1273 foreach ( $ipChain
as $checkip ) {
1275 if ( (
string)$block->getTarget() === $checkip ) {
1276 if ( $block->isHardblock() ) {
1277 $blocksListExact[
'hard'] = $blocksListExact[
'hard'] ?: $block;
1278 } elseif ( $block->prevents(
'createaccount' ) ) {
1279 $blocksListExact[
'disable_create'] = $blocksListExact[
'disable_create'] ?: $block;
1280 } elseif ( $block->mAuto ) {
1281 $blocksListExact[
'auto'] = $blocksListExact[
'auto'] ?: $block;
1283 $blocksListExact[
'other'] = $blocksListExact[
'other'] ?: $block;
1287 } elseif ( array_filter( $blocksListExact ) == []
1288 && $block->getRangeStart() <= $checkipHex
1289 && $block->getRangeEnd() >= $checkipHex
1291 if ( $block->isHardblock() ) {
1292 $blocksListRange[
'hard'] = $blocksListRange[
'hard'] ?: $block;
1293 } elseif ( $block->prevents(
'createaccount' ) ) {
1294 $blocksListRange[
'disable_create'] = $blocksListRange[
'disable_create'] ?: $block;
1295 } elseif ( $block->mAuto ) {
1296 $blocksListRange[
'auto'] = $blocksListRange[
'auto'] ?: $block;
1298 $blocksListRange[
'other'] = $blocksListRange[
'other'] ?: $block;
1305 if ( array_filter( $blocksListExact ) == [] ) {
1306 $blocksList = &$blocksListRange;
1308 $blocksList = &$blocksListExact;
1311 $chosenBlock =
null;
1312 if ( $blocksList[
'hard'] ) {
1313 $chosenBlock = $blocksList[
'hard'];
1314 } elseif ( $blocksList[
'disable_create'] ) {
1315 $chosenBlock = $blocksList[
'disable_create'];
1316 } elseif ( $blocksList[
'other'] ) {
1317 $chosenBlock = $blocksList[
'other'];
1318 } elseif ( $blocksList[
'auto'] ) {
1319 $chosenBlock = $blocksList[
'auto'];
1321 throw new MWException(
"Proxy block found, but couldn't be classified." );
1324 return $chosenBlock;
1337 # We may have been through this before
1344 } elseif (
$target ===
null ) {
1345 return [
null, null ];
1351 # We can still create a User if it's an IP address, but we need to turn
1352 # off validation checking (which would exclude IP addresses)
1359 # Can't create a User from an IP range
1363 # Consider the possibility that this is not a username at all
1364 # but actually an old subpage (bug #29797)
1365 if ( strpos(
$target,
'/' ) !==
false ) {
1366 # An old subpage, drill down to the user behind it
1371 if ( $userObj instanceof
User ) {
1372 # Note that since numbers are valid usernames, a $target of "12345" will be
1373 # considered a User. If you want to pass a block ID, prepend a hash "#12345",
1374 # since hash characters are not valid in usernames or titles generally.
1377 } elseif ( preg_match(
'/^#\d+$/',
$target ) ) {
1378 # Autoblock reference in the form "#12345"
1383 return [
null, null ];
1448 $this->blocker =
$user;
1468 $expiryValue = DateTime::createFromFormat(
'YmdHis',
$expiryTime )->format(
'U' );
1469 $cookieOptions = [
'httpOnly' =>
false ];
1471 $response->
setCookie(
'BlockID', $cookieValue, $expiryValue, $cookieOptions );
1480 $response->clearCookie(
'BlockID', [
'httpOnly' =>
false ] );
1491 $id = $this->
getId();
1492 $secretKey = $config->get(
'SecretKey' );
1493 if ( !$secretKey ) {
1498 $cookieValue = $id .
'!' . $hmac;
1499 return $cookieValue;
1510 $bangPos = strpos( $cookieValue,
'!' );
1511 $id = ( $bangPos ===
false ) ? $cookieValue : substr( $cookieValue, 0, $bangPos );
1514 $secretKey = $config->get(
'SecretKey' );
1515 if ( !$secretKey ) {
1519 $storedHmac = substr( $cookieValue, $bangPos + 1 );
1521 if ( $calculatedHmac === $storedHmac ) {
1539 $link =
"[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
1545 if ( $reason ==
'' ) {
1546 $reason =
$context->
msg(
'blockednoreason' )->text();
1558 ?
'systemblockedtext'
1559 : ( $this->mAuto ?
'autoblockedtext' :
'blockedtext' ),
1565 $lang->formatExpiry( $this->mExpiry ),
prevents( $action, $x=null)
Get/set whether the Block prevents a given action.
static toHex( $ip)
Return a zero-padded upper case hexadecimal representation of an IP address.
isHardblock( $x=null)
Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range)
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
static newFromId( $id)
Static factory method for creation from a given user ID.
getSystemBlockType()
Get the system block type, if any.
equals(Block $block)
Check if two blocks are effectively equal.
getType()
Get the type of target for this particular block.
processing should stop and the error should be shown to the user * false
getId()
Get the user's ID.
getCookieValue()
Get the BlockID cookie's value for this block.
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 clearCookie(WebResponse $response)
Unset the 'BlockID' cookie.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
static getIpFragment( $hex)
Get the component of an IP address which is certain to be the same between an IP address and a rangeb...
isExpired()
Has the block expired?
if(!isset( $args[0])) $lang
static newFromID( $id)
Load a blocked user from their block id.
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...
getBy()
Get the user id of the blocking sysop.
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest Block.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
update()
Update a block in the DB with new parameters.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
setCookie(WebResponse $response)
Set the 'BlockID' cookie to this block's ID and expiry time.
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
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
setCookie( $name, $value, $expire=0, $options=[])
Set the browser cookie.
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
wfReadOnly()
Check whether the wiki is in read-only mode.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
isValid()
Is the block address valid (i.e.
initFromRow( $row)
Given a database row from the ipblocks table, initialize member variables.
getUserPage()
Get this user's personal page title.
getRangeEnd()
Get the IP address at the end of the range in Hex form.
__construct( $options=[])
Create a new block with specified parameters on a user, IP or IP range.
getRequest()
Get the WebRequest object.
getUser()
Get the User object.
deleteIfExpired()
Check if a block has expired.
insert( $dbw=null)
Insert a block into the block table.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
getRedactedName()
Get the block name, but with autoblocked IPs hidden as per standard privacy policy.
newLoad( $vagueTarget=null)
Load a block from the database which affects the already-set $this->target: 1) A block directly on th...
int $type
Block::TYPE_ constant.
wfMemcKey()
Make a cache key for the local wiki.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static parseTarget( $target)
From an existing Block, get the target and the type of target.
static getRangeCond( $start, $end=null)
Get a set of SQL conditions which will select rangeblocks encompassing a given range.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
doAutoblock( $autoblockIP)
Autoblocks the given IP, referring to this Block.
static isWhitelistedFromAutoblocks( $ip)
Checks whether a given IP is on the autoblock whitelist.
getAutoblockUpdateArray()
when a variable name is used in a it is silently declared as a new masking the global
static isInRange( $addr, $range)
Determine if a given IPv4/IPv6 address is in a given CIDR network.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
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
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
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
getTargetAndType()
Get the target and target type for this particular Block.
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
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.
updateTimestamp()
Update the timestamp on autoblocks.
string null $systemBlockType
static parseRange( $range)
Given a string range in a number of formats, return the start and end of the range in hexadecimal.
getBlocker()
Get the user who implemented this block.
setBlocker( $user)
Set the user who implemented (or will implement) this block.
fromMaster( $x=null)
Get/set a flag determining whether the master is used for reads.
getTarget()
Get the target for this particular Block.
static purgeExpired()
Purge expired blocks from the ipblocks table.
static getMain()
Static methods.
static isValid( $ip)
Validate an IP address.
this hook is for auditing only $response
Interface for objects which can provide a MediaWiki context on request.
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
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
static selectFields()
Return the list of ipblocks fields that should be selected to create a new block.
int $forcedTargetID
Hack for foreign blocking (CentralAuth)
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
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
getRangeStart()
Get the IP address at the start of the range in Hex form.
usually copyright or history_copyright This message must be in HTML not wikitext & $link
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
getPermissionsError(IContextSource $context)
Get the key and parameters for the corresponding error message.
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 "<
getDatabaseArray( $db=null)
Get an array suitable for passing to $dbw->insert() or $dbw->update()
getByName()
Get the username of the blocking sysop.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
static newFromRow( $row)
Create a new Block object from a database row.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static isValidBlock( $ipblock)
Validate an IP Block (valid address WITH a valid prefix).
getName()
Get the user name, or the IP of an anonymous user.
static defaultRetroactiveAutoblock(Block $block, array &$blockIds)
Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
static sanitizeRange( $range)
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111....
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
setTarget( $target)
Set the target for this block, and update $this->type accordingly.
getLanguage()
Get the Language object.
the array() calling protocol came about after MediaWiki 1.4rc1.
static getAutoblockExpiry( $timestamp)
Get a timestamp of the expiry for autoblocks.