- if(empty($goodNames))
- return $retval;
-
- $db = $this->getDb();
- $userTable = $db->tableName('user');
- $tables = "$userTable AS u1";
- $this->addFields('u1.user_name');
- $this->addWhereFld('u1.user_name', $goodNames);
- $this->addFieldsIf('u1.user_editcount', isset($this->prop['editcount']));
-
- if(isset($this->prop['groups'])) {
- $ug = $db->tableName('user_groups');
- $tables = "$tables LEFT JOIN $ug ON `ug_user`=`u1`.`user_id`";
- $this->addFields('ug_group');
- }
- if(isset($this->prop['blockinfo'])) {
- $ipb = $db->tableName('ipblocks');
- $tables = "$tables LEFT JOIN $ipb ON `ipb_user`=`u1`.`user_id`";
- $tables = "$tables LEFT JOIN $userTable AS u2 ON `ipb_by`=`u2`.`user_id`";
- $this->addFields(array('ipb_reason', 'u2.user_name AS blocker_name'));
- }
- $this->addTables($tables);
-
- $data = array();
- $res = $this->select(__METHOD__);
- while(($r = $db->fetchObject($res))) {
- $data[$r->user_name]['name'] = $r->user_name;
- if(isset($this->prop['editcount']))
- $data[$r->user_name]['editcount'] = $r->user_editcount;
- if(isset($this->prop['groups']))
- // This row contains only one group, others will be added from other rows
- if(!is_null($r->ug_group))
- $data[$r->user_name]['groups'][] = $r->ug_group;
- if(isset($this->prop['blockinfo']))
- if(!is_null($r->blocker_name)) {
- $data[$r->user_name]['blockedby'] = $r->blocker_name;
- $data[$r->user_name]['blockreason'] = $r->ipb_reason;
+
+ if ( count( $goodNames ) ) {
+ $db = $this->getDb();
+ $this->addTables( 'user', 'u1' );
+ $this->addFields( 'u1.*' );
+ $this->addWhereFld( 'u1.user_name', $goodNames );
+
+ if ( isset( $this->prop['groups'] ) ) {
+ $this->addTables( 'user_groups' );
+ $this->addJoinConds( array( 'user_groups' => array( 'LEFT JOIN', 'ug_user=u1.user_id' ) ) );
+ $this->addFields( 'ug_group' );
+ }
+ if ( isset( $this->prop['blockinfo'] ) ) {
+ $this->addTables( 'ipblocks' );
+ $this->addTables( 'user', 'u2' );
+ $u2 = $this->getAliasedName( 'user', 'u2' );
+ $this->addJoinConds( array(
+ 'ipblocks' => array( 'LEFT JOIN', 'ipb_user=u1.user_id' ),
+ $u2 => array( 'LEFT JOIN', 'ipb_by=u2.user_id' ) ) );
+ $this->addFields( array( 'ipb_reason', 'u2.user_name AS blocker_name' ) );
+ }
+
+ $data = array();
+ $res = $this->select( __METHOD__ );
+ while ( ( $r = $db->fetchObject( $res ) ) ) {
+ $user = User::newFromRow( $r );
+ $name = $user->getName();
+ $data[$name]['name'] = $name;
+ if ( isset( $this->prop['editcount'] ) ) {
+ $data[$name]['editcount'] = intval( $user->getEditCount() );
+ }
+ if ( isset( $this->prop['registration'] ) ) {
+ $data[$name]['registration'] = wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
+ }
+ if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) ) {
+ // This row contains only one group, others will be added from other rows
+ $data[$name]['groups'][] = $r->ug_group;
+ }
+ if ( isset( $this->prop['blockinfo'] ) && !is_null( $r->blocker_name ) ) {
+ $data[$name]['blockedby'] = $r->blocker_name;
+ $data[$name]['blockreason'] = $r->ipb_reason;
+ }
+ if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) {
+ $data[$name]['emailable'] = '';
+ }
+
+ if ( isset( $this->prop['gender'] ) ) {
+ $gender = $user->getOption( 'gender' );
+ if ( strval( $gender ) === '' ) {
+ $gender = 'unknown';
+ }
+ $data[$name]['gender'] = $gender;