Merge "Add AbstractBlock parent class for Block"
[lhc/web/wiklou.git] / includes / Block.php
index 489cc66..6bfd7d3 100644 (file)
 
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\Block\AbstractBlock;
 use MediaWiki\Block\BlockRestrictionStore;
 use MediaWiki\Block\Restriction\Restriction;
 use MediaWiki\Block\Restriction\NamespaceRestriction;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\MediaWikiServices;
 
-class Block {
+class Block extends AbstractBlock {
        /** @var string */
        public $mReason;
 
@@ -387,12 +388,12 @@ class Block {
                        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 {