Merge "Deprecate and replace usages of User:isAllowed{All,Any}"
authorPpchelko <ppchelko@wikimedia.org>
Thu, 22 Aug 2019 17:31:50 +0000 (17:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 22 Aug 2019 17:31:50 +0000 (17:31 +0000)
1  2 
includes/skins/SkinTemplate.php
includes/specials/pagers/ContribsPager.php
includes/user/User.php

@@@ -585,7 -585,6 +585,7 @@@ class SkinTemplate extends Skin 
                $request = $this->getRequest();
                $pageurl = $title->getLocalURL();
                $authManager = AuthManager::singleton();
 +              $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
  
                /* set up the default links for the personal toolbar */
                $personal_urls = [];
                        ];
  
                        // No need to show Talk and Contributions to anons if they can't contribute!
 -                      if ( User::groupHasPermission( '*', 'edit' ) ) {
 +                      if ( $permissionManager->groupHasPermission( '*', 'edit' ) ) {
                                // Because of caching, we can't link directly to the IP talk and
                                // contributions pages. Instead we use the special page shortcuts
                                // (which work correctly regardless of caching). This means we can't
                        }
  
                        if ( $authManager->canAuthenticateNow() ) {
 -                              $key = User::groupHasPermission( '*', 'read' )
 +                              $key = $permissionManager->groupHasPermission( '*', 'read' )
                                        ? 'login'
                                        : 'login-private';
                                $personal_urls[$key] = $login_url;
                                }
  
                                // Checks if the user is logged in
-                               if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
+                               if ( $this->loggedin && MediaWikiServices::getInstance()
+                                               ->getPermissionManager()
+                                               ->userHasAllRights( $user, 'viewmywatchlist', 'editmywatchlist' )
+                               ) {
                                        /**
                                         * The following actions use messages which, if made particular to
                                         * the any specific skins, would break the Ajax code which makes this
@@@ -285,9 -285,7 +285,9 @@@ class ContribsPager extends RangeChrono
                        $queryInfo['conds'][] = $revQuery['fields']['rev_user'] . ' >' . (int)( $max - $max / 100 );
                        # ignore local groups with the bot right
                        # @todo FIXME: Global groups may have 'bot' rights
 -                      $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
 +                      $groupsWithBotPermission = MediaWikiServices::getInstance()
 +                              ->getPermissionManager()
 +                              ->getGroupsWithPermission( 'bot' );
                        if ( count( $groupsWithBotPermission ) ) {
                                $queryInfo['tables'][] = 'user_groups';
                                $queryInfo['conds'][] = 'ug_group IS NULL';
                        $queryInfo['conds'][] = $this->mDb->bitAnd(
                                'rev_deleted', RevisionRecord::DELETED_USER
                                ) . ' = 0';
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $queryInfo['conds'][] = $this->mDb->bitAnd(
                                'rev_deleted', RevisionRecord::SUPPRESSED_USER
                                ) . ' != ' . RevisionRecord::SUPPRESSED_USER;
diff --combined includes/user/User.php
@@@ -3601,32 -3601,28 +3601,28 @@@ class User implements IDBAccessObject, 
        /**
         * Check if user is allowed to access a feature / make an action
         *
+        * @deprecated since 1.34, use MediaWikiServices::getInstance()
+        * ->getPermissionManager()->userHasAnyRights(...) instead
+        *
         * @param string $permissions,... Permissions to test
         * @return bool True if user is allowed to perform *any* of the given actions
         */
        public function isAllowedAny() {
-               $permissions = func_get_args();
-               foreach ( $permissions as $permission ) {
-                       if ( $this->isAllowed( $permission ) ) {
-                               return true;
-                       }
-               }
-               return false;
+               return MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $this, ...func_get_args() );
        }
  
        /**
-        *
+        * @deprecated since 1.34, use MediaWikiServices::getInstance()
+        * ->getPermissionManager()->userHasAllRights(...) instead
         * @param string $permissions,... Permissions to test
         * @return bool True if the user is allowed to perform *all* of the given actions
         */
        public function isAllowedAll() {
-               $permissions = func_get_args();
-               foreach ( $permissions as $permission ) {
-                       if ( !$this->isAllowed( $permission ) ) {
-                               return false;
-                       }
-               }
-               return true;
+               return MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAllRights( $this, ...func_get_args() );
        }
  
        /**
                global $wgLang;
  
                $groups = [];
 -              foreach ( self::getGroupsWithPermission( $permission ) as $group ) {
 +              foreach ( MediaWikiServices::getInstance()
 +                                        ->getPermissionManager()
 +                                        ->getGroupsWithPermission( $permission ) as $group ) {
                        $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
                }