SECURITY: jquery.makeCollapsible: Escape user-generated CSS selectors
[lhc/web/wiklou.git] / includes / user / CentralIdLookup.php
index 2ced6e2..2a86f4a 100644 (file)
@@ -19,6 +19,7 @@
  *
  * @file
  */
+use Wikimedia\ObjectFactory;
 
 /**
  * The CentralIdLookup service allows for connecting local users with
@@ -157,6 +158,27 @@ abstract class CentralIdLookup implements IDBAccessObject {
                return $idToName[$id];
        }
 
+       /**
+        * Given a an array of central user IDs, return the (local) user names.
+        * @param int[] $ids Central user IDs
+        * @param int|User $audience One of the audience constants, or a specific user
+        * @param int $flags IDBAccessObject read flags
+        * @return string[] User names
+        * @since 1.30
+        */
+       public function namesFromCentralIds(
+               array $ids, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
+       ) {
+               $idToName = array_fill_keys( $ids, false );
+               $names = $this->lookupCentralIds( $idToName, $audience, $flags );
+               $names = array_unique( $names );
+               $names = array_filter( $names, function ( $name ) {
+                       return $name !== false && $name !== '';
+               } );
+
+               return array_values( $names );
+       }
+
        /**
         * Given a (local) user name, return the central ID
         * @note There's no requirement that the user name actually exists locally,
@@ -174,6 +196,27 @@ abstract class CentralIdLookup implements IDBAccessObject {
                return $nameToId[$name];
        }
 
+       /**
+        * Given an array of (local) user names, return the central IDs.
+        * @param string[] $names Canonicalized user names
+        * @param int|User $audience One of the audience constants, or a specific user
+        * @param int $flags IDBAccessObject read flags
+        * @return int[] User IDs
+        * @since 1.30
+        */
+       public function centralIdsFromNames(
+               array $names, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
+       ) {
+               $nameToId = array_fill_keys( $names, false );
+               $ids = $this->lookupUserNames( $nameToId, $audience, $flags );
+               $ids = array_unique( $ids );
+               $ids = array_filter( $ids, function ( $id ) {
+                       return $id !== false;
+               } );
+
+               return array_values( $ids );
+       }
+
        /**
         * Given a central user ID, return a local User object
         * @note Unlike nameFromCentralId(), this does guarantee that the local