UserCache::getUserName: Docs said @since 1.21, but not in REL1_21
[lhc/web/wiklou.git] / includes / cache / UserCache.php
index 6ec2366..6085f58 100644 (file)
@@ -45,7 +45,7 @@ class UserCache {
         * Get a property of a user based on their user ID
         *
         * @param $userId integer User ID
-        * @param $prop string User property
+        * @param string $prop User property
         * @return mixed The property or false if the user does not exist
         */
        public function getProp( $userId, $prop ) {
@@ -58,11 +58,22 @@ class UserCache {
                        : false; // user does not exist?
        }
 
+       /**
+        * Get the name of a user or return $ip if the user ID is 0
+        *
+        * @param integer $userId
+        * @param string $ip
+        * @since 1.22
+        */
+       public function getUserName( $userId, $ip ) {
+               return $userId > 0 ? $this->getProp( $userId, 'name' ) : $ip;
+       }
+
        /**
         * Preloads user names for given list of users.
-        * @param $userIds Array List of user IDs
-        * @param $options Array Option flags; include 'userpage' and 'usertalk'
-        * @param $caller String: the calling method
+        * @param array $userIds List of user IDs
+        * @param array $options Option flags; include 'userpage' and 'usertalk'
+        * @param string $caller the calling method
         */
        public function doQuery( array $userIds, $options = array(), $caller = '' ) {
                wfProfileIn( __METHOD__ );
@@ -70,6 +81,8 @@ class UserCache {
                $usersToCheck = array();
                $usersToQuery = array();
 
+               $userIds = array_unique( $userIds );
+
                foreach ( $userIds as $userId ) {
                        $userId = (int)$userId;
                        if ( $userId <= 0 ) {
@@ -124,8 +137,8 @@ class UserCache {
         * Check if a cache type is in $options and was not loaded for this user
         *
         * @param $uid integer user ID
-        * @param $type string Cache type
-        * @param $options Array Requested cache types
+        * @param string $type Cache type
+        * @param array $options Requested cache types
         * @return bool
         */
        protected function queryNeeded( $uid, $type, array $options ) {