X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fblock%2FBlockRestriction.php;h=72f6eaa9b6f7feff850b6d69c42a5ee97b682259;hb=4b7107764668118b181b7f569494a4fcbe8c89d7;hp=5bf286d013daa726e4e507130c46f9fa03eccaf9;hpb=5417327be0829de7a2e258eaadc2422dec24e318;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/block/BlockRestriction.php b/includes/block/BlockRestriction.php index 5bf286d013..72f6eaa9b6 100644 --- a/includes/block/BlockRestriction.php +++ b/includes/block/BlockRestriction.php @@ -22,6 +22,7 @@ namespace MediaWiki\Block; +use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\Restriction; use Wikimedia\Rdbms\IResultWrapper; @@ -29,15 +30,24 @@ use Wikimedia\Rdbms\IDatabase; 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. * + * @since 1.33 * @param int|array $blockId * @param IDatabase|null $db * @return Restriction[] */ public static function loadByBlockId( $blockId, IDatabase $db = null ) { - if ( is_null( $blockId ) || $blockId === [] ) { + if ( $blockId === null || $blockId === [] ) { return []; } @@ -58,6 +68,7 @@ class BlockRestriction { /** * Inserts the restrictions into the database. * + * @since 1.33 * @param Restriction[] $restrictions * @return bool */ @@ -92,6 +103,7 @@ class BlockRestriction { * Updates the list of restrictions. This method does not allow removing all * of the restrictions. To do that, use ::deleteByBlockId(). * + * @since 1.33 * @param Restriction[] $restrictions * @return bool */ @@ -137,7 +149,6 @@ class BlockRestriction { $restrictions ); - // Nothing to remove. if ( empty( $restrictionsToRemove ) ) { continue; } @@ -156,6 +167,7 @@ class BlockRestriction { /** * Updates the list of restrictions by parent id. * + * @since 1.33 * @param int $parentBlockId * @param Restriction[] $restrictions * @return bool @@ -195,6 +207,7 @@ class BlockRestriction { /** * Delete the restrictions. * + * @since 1.33 * @param Restriction[]|null $restrictions * @throws MWException * @return bool @@ -224,6 +237,7 @@ class BlockRestriction { /** * Delete the restrictions by Block ID. * + * @since 1.33 * @param int|array $blockId * @throws MWException * @return bool @@ -240,6 +254,7 @@ class BlockRestriction { /** * Delete the restrictions by Parent Block ID. * + * @since 1.33 * @param int|array $parentBlockId * @throws MWException * @return bool @@ -261,6 +276,7 @@ class BlockRestriction { * equality check as the restrictions do not have to contain the same block * ids. * + * @since 1.33 * @param Restriction[] $a * @param Restriction[] $b * @return bool @@ -305,6 +321,7 @@ class BlockRestriction { /** * Set the blockId on a set of restrictions and return a new set. * + * @since 1.33 * @param int $blockId * @param Restriction[] $restrictions * @return Restriction[] @@ -406,11 +423,11 @@ class BlockRestriction { * @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; } }