MediaWiki REL1_34
|
A service class for checking blocks. More...
Public Member Functions | |
__construct (ServiceOptions $options, PermissionManager $permissionManager, LoggerInterface $logger) | |
getCookieValue (DatabaseBlock $block) | |
Get the BlockID cookie's value for this block. | |
getIdFromCookieValue ( $cookieValue) | |
Get the stored ID from the 'BlockID' cookie. | |
getUserBlock (User $user, $request, $fromReplica) | |
Get the blocks that apply to a user. | |
isDnsBlacklisted ( $ip, $checkWhitelist=false) | |
Whether the given IP is in a DNS blacklist. | |
setBlockCookie (DatabaseBlock $block, WebResponse $response) | |
Set the 'BlockID' cookie to this block's ID and expiry time. | |
trackBlockWithCookie (User $user) | |
Set the 'BlockID' cookie depending on block type and user authentication status. | |
Static Public Member Functions | |
static | clearBlockCookie (WebResponse $response) |
Unset the 'BlockID' cookie. | |
Protected Member Functions | |
checkHost ( $hostname) | |
Wrapper for mocking in tests. | |
Private Member Functions | |
getAdditionalIpBlocks (&$blocks, WebRequest $request, $isAnon, $fromMaster) | |
Check for any additional blocks against the IP address or any IPs in the XFF header. | |
getBlockFromCookieValue (UserIdentity $user, WebRequest $request) | |
Try to load a block from an ID given in a cookie value. | |
getCookieBlock (&$blocks, UserIdentity $user, WebRequest $request) | |
Get the cookie block, if there is one. | |
getUniqueBlocks (array $blocks) | |
Given a list of blocks, return a list of unique blocks. | |
inDnsBlacklist ( $ip, array $bases) | |
Whether the given IP is in a given DNS blacklist. | |
isLocallyBlockedProxy ( $ip) | |
Check if an IP address is in the local proxy list. | |
shouldApplyCookieBlock (DatabaseBlock $block, $isAnon) | |
Check if the block loaded from the cookie should be applied. | |
shouldTrackBlockWithCookie (AbstractBlock $block, $isAnon) | |
Check if the block should be tracked with a cookie. | |
Private Attributes | |
LoggerInterface | $logger |
ServiceOptions | $options |
PermissionManager | $permissionManager |
A service class for checking blocks.
To obtain an instance, use MediaWikiServices::getInstance()->getBlockManager().
Definition at line 44 of file BlockManager.php.
MediaWiki\Block\BlockManager::__construct | ( | ServiceOptions | $options, |
PermissionManager | $permissionManager, | ||
LoggerInterface | $logger ) |
ServiceOptions | $options | |
PermissionManager | $permissionManager | |
LoggerInterface | $logger |
Definition at line 75 of file BlockManager.php.
References MediaWiki\Block\BlockManager\$logger, MediaWiki\Block\BlockManager\$options, MediaWiki\Block\BlockManager\$permissionManager, and MediaWiki\Config\ServiceOptions\assertRequiredOptions().
|
protected |
Wrapper for mocking in tests.
string | $hostname | DNSBL query |
Definition at line 426 of file BlockManager.php.
Referenced by MediaWiki\Block\BlockManager\inDnsBlacklist().
|
static |
Unset the 'BlockID' cookie.
WebResponse | $response |
Definition at line 534 of file BlockManager.php.
References $response.
Referenced by MediaWiki\Block\BlockManager\getBlockFromCookieValue().
|
private |
Check for any additional blocks against the IP address or any IPs in the XFF header.
AbstractBlock[] | &$blocks | Blocks found so far |
WebRequest | $request | |
bool | $isAnon | The user is logged out |
bool | $fromMaster |
Definition at line 196 of file BlockManager.php.
References MediaWiki\Block\DatabaseBlock\getBlocksForIPList(), WebRequest\getHeader(), WebRequest\getIP(), MediaWiki\Block\BlockManager\isDnsBlacklisted(), MediaWiki\Block\BlockManager\isLocallyBlockedProxy(), and wfMessage().
Referenced by MediaWiki\Block\BlockManager\getUserBlock().
|
private |
Try to load a block from an ID given in a cookie value.
If the block is invalid doesn't exist, or the cookie value is malformed, remove the cookie.
UserIdentity | $user | |
WebRequest | $request |
Definition at line 282 of file BlockManager.php.
References MediaWiki\Block\BlockManager\clearBlockCookie(), WebRequest\getCookie(), MediaWiki\Block\BlockManager\getIdFromCookieValue(), MediaWiki\User\UserIdentity\isRegistered(), MediaWiki\Block\DatabaseBlock\newFromID(), WebRequest\response(), and MediaWiki\Block\BlockManager\shouldApplyCookieBlock().
Referenced by MediaWiki\Block\BlockManager\getCookieBlock().
|
private |
Get the cookie block, if there is one.
AbstractBlock[] | &$blocks | |
UserIdentity | $user | |
WebRequest | $request |
Definition at line 180 of file BlockManager.php.
References MediaWiki\Block\BlockManager\getBlockFromCookieValue().
Referenced by MediaWiki\Block\BlockManager\getUserBlock().
MediaWiki\Block\BlockManager::getCookieValue | ( | DatabaseBlock | $block | ) |
Get the BlockID cookie's value for this block.
This is usually the block ID concatenated with an HMAC in order to avoid spoofing (T152951), but if wgSecretKey is not set will just be the block ID.
Definition at line 581 of file BlockManager.php.
References MediaWiki\Block\DatabaseBlock\getId(), and MWCryptHash\hmac().
MediaWiki\Block\BlockManager::getIdFromCookieValue | ( | $cookieValue | ) |
Get the stored ID from the 'BlockID' cookie.
The cookie's value is usually a combination of the ID and a HMAC (see DatabaseBlock::setCookie), but will sometimes only be the ID.
Definition at line 548 of file BlockManager.php.
References MWCryptHash\hmac().
Referenced by MediaWiki\Block\BlockManager\getBlockFromCookieValue().
|
private |
Given a list of blocks, return a list of unique blocks.
This usually means that each block has a unique ID. For a block with ID null, if it's an autoblock, it will be filtered out if the parent block is present; if not, it is assumed to be a unique system block, and kept.
AbstractBlock[] | $blocks |
Definition at line 253 of file BlockManager.php.
References MediaWiki\Block\AbstractBlock\TYPE_AUTO.
Referenced by MediaWiki\Block\BlockManager\getUserBlock().
MediaWiki\Block\BlockManager::getUserBlock | ( | User | $user, |
$request, | |||
$fromReplica ) |
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 needed for checking the cookies. (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.
Definition at line 116 of file BlockManager.php.
References MediaWiki\Block\BlockManager\getAdditionalIpBlocks(), MediaWiki\Block\BlockManager\getCookieBlock(), MediaWiki\Block\BlockManager\getUniqueBlocks(), User\isRegistered(), MediaWiki\Block\DatabaseBlock\newListFromTarget(), and wfMessage().
|
private |
Whether the given IP is in a given DNS blacklist.
string | $ip | IP to check |
array | $bases | Array of Strings: URL of the DNS blacklist |
Definition at line 379 of file BlockManager.php.
References $base, and MediaWiki\Block\BlockManager\checkHost().
Referenced by MediaWiki\Block\BlockManager\isDnsBlacklisted().
MediaWiki\Block\BlockManager::isDnsBlacklisted | ( | $ip, | |
$checkWhitelist = false ) |
Whether the given IP is in a DNS blacklist.
string | $ip | IP to check |
bool | $checkWhitelist | Whether to check the whitelist first |
Definition at line 362 of file BlockManager.php.
References MediaWiki\Block\BlockManager\inDnsBlacklist().
Referenced by MediaWiki\Block\BlockManager\getAdditionalIpBlocks().
|
private |
Check if an IP address is in the local proxy list.
string | $ip |
Definition at line 340 of file BlockManager.php.
Referenced by MediaWiki\Block\BlockManager\getAdditionalIpBlocks().
MediaWiki\Block\BlockManager::setBlockCookie | ( | DatabaseBlock | $block, |
WebResponse | $response ) |
Set the 'BlockID' cookie to this block's ID and expiry time.
The cookie's expiry will be the same as the block's, to a maximum of 24 hours.
Definition at line 483 of file BlockManager.php.
References $expiryTime, $response, MediaWiki\Block\AbstractBlock\getExpiry(), and wfTimestamp().
Referenced by MediaWiki\Block\BlockManager\trackBlockWithCookie().
|
private |
Check if the block loaded from the cookie should be applied.
DatabaseBlock | $block | |
bool | $isAnon | The user is logged out |
Definition at line 315 of file BlockManager.php.
References MediaWiki\Block\DatabaseBlock\getType(), MediaWiki\Block\DatabaseBlock\isAutoblocking(), MediaWiki\Block\DatabaseBlock\isExpired(), MediaWiki\Block\AbstractBlock\TYPE_IP, MediaWiki\Block\AbstractBlock\TYPE_RANGE, and MediaWiki\Block\AbstractBlock\TYPE_USER.
Referenced by MediaWiki\Block\BlockManager\getBlockFromCookieValue().
|
private |
Check if the block should be tracked with a cookie.
AbstractBlock | $block | |
bool | $isAnon | The user is logged out |
Definition at line 511 of file BlockManager.php.
References MediaWiki\Block\AbstractBlock\getType(), MediaWiki\Block\AbstractBlock\TYPE_IP, MediaWiki\Block\AbstractBlock\TYPE_RANGE, and MediaWiki\Block\AbstractBlock\TYPE_USER.
Referenced by MediaWiki\Block\BlockManager\trackBlockWithCookie().
MediaWiki\Block\BlockManager::trackBlockWithCookie | ( | User | $user | ) |
Set the 'BlockID' cookie depending on block type and user authentication status.
User | $user |
Definition at line 436 of file BlockManager.php.
References $response, User\getBlock(), User\getRequest(), User\isAnon(), MediaWiki\Block\BlockManager\setBlockCookie(), and MediaWiki\Block\BlockManager\shouldTrackBlockWithCookie().
|
private |
Definition at line 68 of file BlockManager.php.
Referenced by MediaWiki\Block\BlockManager\__construct().
|
private |
Definition at line 49 of file BlockManager.php.
Referenced by MediaWiki\Block\BlockManager\__construct().
|
private |
Definition at line 46 of file BlockManager.php.
Referenced by MediaWiki\Block\BlockManager\__construct().