namespace MediaWiki\Block;
+use MediaWiki\Block\Restriction\NamespaceRestriction;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\Restriction;
use Wikimedia\Rdbms\IResultWrapper;
class BlockRestriction {
+ /**
+ * Map of all of the restriction types.
+ */
+ private static $types = [
+ PageRestriction::TYPE_ID => PageRestriction::class,
+ NamespaceRestriction::TYPE_ID => NamespaceRestriction::class,
+ ];
+
/**
* Retrieves the restrictions from the database by block id.
*
$dbw = wfGetDB( DB_MASTER );
- return $dbw->insert(
+ $dbw->insert(
'ipblocks_restrictions',
$rows,
__METHOD__,
[ 'IGNORE' ]
);
+
+ return true;
}
/**
$restrictions
);
- // Nothing to remove.
if ( empty( $restrictionsToRemove ) ) {
continue;
}
* @return Restriction|null
*/
private static function rowToRestriction( \stdClass $row ) {
- switch ( $row->ir_type ) {
- case PageRestriction::TYPE_ID:
- return PageRestriction::newFromRow( $row );
- default:
- return null;
+ if ( array_key_exists( (int)$row->ir_type, self::$types ) ) {
+ $class = self::$types[ (int)$row->ir_type ];
+ return call_user_func( [ $class, 'newFromRow' ], $row );
}
+
+ return null;
}
}