Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / title / NamespaceInfo.php
index 7307cc1..7234be2 100644 (file)
@@ -22,6 +22,7 @@
 
 use MediaWiki\Config\ServiceOptions;
 use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
 
 /**
  * This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of
@@ -61,6 +62,7 @@ class NamespaceInfo {
        public static $canonicalNames = [
                NS_MEDIA            => 'Media',
                NS_SPECIAL          => 'Special',
+               NS_MAIN             => '',
                NS_TALK             => 'Talk',
                NS_USER             => 'User',
                NS_USER_TALK        => 'User_talk',
@@ -93,10 +95,8 @@ class NamespaceInfo {
                'ExtraNamespaces',
                'ExtraSignatureNamespaces',
                'NamespaceContentModels',
-               'NamespaceProtection',
                'NamespacesWithSubpages',
                'NonincludableNamespaces',
-               'RestrictionLevels',
        ];
 
        /**
@@ -342,7 +342,7 @@ class NamespaceInfo {
         * Returns array of all defined namespaces with their canonical
         * (English) names.
         *
-        * @return array
+        * @return string[]
         */
        public function getCanonicalNamespaces() {
                if ( $this->canonicalNamespaces === null ) {
@@ -397,6 +397,7 @@ class NamespaceInfo {
         */
        public function getValidNamespaces() {
                if ( is_null( $this->validNamespaces ) ) {
+                       $this->validNamespaces = [];
                        foreach ( array_keys( $this->getCanonicalNamespaces() ) as $ns ) {
                                if ( $ns >= 0 ) {
                                        $this->validNamespaces[] = $ns;
@@ -572,82 +573,18 @@ class NamespaceInfo {
         * Determine which restriction levels it makes sense to use in a namespace,
         * optionally filtered by a user's rights.
         *
-        * @todo Move this to PermissionManager and remove the dependency here on permissions-related
-        * config settings.
-        *
+        * @deprecated since 1.34 User PermissionManager::getNamespaceRestrictionLevels instead.
         * @param int $index Index to check
         * @param User|null $user User to check
         * @return array
         */
        public function getRestrictionLevels( $index, User $user = null ) {
-               if ( !isset( $this->options->get( 'NamespaceProtection' )[$index] ) ) {
-                       // All levels are valid if there's no namespace restriction.
-                       // But still filter by user, if necessary
-                       $levels = $this->options->get( 'RestrictionLevels' );
-                       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;
-               }
-
-               // $wgNamespaceProtection can require one or more rights to edit the namespace, which
-               // may be satisfied by membership in multiple groups each giving a subset of those rights.
-               // A restriction level is redundant if, for any one of the namespace rights, all groups
-               // giving that right also give the restriction level's right. Or, conversely, a
-               // restriction level is not redundant if, for every namespace right, there's at least one
-               // group giving that right without the restriction level's right.
-               //
-               // First, for each right, get a list of groups with that right.
-               $namespaceRightGroups = [];
-               foreach ( (array)$this->options->get( 'NamespaceProtection' )[$index] as $right ) {
-                       if ( $right == 'sysop' ) {
-                               $right = 'editprotected'; // BC
-                       }
-                       if ( $right == 'autoconfirmed' ) {
-                               $right = 'editsemiprotected'; // BC
-                       }
-                       if ( $right != '' ) {
-                               $namespaceRightGroups[$right] = User::getGroupsWithPermission( $right );
-                       }
-               }
-
-               // Now, go through the protection levels one by one.
-               $usableLevels = [ '' ];
-               foreach ( $this->options->get( 'RestrictionLevels' ) as $level ) {
-                       $right = $level;
-                       if ( $right == 'sysop' ) {
-                               $right = 'editprotected'; // BC
-                       }
-                       if ( $right == 'autoconfirmed' ) {
-                               $right = 'editsemiprotected'; // BC
-                       }
-
-                       if ( $right != '' &&
-                               !isset( $namespaceRightGroups[$right] ) &&
-                               ( !$user || $user->isAllowed( $right ) )
-                       ) {
-                               // Do any of the namespace rights imply the restriction right? (see explanation above)
-                               foreach ( $namespaceRightGroups as $groups ) {
-                                       if ( !array_diff( $groups, User::getGroupsWithPermission( $right ) ) ) {
-                                               // Yes, this one does.
-                                               continue 2;
-                                       }
-                               }
-                               // No, keep the restriction level
-                               $usableLevels[] = $level;
-                       }
-               }
-
-               return $usableLevels;
+               // PermissionManager is not injected because adding an explicit dependency
+               // breaks MW installer by adding a dependency chain on the database before
+               // it was set up. Also, the method is deprecated and will be soon removed.
+               return MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->getNamespaceRestrictionLevels( $index, $user );
        }
 
        /**