Deprecate and replace usages of User:isAllowed{All,Any}
authorPetr Pchelko <ppchelko@wikimedia.org>
Wed, 21 Aug 2019 22:42:08 +0000 (15:42 -0700)
committerPetr Pchelko <ppchelko@wikimedia.org>
Thu, 22 Aug 2019 01:36:16 +0000 (18:36 -0700)
Bug: T220191
Change-Id: I197b8fadaa93e7b320fc19c10e3e09387fe09ad2

30 files changed:
includes/Permissions/PermissionManager.php
includes/api/ApiBase.php
includes/api/ApiComparePages.php
includes/api/ApiQueryAllDeletedRevisions.php
includes/api/ApiQueryAllRevisions.php
includes/api/ApiQueryBase.php
includes/api/ApiQueryDeletedRevisions.php
includes/api/ApiQueryDeletedrevs.php
includes/api/ApiQueryFilearchive.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQueryUserContribs.php
includes/auth/AuthManager.php
includes/logging/LogEventsList.php
includes/logging/LogPager.php
includes/page/ImageHistoryList.php
includes/page/WikiPage.php
includes/skins/Skin.php
includes/skins/SkinTemplate.php
includes/specials/SpecialImport.php
includes/specials/SpecialLog.php
includes/specials/SpecialWatchlist.php
includes/specials/forms/PreferencesFormOOUI.php
includes/specials/pagers/ContribsPager.php
includes/specials/pagers/DeletedContribsPager.php
includes/user/User.php
tests/phpunit/includes/api/ApiOptionsTest.php
tests/phpunit/includes/specials/SpecialPreferencesTest.php

index 2d4885e..bd88c17 100644 (file)
@@ -827,7 +827,7 @@ class PermissionManager {
         * Check restrictions on cascading pages.
         *
         * @param string $action The action to check
-        * @param User $user User to check
+        * @param UserIdentity $user User to check
         * @param array $errors List of current errors
         * @param string $rigor One of PermissionManager::RIGOR_ constants
         *   - RIGOR_QUICK  : does cheap permission checks from replica DBs (usable for GUI creation)
@@ -841,7 +841,7 @@ class PermissionManager {
         */
        private function checkCascadingSourcesRestrictions(
                $action,
-               User $user,
+               UserIdentity $user,
                $errors,
                $rigor,
                $short,
@@ -870,7 +870,7 @@ class PermissionManager {
                                        if ( $right == 'autoconfirmed' ) {
                                                $right = 'editsemiprotected';
                                        }
-                                       if ( $right != '' && !$user->isAllowedAll( 'protect', $right ) ) {
+                                       if ( $right != '' && !$this->userHasAllRights( $user, 'protect', $right ) ) {
                                                $wikiPages = '';
                                                /** @var Title $wikiPage */
                                                foreach ( $cascadingSources as $wikiPage ) {
@@ -1086,7 +1086,7 @@ class PermissionManager {
         * Check CSS/JSON/JS sub-page permissions
         *
         * @param string $action The action to check
-        * @param User $user User to check
+        * @param UserIdentity $user User to check
         * @param array $errors List of current errors
         * @param string $rigor One of PermissionManager::RIGOR_ constants
         *   - RIGOR_QUICK  : does cheap permission checks from replica DBs (usable for GUI creation)
@@ -1100,7 +1100,7 @@ class PermissionManager {
         */
        private function checkUserConfigPermissions(
                $action,
-               User $user,
+               UserIdentity $user,
                $errors,
                $rigor,
                $short,
@@ -1120,22 +1120,22 @@ class PermissionManager {
                        // Users need editmyuser* to edit their own CSS/JSON/JS subpages.
                        if (
                                $title->isUserCssConfigPage()
-                               && !$user->isAllowedAny( 'editmyusercss', 'editusercss' )
+                               && !$this->userHasAnyRight( $user, 'editmyusercss', 'editusercss' )
                        ) {
                                $errors[] = [ 'mycustomcssprotected', $action ];
                        } elseif (
                                $title->isUserJsonConfigPage()
-                               && !$user->isAllowedAny( 'editmyuserjson', 'edituserjson' )
+                               && !$this->userHasAnyRight( $user, 'editmyuserjson', 'edituserjson' )
                        ) {
                                $errors[] = [ 'mycustomjsonprotected', $action ];
                        } elseif (
                                $title->isUserJsConfigPage()
-                               && !$user->isAllowedAny( 'editmyuserjs', 'edituserjs' )
+                               && !$this->userHasAnyRight( $user, 'editmyuserjs', 'edituserjs' )
                        ) {
                                $errors[] = [ 'mycustomjsprotected', $action ];
                        } elseif (
                                $title->isUserJsConfigPage()
-                               && !$user->isAllowedAny( 'edituserjs', 'editmyuserjsredirect' )
+                               && !$this->userHasAnyRight( $user, 'edituserjs', 'editmyuserjsredirect' )
                        ) {
                                // T207750 - do not allow users to edit a redirect if they couldn't edit the target
                                $rev = $this->revisionLookup->getRevisionByTitle( $title );
@@ -1195,6 +1195,40 @@ class PermissionManager {
                return in_array( $action, $this->getUserPermissions( $user ), true );
        }
 
+       /**
+        * Check if user is allowed to make any action
+        *
+        * @param UserIdentity $user
+        * @param string[] ...$actions
+        * @return bool True if user is allowed to perform *any* of the given actions
+        * @since 1.34
+        */
+       public function userHasAnyRight( UserIdentity $user, ...$actions ) {
+               foreach ( $actions as $action ) {
+                       if ( $this->userHasRight( $user, $action ) ) {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * Check if user is allowed to make all actions
+        *
+        * @param UserIdentity $user
+        * @param string[] ...$actions
+        * @return bool True if user is allowed to perform *all* of the given actions
+        * @since 1.34
+        */
+       public function userHasAllRights( UserIdentity $user, ...$actions ) {
+               foreach ( $actions as $action ) {
+                       if ( !$this->userHasRight( $user, $action ) ) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
        /**
         * Get the permissions this user has.
         *
index a7b872c..8b6a3e5 100644 (file)
@@ -2126,7 +2126,9 @@ abstract class ApiBase extends ContextSource {
                        $user = $this->getUser();
                }
                $rights = (array)$rights;
-               if ( !$user->isAllowedAny( ...$rights ) ) {
+               if ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $user, ...$rights )
+               ) {
                        $this->dieWithError( [ 'apierror-permissiondenied', $this->msg( "action-{$rights[0]}" ) ] );
                }
        }
index e096915..05eb438 100644 (file)
@@ -231,7 +231,9 @@ class ApiComparePages extends ApiBase {
         */
        private function getRevisionById( $id ) {
                $rev = $this->revisionStore->getRevisionById( $id );
-               if ( !$rev && $this->getUser()->isAllowedAny( 'deletedtext', 'undelete' ) ) {
+               if ( !$rev && $this->getPermissionManager()
+                               ->userHasAnyRight( $this->getUser(), 'deletedtext', 'undelete' )
+               ) {
                        // Try the 'archive' table
                        $arQuery = $this->revisionStore->getArchiveQueryInfo();
                        $row = $this->getDB()->selectRow(
index 4eead4c..d713b3a 100644 (file)
@@ -239,7 +239,9 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
                        // check it again just in case)
                        if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
                                $bitmask = RevisionRecord::DELETED_USER;
-                       } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
index 17a6e00..3751102 100644 (file)
@@ -156,7 +156,9 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
                        // Paranoia: avoid brute force searches (T19342)
                        if ( !$this->getPermissionManager()->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
                                $bitmask = RevisionRecord::DELETED_USER;
-                       } elseif ( !$this->getUser()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $this->getUser(), 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
index 846a8b1..10db848 100644 (file)
@@ -600,7 +600,8 @@ abstract class ApiQueryBase extends ApiBase {
         * @return bool
         */
        public function userCanSeeRevDel() {
-               return $this->getUser()->isAllowedAny(
+               return $this->getPermissionManager()->userHasAnyRight(
+                       $this->getUser(),
                        'deletedhistory',
                        'deletedtext',
                        'suppressrevision',
index ac12b47..fc88499 100644 (file)
@@ -134,7 +134,9 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
                        // check it again just in case)
                        if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
                                $bitmask = RevisionRecord::DELETED_USER;
-                       } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $this->getUser(), 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
index aa88a51..1af4d95 100644 (file)
@@ -199,7 +199,9 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
                        // check it again just in case)
                        if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
                                $bitmask = RevisionRecord::DELETED_USER;
-                       } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
index fe484a8..f9087eb 100644 (file)
@@ -116,7 +116,9 @@ class ApiQueryFilearchive extends ApiQueryBase {
                // Exclude files this user can't view.
                if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedtext' ) ) {
                        $bitmask = File::DELETED_FILE;
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !$this->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $bitmask = File::DELETED_FILE | File::DELETED_RESTRICTED;
                } else {
                        $bitmask = 0;
index 50bd63f..ac7e5cc 100644 (file)
@@ -250,7 +250,9 @@ class ApiQueryInfo extends ApiQueryBase {
         */
        public static function getImportToken( $pageid, $title ) {
                global $wgUser;
-               if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
+               if ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $wgUser, 'import', 'importupload' ) ) {
                        return false;
                }
 
index c995ec5..47a6f87 100644 (file)
@@ -223,7 +223,9 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        if ( !$this->getPermissionManager()->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
                                $titleBits = LogPage::DELETED_ACTION;
                                $userBits = LogPage::DELETED_USER;
-                       } elseif ( !$this->getUser()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $this->getUser(), 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $titleBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
                                $userBits = LogPage::DELETED_USER | LogPage::DELETED_RESTRICTED;
                        } else {
index a74faf2..143d466 100644 (file)
@@ -363,7 +363,9 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
                        if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
                                $bitmask = RevisionRecord::DELETED_USER;
-                       } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
@@ -376,7 +378,9 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        // LogPage::DELETED_ACTION hides the affected page, too.
                        if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
                                $bitmask = LogPage::DELETED_ACTION;
-                       } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                       } elseif ( !$this->getPermissionManager()
+                               ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+                       ) {
                                $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
                        } else {
                                $bitmask = 0;
index 3a06e36..d616ad4 100644 (file)
@@ -335,7 +335,9 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
                                // Paranoia: avoid brute force searches (T19342)
                                if ( !$this->getPermissionManager()->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
                                        $bitmask = RevisionRecord::DELETED_USER;
-                               } elseif ( !$this->getUser()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+                               } elseif ( !$this->getPermissionManager()
+                                       ->userHasAnyRight( $this->getUser(), 'suppressrevision', 'viewsuppressed' )
+                               ) {
                                        $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                                } else {
                                        $bitmask = 0;
index cfefcb2..919c763 100644 (file)
@@ -410,7 +410,9 @@ class ApiQueryUserContribs extends ApiQueryBase {
                $user = $this->getUser();
                if ( !$this->getPermissionManager()->userHasRight( $user, 'deletedhistory' ) ) {
                        $bitmask = RevisionRecord::DELETED_USER;
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !$this->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
                } else {
                        $bitmask = 0;
index c871ce1..4fcaf4e 100644 (file)
@@ -1639,8 +1639,9 @@ class AuthManager implements LoggerAwareInterface {
 
                // Is the IP user able to create accounts?
                $anon = new User;
-               if ( $source !== self::AUTOCREATE_SOURCE_MAINT &&
-                       !$anon->isAllowedAny( 'createaccount', 'autocreateaccount' )
+               if ( $source !== self::AUTOCREATE_SOURCE_MAINT && !MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasAnyRight( $anon, 'createaccount', 'autocreateaccount' )
                ) {
                        $this->logger->debug( __METHOD__ . ': IP lacks the ability to create or autocreate accounts', [
                                'username' => $username,
index e66bd69..66be436 100644 (file)
@@ -565,7 +565,9 @@ class LogEventsList extends ContextSource {
                        }
                        $permissionlist = implode( ', ', $permissions );
                        wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
-                       return $user->isAllowedAny( ...$permissions );
+                       return MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasAnyRight( $user, ...$permissions );
                }
                return true;
        }
index 4ecc368..15b149e 100644 (file)
@@ -23,6 +23,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @ingroup Pager
  */
@@ -462,7 +464,10 @@ class LogPager extends ReverseChronologicalPager {
                $user = $this->getUser();
                if ( !$user->isAllowed( 'deletedhistory' ) ) {
                        $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
                                ' != ' . LogPage::SUPPRESSED_USER;
                }
@@ -480,7 +485,10 @@ class LogPager extends ReverseChronologicalPager {
                $user = $this->getUser();
                if ( !$user->isAllowed( 'deletedhistory' ) ) {
                        $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
                                ' != ' . LogPage::SUPPRESSED_ACTION;
                }
index e488b6c..2de82bf 100644 (file)
@@ -91,7 +91,9 @@ class ImageHistoryList extends ContextSource {
                . Xml::openElement( 'table', [ 'class' => 'wikitable filehistory' ] ) . "\n"
                . '<tr><th></th>'
                . ( $this->current->isLocal()
-               && ( $this->getUser()->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '<th></th>' : '' )
+               && ( MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasAnyRight( $this->getUser(), 'delete', 'deletedhistory' ) ) ? '<th></th>' : '' )
                . '<th>' . $this->msg( 'filehist-datetime' )->escaped() . '</th>'
                . ( $this->showThumb ? '<th>' . $this->msg( 'filehist-thumb' )->escaped() . '</th>' : '' )
                . '<th>' . $this->msg( 'filehist-dimensions' )->escaped() . '</th>'
@@ -126,7 +128,10 @@ class ImageHistoryList extends ContextSource {
                $row = $selected = '';
 
                // Deletion link
-               if ( $local && ( $user->isAllowedAny( 'delete', 'deletedhistory' ) ) ) {
+               if ( $local && ( MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasAnyRight( $user, 'delete', 'deletedhistory' ) )
+               ) {
                        $row .= '<td>';
                        # Link to remove from history
                        if ( $user->isAllowed( 'delete' ) ) {
index 8cc5a39..4607535 100644 (file)
@@ -3249,7 +3249,10 @@ class WikiPage implements Page, IDBAccessObject {
                        $flags |= EDIT_MINOR;
                }
 
-               if ( $bot && ( $guser->isAllowedAny( 'markbotedits', 'bot' ) ) ) {
+               if ( $bot && ( MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasAnyRight( $guser, 'markbotedits', 'bot' ) )
+               ) {
                        $flags |= EDIT_FORCE_BOT;
                }
 
index bbad648..e46f99d 100644 (file)
@@ -238,7 +238,9 @@ abstract class Skin extends ContextSource {
 
                // Add various resources if required
                if ( $user->isLoggedIn()
-                       && $user->isAllowedAll( 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
+                       && MediaWikiServices::getInstance()
+                                ->getPermissionManager()
+                                ->userHasAllRights( $user, 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
                        && $this->getRelevantTitle()->canExist()
                ) {
                        $modules['watch'][] = 'mediawiki.page.watch.ajax';
index af7ec29..f32f2ff 100644 (file)
@@ -1081,7 +1081,10 @@ class SkinTemplate extends Skin {
                                }
 
                                // 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
index c3aec83..f21c206 100644 (file)
@@ -24,6 +24,7 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Permissions\PermissionManager;
 
 /**
@@ -76,7 +77,10 @@ class SpecialImport extends SpecialPage {
                Hooks::run( 'ImportSources', [ &$this->importSources ] );
 
                $user = $this->getUser();
-               if ( !$user->isAllowedAny( 'import', 'importupload' ) ) {
+               if ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $user, 'import', 'importupload' )
+               ) {
                        throw new PermissionsError( 'import' );
                }
 
index 2f0c2ce..c6927c1 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Timestamp\TimestampException;
 
 /**
@@ -264,7 +265,9 @@ class SpecialLog extends SpecialPage {
 
        private function getActionButtons( $formcontents ) {
                $user = $this->getUser();
-               $canRevDelete = $user->isAllowedAll( 'deletedhistory', 'deletelogentry' );
+               $canRevDelete = MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAllRights( $user, 'deletedhistory', 'deletelogentry' );
                $showTagEditUI = ChangeTags::showTagEditingUI( $user );
                # If the user doesn't have the ability to delete log entries nor edit tags,
                # don't bother showing them the button(s).
index 2443470..f5239b4 100644 (file)
@@ -382,7 +382,10 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                // the necessary rights.
                if ( !$user->isAllowed( 'deletedhistory' ) ) {
                        $bitmask = LogPage::DELETED_ACTION;
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
                } else {
                        $bitmask = 0;
index 5dae156..ea23973 100644 (file)
@@ -18,6 +18,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Form to edit user preferences.
  *
@@ -71,7 +73,10 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
         * @return string
         */
        function getButtons() {
-               if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
+               if ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $this->getModifiedUser(), 'editmyprivateinfo', 'editmyoptions' )
+               ) {
                        return '';
                }
 
index 1cb78b8..1fd87f6 100644 (file)
@@ -351,7 +351,10 @@ class ContribsPager extends RangeChronologicalPager {
                        $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;
index 88e1ea8..2f40ace 100644 (file)
@@ -90,7 +90,10 @@ class DeletedContribsPager extends IndexPager {
                // Paranoia: avoid brute force searches (T19792)
                if ( !$user->isAllowed( 'deletedhistory' ) ) {
                        $conds[] = $this->mDb->bitAnd( 'ar_deleted', RevisionRecord::DELETED_USER ) . ' = 0';
-               } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+               } elseif ( !MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
+               ) {
                        $conds[] = $this->mDb->bitAnd( 'ar_deleted', RevisionRecord::SUPPRESSED_USER ) .
                                ' != ' . RevisionRecord::SUPPRESSED_USER;
                }
index 7c2f038..3ed3896 100644 (file)
@@ -3601,32 +3601,28 @@ class User implements IDBAccessObject, UserIdentity {
        /**
         * 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() );
        }
 
        /**
index 30ba1c1..bdce70c 100644 (file)
@@ -29,8 +29,6 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
                // Set up groups and rights
                $this->mUserMock->expects( $this->any() )
                        ->method( 'getEffectiveGroups' )->will( $this->returnValue( [ '*', 'user' ] ) );
-               $this->mUserMock->expects( $this->any() )
-                       ->method( 'isAllowedAny' )->will( $this->returnValue( true ) );
 
                // Set up callback for User::getOptionKinds
                $this->mUserMock->expects( $this->any() )
@@ -49,6 +47,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase {
                $this->mContext->getContext()->setTitle( Title::newFromText( 'Test' ) );
                $this->mContext->setUser( $this->mUserMock );
 
+               $this->overrideUserPermissions( $this->mUserMock, [ 'editmyoptions' ] );
                $main = new ApiMain( $this->mContext );
 
                // Empty session
index 90f6ad9..510a2f2 100644 (file)
@@ -24,7 +24,6 @@ class SpecialPreferencesTest extends MediaWikiTestCase {
        public function testT43337() {
                // Set a low limit
                $this->setMwGlobals( 'wgMaxSigChars', 2 );
-
                $user = $this->createMock( User::class );
                $user->expects( $this->any() )
                        ->method( 'isAnon' )
@@ -47,6 +46,10 @@ class SpecialPreferencesTest extends MediaWikiTestCase {
                $user->method( 'getOptions' )
                        ->willReturn( [] );
 
+               // isAnyAllowed used to return null from the mock,
+               // thus revoke it's permissions.
+               $this->overrideUserPermissions( $user, [] );
+
                # Forge a request to call the special page
                $context = new RequestContext();
                $context->setRequest( new FauxRequest() );