* Special namespaces are defined in includes/Defines.php and have
* a value below 0 (ex: NS_SPECIAL = -1 , NS_MEDIA = -2)
*
- * @param $index
- * @param $method
+ * @param int $index
+ * @param string $method
*
* @throws MWException
* @return bool
/**
* Can pages in the given namespace be moved?
*
- * @param int $index namespace index
+ * @param int $index Namespace index
* @return bool
*/
public static function isMovable( $index ) {
/**
* Is the given namespace is a subject (non-talk) namespace?
*
- * @param int $index namespace index
+ * @param int $index Namespace index
* @return bool
* @since 1.19
*/
/**
* Is the given namespace a talk namespace?
*
- * @param int $index namespace index
+ * @param int $index Namespace index
* @return bool
*/
public static function isTalk( $index ) {
/**
* Get the talk namespace index for a given namespace
*
- * @param int $index namespace index
+ * @param int $index Namespace index
* @return int
*/
public static function getTalk( $index ) {
* For talk namespaces, returns the subject (non-talk) namespace
* For subject (non-talk) namespaces, returns the talk namespace
*
- * @param int $index namespace index
- * @return int or null if no associated namespace could be found
+ * @param int $index Namespace index
+ * @return int|null If no associated namespace could be found
*/
public static function getAssociated( $index ) {
self::isMethodValidFor( $index, __METHOD__ );
/**
* Returns whether the specified namespace exists
*
- * @param $index
+ * @param int $index
*
* @return bool
* @since 1.19
* Returns array of all defined namespaces with their canonical
* (English) names.
*
- * @param bool $rebuild rebuild namespace list (default = false). Used for testing.
+ * @param bool $rebuild Rebuild namespace list (default = false). Used for testing.
*
* @return array
* @since 1.17
/**
* Returns the canonical (English) name for a given index
*
- * @param int $index namespace index
- * @return string or false if no canonical definition.
+ * @param int $index Namespace index
+ * @return string|false If no canonical definition.
*/
public static function getCanonicalName( $index ) {
$nslist = self::getCanonicalNamespaces();
* Returns the index for a given canonical name, or NULL
* The input *must* be converted to lower case first
*
- * @param string $name namespace name
+ * @param string $name Namespace name
* @return int
*/
public static function getCanonicalIndex( $name ) {
/**
* Can this namespace ever have a talk namespace?
*
- * @param int $index namespace index
+ * @param int $index Namespace index
* @return bool
*/
public static function canTalk( $index ) {
* Does this namespace contain content, for the purposes of calculating
* statistics, etc?
*
- * @param int $index index to check
+ * @param int $index Index to check
* @return bool
*/
public static function isContent( $index ) {
/**
* Can pages in a namespace be watched?
*
- * @param $index Int
+ * @param int $index
* @return bool
*/
public static function isWatchable( $index ) {
/**
* Get a list of all namespace indices which are considered to contain content
- * @return array of namespace indices
+ * @return array Array of namespace indices
*/
public static function getContentNamespaces() {
global $wgContentNamespaces;
* List all namespace indices which are considered subject, aka not a talk
* or special namespace. See also MWNamespace::isSubject
*
- * @return array of namespace indices
+ * @return array Array of namespace indices
*/
public static function getSubjectNamespaces() {
return array_filter(
* List all namespace indices which are considered talks, aka not a subject
* or special namespace. See also MWNamespace::isTalk
*
- * @return array of namespace indices
+ * @return array Array of namespace indices
*/
public static function getTalkNamespaces() {
return array_filter(
*
* @since 1.21
* @param int $index Index to check
- * @return null|string default model name for the given namespace, if set
+ * @return null|string Default model name for the given namespace, if set
*/
public static function getNamespaceContentModel( $index ) {
global $wgNamespaceContentModels;
? $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;
+ }
}