const TYPE_ID = 5;
/**
- * Create a new block with specified parameters on a user, IP or IP range.
+ * Create a new block with specified option parameters on a user, IP or IP range.
*
* @param array $options Parameters of the block:
* address string|User Target user name, User object, IP address or IP range
* actions, except those specifically allowed by
* other block flags
*
- * @since 1.26 accepts $options array instead of individual parameters; order
- * of parameters above reflects the original order
+ * @since 1.26 $options array
*/
- function __construct( $options = [] ) {
+ public function __construct( array $options = [] ) {
$defaults = [
'address' => '',
'user' => null,
if ( $block->getType() == self::TYPE_RANGE ) {
# This is the number of bits that are allowed to vary in the block, give
# or take some floating point errors
- $end = Wikimedia\base_convert( $block->getRangeEnd(), 16, 10 );
- $start = Wikimedia\base_convert( $block->getRangeStart(), 16, 10 );
+ $prefix = 'v6-';
+ $end = Wikimedia\base_convert( ltrim( $block->getRangeEnd(), $prefix ), 16, 10 );
+ $start = Wikimedia\base_convert( ltrim( $block->getRangeStart(), $prefix ), 16, 10 );
$size = log( $end - $start + 1, 2 );
- # This has the nice property that a /32 block is ranked equally with a
- # single-IP block, which is exactly what it is...
+ # Rank a range block covering a single IP equally with a single-IP block
$score = self::TYPE_RANGE - 1 + ( $size / 128 );
} else {
* Check if the block should be tracked with a cookie.
*
* @since 1.33
- * @param bool $isIpUser The user is logged out
+ * @param bool $isAnon The user is logged out
* @return bool The block should be tracked with a cookie
*/
- public function shouldTrackWithCookie( $isIpUser ) {
+ public function shouldTrackWithCookie( $isAnon ) {
$config = RequestContext::getMain()->getConfig();
switch ( $this->getType() ) {
case self::TYPE_IP:
case self::TYPE_RANGE:
- return $isIpUser && $config->get( 'CookieSetOnIpBlock' );
+ return $isAnon && $config->get( 'CookieSetOnIpBlock' );
case self::TYPE_USER:
- return !$isIpUser && $config->get( 'CookieSetOnAutoblock' ) && $this->isAutoblocking();
+ return !$isAnon && $config->get( 'CookieSetOnAutoblock' ) && $this->isAutoblocking();
default:
return false;
}