Add UserArray::newFromNames()
authorKunal Mehta <legoktm@gmail.com>
Tue, 24 Feb 2015 20:46:13 +0000 (12:46 -0800)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 26 Feb 2015 19:18:35 +0000 (19:18 +0000)
Change-Id: I91bb8349dd846e982be9294c7f4f3858995ad2eb

includes/UserArray.php

index e5621da..31bd601 100644 (file)
@@ -56,6 +56,27 @@ abstract class UserArray implements Iterator {
                return self::newFromResult( $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