return self::$idCacheByName[$name];
}
- $db = ( $flags & self::READ_LATEST )
- ? wfGetDB( DB_MASTER )
- : wfGetDB( DB_SLAVE );
+ list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
+ $db = wfGetDB( $index );
$s = $db->selectRow(
'user',
[ 'user_id' ],
[ 'user_name' => $nt->getText() ],
- __METHOD__
+ __METHOD__,
+ $options
);
if ( $s === false ) {
return true;
}
+ /**
+ * Return the users who are members of the given group(s). In case of multiple groups,
+ * users who are members of at least one of them are returned.
+ *
+ * @param string|array $groups A single group name or an array of group names
+ * @param int $limit Max number of users to return. The actual limit will never exceed 5000
+ * records; larger values are ignored.
+ * @param int $after ID the user to start after
+ * @return UserArrayFromResult
+ */
+ public static function findUsersByGroup( $groups, $limit = 5000, $after = null ) {
+ if ( $groups === [] ) {
+ return UserArrayFromResult::newFromIDs( [] );
+ }
+
+ $groups = array_unique( (array)$groups );
+ $limit = min( 5000, $limit );
+
+ $conds = [ 'ug_group' => $groups ];
+ if ( $after !== null ) {
+ $conds[] = 'ug_user > ' . (int)$after;
+ }
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $ids = $dbr->selectFieldValues(
+ 'user_groups',
+ 'ug_user',
+ $conds,
+ __METHOD__,
+ [
+ 'DISTINCT' => true,
+ 'ORDER BY' => 'ug_user',
+ 'LIMIT' => $limit,
+ ]
+ ) ?: [];
+ return UserArray::newFromIDs( $ids );
+ }
+
/**
* Usernames which fail to pass this function will be blocked
* from new account registrations, but may be used internally
* @return string|bool User's current value for the option, or false if this option is disabled.
* @see resetTokenFromOption()
* @see getOption()
- * @deprecated 1.26 Applications should use the OAuth extension
+ * @deprecated since 1.26 Applications should use the OAuth extension
*/
public function getTokenFromOption( $oname ) {
global $wgHiddenPrefs;