return null;
}
+
+ /**
+ * Check if the block should be tracked with a cookie.
+ *
+ * @since 1.33
+ * @param bool $isIpUser The user is logged out
+ * @return bool The block should be tracked with a cookie
+ */
+ public function shouldTrackWithCookie( $isIpUser ) {
+ $config = RequestContext::getMain()->getConfig();
+ switch ( $this->getType() ) {
+ case self::TYPE_IP:
+ case self::TYPE_RANGE:
+ return $isIpUser && $config->get( 'CookieSetOnIpBlock' );
+ case self::TYPE_USER:
+ return !$isIpUser && $config->get( 'CookieSetOnAutoblock' ) && $this->isAutoblocking();
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Check if the block prevents a user from resetting their password
+ *
+ * @since 1.33
+ * @return bool|null The block blocks password reset
+ */
+ public function appliesToPasswordReset() {
+ switch ( $this->getSystemBlockType() ) {
+ case null:
+ case 'global-block':
+ return $this->isCreateAccountBlocked();
+ case 'proxy':
+ return true;
+ case 'dnsbl':
+ case 'wgSoftBlockRanges':
+ return false;
+ default:
+ return false;
+ }
+ }
+
}
if ( !$block ) {
return false;
}
- $type = $block->getSystemBlockType();
- if ( in_array( $type, [ null, 'global-block' ], true ) ) {
- // Normal block. Maybe it was meant for someone else and the user just needs to log in;
- // or maybe it was issued specifically to prevent some IP from messing with password
- // reset? Go out on a limb and use the registration allowed flag to decide.
- return $block->isCreateAccountBlocked();
- } elseif ( $type === 'proxy' ) {
- // we disallow actions through proxy even if the user is logged in
- // so it makes sense to disallow password resets as well
- return true;
- } elseif ( in_array( $type, [ 'dnsbl', 'wgSoftBlockRanges' ], true ) ) {
- // these are just meant to force login so let's not prevent that
- return false;
- } else {
- // some extension - we'll have to guess
- return true;
- }
+ return $block->appliesToPasswordReset();
}
/**
*/
public function trackBlockWithCookie() {
$block = $this->getBlock();
- if ( $block && $this->getRequest()->getCookie( 'BlockID' ) === null ) {
- $config = RequestContext::getMain()->getConfig();
- $shouldSetCookie = false;
- if ( $this->isAnon() && $config->get( 'CookieSetOnIpBlock' ) ) {
- // If user is logged-out, set a cookie to track the Block
- $shouldSetCookie = in_array( $block->getType(), [
- Block::TYPE_IP, Block::TYPE_RANGE
- ] );
- if ( $shouldSetCookie ) {
- $block->setCookie( $this->getRequest()->response() );
- }
- } elseif ( $this->isLoggedIn() && $config->get( 'CookieSetOnAutoblock' ) ) {
- $shouldSetCookie = $block->getType() === Block::TYPE_USER && $block->isAutoblocking();
- if ( $shouldSetCookie ) {
- $block->setCookie( $this->getRequest()->response() );
- }
+ if ( $block && $this->getRequest()->getCookie( 'BlockID' ) === null ) {
+ if ( $block->shouldTrackWithCookie( $this->isAnon() ) ) {
+ $block->setCookie( $this->getRequest()->response() );
}
}
}