MediaWiki master
|
A service class for checking blocks. More...
Public Member Functions | |
__construct (ServiceOptions $options, UserFactory $userFactory, UserIdentityUtils $userIdentityUtils, LoggerInterface $logger, HookContainer $hookContainer, DatabaseBlockStore $blockStore, ProxyLookup $proxyLookup) | |
clearUserCache (UserIdentity $user) | |
Clear the cache of any blocks that refer to the specified user. | |
filter (?Block $block, $callback) | |
Remove elements of a block which fail a callback test. | |
getBlock (UserIdentity $user, ?WebRequest $request, $fromReplica=true) | |
Get the blocks that apply to a user. | |
getBlocksForIPList (array $ipChain, bool $applySoftBlocks, bool $fromPrimary) | |
Get all blocks that match any IP from an array of IP addresses. | |
getCreateAccountBlock (UserIdentity $user, ?WebRequest $request, $fromReplica) | |
Get the block which applies to a create account action, if there is any. | |
getIpBlock (string $ip, bool $fromReplica) | |
Get the blocks that apply to an IP address. | |
getUserBlock (UserIdentity $user, $request, $fromReplica, $disableIpBlockExemptChecking=false) | |
Get the blocks that apply to a user. | |
isDnsBlacklisted ( $ip, $checkAllowed=false) | |
Whether the given IP is in a DNS blacklist. | |
trackBlockWithCookie (User $user, WebResponse $response) | |
Set the 'BlockID' cookie depending on block type and user authentication status. | |
Static Public Member Functions | |
static | clearBlockCookie (WebResponse $response) |
Unset the 'BlockID' cookie. | |
Public Attributes | |
const | CONSTRUCTOR_OPTIONS |
Protected Member Functions | |
checkHost ( $hostname) | |
Wrapper for mocking in tests. | |
A service class for checking blocks.
To obtain an instance, use MediaWikiServices::getInstance()->getBlockManager().
Definition at line 48 of file BlockManager.php.
MediaWiki\Block\BlockManager::__construct | ( | ServiceOptions | $options, |
UserFactory | $userFactory, | ||
UserIdentityUtils | $userIdentityUtils, | ||
LoggerInterface | $logger, | ||
HookContainer | $hookContainer, | ||
DatabaseBlockStore | $blockStore, | ||
ProxyLookup | $proxyLookup ) |
Definition at line 75 of file BlockManager.php.
References MediaWiki\Config\ServiceOptions\assertRequiredOptions().
|
protected |
Wrapper for mocking in tests.
string | $hostname | DNSBL query |
Definition at line 704 of file BlockManager.php.
|
static |
Unset the 'BlockID' cookie.
WebResponse | $response |
Definition at line 824 of file BlockManager.php.
References MediaWiki\Request\WebResponse\clearCookie().
MediaWiki\Block\BlockManager::clearUserCache | ( | UserIdentity | $user | ) |
Clear the cache of any blocks that refer to the specified user.
UserIdentity | $user |
Definition at line 234 of file BlockManager.php.
MediaWiki\Block\BlockManager::filter | ( | ?Block | $block, |
$callback ) |
Remove elements of a block which fail a callback test.
Block | null | $block | The block, or null to pass in zero blocks. |
callable | $callback | The callback, which will be called once for each non-composite component of the block. The only parameter is the non-composite Block. It should return true, to keep that component, or false, to remove that component. |
Definition at line 310 of file BlockManager.php.
MediaWiki\Block\BlockManager::getBlock | ( | UserIdentity | $user, |
?WebRequest | $request, | ||
$fromReplica = true ) |
Get the blocks that apply to a user.
If there is only one, return that, otherwise return a composite block that combines the strictest features of the applicable blocks.
If the user is exempt from IP blocks, the request should be null.
UserIdentity | $user | The user performing the action |
WebRequest | null | $request | The request to use for IP and cookie blocks, or null to skip checking for such blocks. If the user has the ipblock-exempt right, the request should be null. |
bool | $fromReplica | Whether to check the replica DB first. To improve performance, non-critical checks are done against replica DBs. Check when actually saving should be done against primary. |
Definition at line 173 of file BlockManager.php.
Referenced by MediaWiki\Block\BlockManager\getUserBlock().
MediaWiki\Block\BlockManager::getBlocksForIPList | ( | array | $ipChain, |
bool | $applySoftBlocks, | ||
bool | $fromPrimary ) |
Get all blocks that match any IP from an array of IP addresses.
array | $ipChain | List of IPs (strings), usually retrieved from the X-Forwarded-For header of the request |
bool | $applySoftBlocks | Include soft blocks (anonymous-only blocks). These should only block anonymous and temporary users. |
bool | $fromPrimary | Whether to query the primary or replica DB |
Definition at line 493 of file BlockManager.php.
MediaWiki\Block\BlockManager::getCreateAccountBlock | ( | UserIdentity | $user, |
?WebRequest | $request, | ||
$fromReplica ) |
Get the block which applies to a create account action, if there is any.
UserIdentity | $user | |
WebRequest | null | $request | The request, or null to omit IP address and cookie blocks. If the user has the ipblock-exempt right, null should be passed. |
bool | $fromReplica |
Definition at line 250 of file BlockManager.php.
References MediaWiki\Request\WebRequest\getIP().
MediaWiki\Block\BlockManager::getIpBlock | ( | string | $ip, |
bool | $fromReplica ) |
Get the blocks that apply to an IP address.
If there is only one, return that, otherwise return a composite block that combines the strictest features of the applicable blocks.
string | $ip | |
bool | $fromReplica |
Definition at line 376 of file BlockManager.php.
MediaWiki\Block\BlockManager::getUserBlock | ( | UserIdentity | $user, |
$request, | |||
$fromReplica, | |||
$disableIpBlockExemptChecking = false ) |
Get the blocks that apply to a user.
If there is only one, return that, otherwise return a composite block that combines the strictest features of the applicable blocks.
Different blocks may be sought, depending on the user and their permissions. The user may be: (1) The global user (and can be affected by IP blocks). The global request object is needed for checking the IP address, the XFF header and the cookies. (2) The global user (and exempt from IP blocks). The global request object is available. (3) Another user (not the global user). No request object is available or needed; just look for a block against the user account.
Cases #1 and #2 check whether the global user is blocked in practice; the block may due to their user account being blocked or to an IP address block or cookie block (or multiple of these). Case #3 simply checks whether a user's account is blocked, and does not determine whether the person using that account is affected in practice by any IP address or cookie blocks.
UserIdentity | $user | |
WebRequest | null | $request | The global request object if the user is the global user (cases #1 and #2), otherwise null (case #3). The IP address and information from the request header are needed to find some types of blocks. |
bool | $fromReplica | Whether to check the replica DB first. To improve performance, non-critical checks are done against replica DBs. Check when actually saving should be done against primary. |
bool | $disableIpBlockExemptChecking | This is used internally to prevent a infinite recursion with autopromote. See T270145. |
Definition at line 132 of file BlockManager.php.
References MediaWiki\Block\BlockManager\getBlock().
MediaWiki\Block\BlockManager::isDnsBlacklisted | ( | $ip, | |
$checkAllowed = false ) |
Whether the given IP is in a DNS blacklist.
string | $ip | IP to check |
bool | $checkAllowed | Whether to check $wgProxyWhitelist first |
Definition at line 635 of file BlockManager.php.
MediaWiki\Block\BlockManager::trackBlockWithCookie | ( | User | $user, |
WebResponse | $response ) |
Set the 'BlockID' cookie depending on block type and user authentication status.
If a block cookie is already set, this will check the block that the cookie references and do the following:
Must be called after the User object is loaded, and before headers are sent.
User | $user | |
WebResponse | $response | The response on which to set the cookie. |
Definition at line 727 of file BlockManager.php.
References MediaWiki\User\User\getBlock(), MediaWiki\User\User\getRequest(), MediaWiki\Request\WebResponse\headersSent(), MediaWiki\User\User\isAnon(), and MediaWiki\User\User\isSafeToLoad().
const MediaWiki\Block\BlockManager::CONSTRUCTOR_OPTIONS |
Definition at line 52 of file BlockManager.php.