* Rename wfGetAvailableRights() to User::getAllRights()
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 7 May 2008 06:42:16 +0000 (06:42 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 7 May 2008 06:42:16 +0000 (06:42 +0000)
* Reintroduce $wgAvailableRights so that the above function is not so terribly slow and broken

includes/DefaultSettings.php
includes/Defines.php
includes/GlobalFunctions.php
includes/User.php

index 4ac2eb2..281e511 100644 (file)
@@ -1282,6 +1282,13 @@ $wgAutopromote = array(
  */
 $wgAddGroups = $wgRemoveGroups = array();
 
+
+/**
+ * A list of available rights, in addition to the ones defined by the core. 
+ * For extensions only.
+ */
+$wgAvailableRights = array();
+
 /**
  * Optional to restrict deletion of pages with higher revision counts
  * to users with the 'bigdelete' permission. (Default given to sysops.)
index 9ef22cb..b0275ec 100644 (file)
@@ -84,30 +84,6 @@ define( 'MW_MATH_MODERN', 4 );
 define( 'MW_MATH_MATHML', 5 );
 /**#@-*/
 
-/**
- * User rights list
- * @deprecated
- */
-$wgAvailableRights = array(
-       'block',
-       'bot',
-       'createaccount',
-       'delete',
-       'edit',
-       'editinterface',
-       'import',
-       'importupload',
-       'move',
-       'patrol',
-       'protect',
-       'read',
-       'rollback',
-       'siteadmin',
-       'unwatchedpages',
-       'upload',
-       'userrights',
-);
-
 /**#@+
  * Cache type
  */
index 27b5a5d..07cfdf6 100644 (file)
@@ -2608,23 +2608,3 @@ function wfWaitForSlaves( $maxLag ) {
 
        return md5( mt_rand( 0, 0x7fffffff ) . $salt );
 }
-
-/**
- * Generate a list of all available rights.
- * @todo Doesn't list any rights which aren't assigned to a group.
- */
-function wfGetAvailableRights() {
-       global $wgGroupPermissions;
-       
-       $rights = array();
-       
-       foreach( $wgGroupPermissions as $permissions ) {
-               $rights = array_merge( array_keys($permissions),$rights );
-       }
-       
-       $rights = array_unique($rights);
-       
-       wfRunHooks( 'GetAvailableRights', array( &$rights ) );
-       
-       return $rights;
-}
index 103b911..464966c 100644 (file)
@@ -105,6 +105,52 @@ class User {
                'mGroups',
        );
 
+       /**
+        * Core rights
+        * Each of these should have a corresponding message of the form "right-$right"
+        */
+       static $mCoreRights = array(
+               'apihighlimits',
+               'autoconfirmed',
+               'autopatrol',
+               'bigdelete',
+               'block',
+               'blockemail',
+               'bot',
+               'browsearchive',
+               'createaccount',
+               'createpage',
+               'createtalk',
+               'delete',
+               'deletedhistory',
+               'edit',
+               'editinterface',
+               'editusercssjs',
+               'import',
+               'importupload',
+               'ipblock-exempt',
+               'markbotedits',
+               'minoredit',
+               'move',
+               'nominornewtalk',
+               'patrol',
+               'protect',
+               'proxyunbannable',
+               'purge',
+               'read',
+               'reupload',
+               'reupload-shared',
+               'rollback',
+               'suppressredirect',
+               'trackback',
+               'undelete',
+               'unwatchedpages',
+               'upload',
+               'upload_by_url',
+               'userrights',
+       );
+       static $mAllRights = false;
+
        /**
         * The cache variable declarations
         */
@@ -2716,6 +2762,22 @@ class User {
                );
        }
 
+       /**
+        * Get a list of all available permissions
+        */
+       static function getAllRights() {
+               if ( self::$mAllRights === false ) {
+                       global $wgAvailableRights;
+                       if ( count( $wgAvailableRights ) ) {
+                               self::$mAllRights = array_unique( array_merge( self::$mCoreRights, $wgAvailableRights ) );
+                       } else {
+                               self::$mAllRights = self::$mCoreRights;
+                       }
+                       wfRunHooks( 'UserGetAllRights', array( &self::$mAllRights ) );
+               }
+               return self::$mAllRights;
+       }
+
        /**
         * Get a list of implicit groups
         *