X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FNamespace.php;h=ce585cec2fbda511db1a5da4a795da6da1ae5c00;hb=97a4ad455f836f779a056a4a53e57227b3ad0d1e;hp=8001b415ae74db193ae90f3da59bd720f2dd783e;hpb=3a26db55ab4ba908b76cd9982794d1eeafb4afa0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Namespace.php b/includes/Namespace.php index 8001b415ae..ce585cec2f 100644 --- a/includes/Namespace.php +++ b/includes/Namespace.php @@ -334,7 +334,7 @@ class MWNamespace { public static function getContentNamespaces() { global $wgContentNamespaces; if ( !is_array( $wgContentNamespaces ) || $wgContentNamespaces === array() ) { - return NS_MAIN; + return array( NS_MAIN ); } elseif ( !in_array( NS_MAIN, $wgContentNamespaces ) ) { // always force NS_MAIN to be part of array (to match the algorithm used by isContent) return array_merge( array( NS_MAIN ), $wgContentNamespaces ); @@ -433,4 +433,74 @@ class MWNamespace { ? $wgNamespaceContentModels[$index] : null; } + + /** + * Determine which restriction levels it makes sense to use in a namespace, + * optionally filtered by a user's rights. + * + * @since 1.23 + * @param int $index Index to check + * @param User $user User to check + * @return array + */ + public static function getRestrictionLevels( $index, User $user = null ) { + global $wgNamespaceProtection, $wgRestrictionLevels; + + if ( !isset( $wgNamespaceProtection[$index] ) ) { + // All levels are valid if there's no namespace restriction. + // But still filter by user, if necessary + $levels = $wgRestrictionLevels; + if ( $user ) { + $levels = array_values( array_filter( $levels, function ( $level ) use ( $user ) { + $right = $level; + if ( $right == 'sysop' ) { + $right = 'editprotected'; // BC + } + if ( $right == 'autoconfirmed' ) { + $right = 'editsemiprotected'; // BC + } + return ( $right == '' || $user->isAllowed( $right ) ); + } ) ); + } + return $levels; + } + + // First, get the list of groups that can edit this namespace. + $namespaceGroups = array(); + $combine = 'array_merge'; + foreach ( (array)$wgNamespaceProtection[$index] as $right ) { + if ( $right == 'sysop' ) { + $right = 'editprotected'; // BC + } + if ( $right == 'autoconfirmed' ) { + $right = 'editsemiprotected'; // BC + } + if ( $right != '' ) { + $namespaceGroups = call_user_func( $combine, $namespaceGroups, + User::getGroupsWithPermission( $right ) ); + $combine = 'array_intersect'; + } + } + + // Now, keep only those restriction levels where there is at least one + // group that can edit the namespace but would be blocked by the + // restriction. + $usableLevels = array( '' ); + foreach ( $wgRestrictionLevels as $level ) { + $right = $level; + if ( $right == 'sysop' ) { + $right = 'editprotected'; // BC + } + if ( $right == 'autoconfirmed' ) { + $right = 'editsemiprotected'; // BC + } + if ( $right != '' && ( !$user || $user->isAllowed( $right ) ) && + array_diff( $namespaceGroups, User::getGroupsWithPermission( $right ) ) + ) { + $usableLevels[] = $level; + } + } + + return $usableLevels; + } }