Merge "Improve wording of imageinfo API userid prop"
[lhc/web/wiklou.git] / includes / UserArray.php
index 51fb154..31bd601 100644 (file)
 
 abstract class UserArray implements Iterator {
        /**
-        * @param $res ResultWrapper
+        * @param ResultWrapper $res
         * @return UserArrayFromResult
         */
        static function newFromResult( $res ) {
                $userArray = null;
-               if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) {
+               if ( !Hooks::run( 'UserArrayFromResult', array( &$userArray, $res ) ) ) {
                        return null;
                }
                if ( $userArray === null ) {
@@ -37,7 +37,7 @@ abstract class UserArray implements Iterator {
        }
 
        /**
-        * @param $ids array
+        * @param array $ids
         * @return UserArrayFromResult
         */
        static function newFromIDs( $ids ) {
@@ -57,7 +57,28 @@ abstract class UserArray implements Iterator {
        }
 
        /**
-        * @param $res
+        * @since 1.25
+        * @param array $names
+        * @return UserArrayFromResult
+        */
+       static function newFromNames( $names ) {
+               $names = array_map( 'strval', (array)$names ); // paranoia
+               if ( !$names ) {
+                       // Database::select() doesn't like empty arrays
+                       return new ArrayIterator( array() );
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       'user',
+                       User::selectFields(),
+                       array( 'user_name' => array_unique( $names ) ),
+                       __METHOD__
+               );
+               return self::newFromResult( $res );
+       }
+
+       /**
+        * @param ResultWrapper $res
         * @return UserArrayFromResult
         */
        protected static function newFromResult_internal( $res ) {