session: Add debug message for the used store class
[lhc/web/wiklou.git] / includes / Permissions / PermissionManager.php
index f9ad3eb..a361639 100644 (file)
@@ -56,12 +56,10 @@ class PermissionManager {
        const RIGOR_SECURE = 'secure';
 
        /**
-        * TODO Make this const when HHVM support is dropped (T192166)
-        *
         * @since 1.34
         * @var array
         */
-       public static $constructorOptions = [
+       public const CONSTRUCTOR_OPTIONS = [
                'WhitelistRead',
                'WhitelistReadRegexp',
                'EmailConfirmToEdit',
@@ -85,8 +83,8 @@ class PermissionManager {
        /** @var NamespaceInfo */
        private $nsInfo;
 
-       /** @var string[] Cached results of getAllRights() */
-       private $allRights = false;
+       /** @var string[]|null Cached results of getAllRights() */
+       private $allRights;
 
        /** @var string[][] Cached user rights */
        private $usersRights = null;
@@ -97,7 +95,7 @@ class PermissionManager {
         */
        private $temporaryUserRights = [];
 
-       /** @var string[] Cached rights for isEveryoneAllowed */
+       /** @var bool[] Cached rights for isEveryoneAllowed, [ right => allowed ] */
        private $cachedRights = [];
 
        /**
@@ -201,7 +199,7 @@ class PermissionManager {
                RevisionLookup $revisionLookup,
                NamespaceInfo $nsInfo
        ) {
-               $options->assertRequiredOptions( self::$constructorOptions );
+               $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
                $this->options = $options;
                $this->specialPageFactory = $specialPageFactory;
                $this->revisionLookup = $revisionLookup;
@@ -231,6 +229,25 @@ class PermissionManager {
                return !count( $this->getPermissionErrorsInternal( $action, $user, $page, $rigor, true ) );
        }
 
+       /**
+        * A convenience method for calling PermissionManager::userCan
+        * with PermissionManager::RIGOR_QUICK
+        *
+        * Suitable for use for nonessential UI controls in common cases, but
+        * _not_ for functional access control.
+        * May provide false positives, but should never provide a false negative.
+        *
+        * @see PermissionManager::userCan()
+        *
+        * @param string $action
+        * @param User $user
+        * @param LinkTarget $page
+        * @return bool
+        */
+       public function quickUserCan( $action, User $user, LinkTarget $page ) {
+               return $this->userCan( $action, $user, $page, self::RIGOR_QUICK );
+       }
+
        /**
         * Can $user perform $action on a page?
         *
@@ -1201,7 +1218,8 @@ class PermissionManager {
         * Check if user is allowed to make any action
         *
         * @param UserIdentity $user
-        * // TODO: HHVM can't create mocks with variable params @param string ...$actions
+        * // TODO: HHVM bug T228695#5450847 @param string ...$actions
+        * @suppress PhanCommentParamWithoutRealParam
         * @return bool True if user is allowed to perform *any* of the given actions
         * @since 1.34
         */
@@ -1219,7 +1237,8 @@ class PermissionManager {
         * Check if user is allowed to make all actions
         *
         * @param UserIdentity $user
-        * // TODO: HHVM can't create mocks with variable params @param string ...$actions
+        * // TODO: HHVM bug T228695#5450847 @param string ...$actions
+        * @suppress PhanCommentParamWithoutRealParam
         * @return bool True if user is allowed to perform *all* of the given actions
         * @since 1.34
         */
@@ -1450,7 +1469,7 @@ class PermissionManager {
         * @return string[] Array of permission names
         */
        public function getAllPermissions() {
-               if ( $this->allRights === false ) {
+               if ( $this->allRights === null ) {
                        if ( count( $this->options->get( 'AvailableRights' ) ) ) {
                                $this->allRights = array_unique( array_merge(
                                        $this->coreRights,