|
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, BlockTargetFactory $blockTargetFactory, 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. | |
| getIpRangeBlock (string $ipRange, bool $fromReplica=true) | |
| Given an IP range, check if a block applies to that range specifically. | |
| 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 35 of file BlockManager.php.
| MediaWiki\Block\BlockManager::__construct | ( | ServiceOptions | $options, |
| UserFactory | $userFactory, | ||
| UserIdentityUtils | $userIdentityUtils, | ||
| LoggerInterface | $logger, | ||
| HookContainer | $hookContainer, | ||
| DatabaseBlockStore | $blockStore, | ||
| BlockTargetFactory | $blockTargetFactory, | ||
| ProxyLookup | $proxyLookup ) |
Definition at line 63 of file BlockManager.php.
|
protected |
Wrapper for mocking in tests.
| string | $hostname | DNSBL query |
Definition at line 667 of file BlockManager.php.
|
static |
Unset the 'BlockID' cookie.
| WebResponse | $response |
Definition at line 787 of file BlockManager.php.
References MediaWiki\Request\WebResponse\clearCookie().
Referenced by trackBlockWithCookie().
| MediaWiki\Block\BlockManager::clearUserCache | ( | UserIdentity | $user | ) |
Clear the cache of any blocks that refer to the specified user.
Definition at line 163 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 239 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 104 of file BlockManager.php.
References $request.
Referenced by getCreateAccountBlock().
| 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 447 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 179 of file BlockManager.php.
References $request, and getBlock().
| 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 306 of file BlockManager.php.
References if.
| MediaWiki\Block\BlockManager::getIpRangeBlock | ( | string | $ipRange, |
| bool | $fromReplica = true ) |
Given an IP range, check if a block applies to that range specifically.
| string | $ipRange | |
| bool | $fromReplica |
Definition at line 327 of file BlockManager.php.
References if.
| 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 598 of file BlockManager.php.
References MediaWiki\MainConfigNames\DnsBlacklistUrls, MediaWiki\MainConfigNames\EnableDnsBlacklist, and MediaWiki\MainConfigNames\ProxyWhitelist.
| 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 690 of file BlockManager.php.
References $request, clearBlockCookie(), MediaWiki\MainConfigNames\CookieSetOnAutoblock, MediaWiki\MainConfigNames\CookieSetOnIpBlock, 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 39 of file BlockManager.php.