RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' ); $this->requestedUser = ''; $un = $opts->getValue( 'username' ); if ( $un != '' ) { $username = Title::makeTitleSafe( NS_USER, $un ); if ( !is_null( $username ) ) { $this->requestedUser = $username->getText(); } } $this->groups = $opts->getValue( 'groups' ); $this->excludegroups = $opts->getValue( 'excludegroups' ); // Backwards-compatibility with old URLs if ( $opts->getValue( 'hidebots' ) ) { $this->excludegroups[] = 'bot'; } if ( $opts->getValue( 'hidesysops' ) ) { $this->excludegroups[] = 'sysop'; } } function getIndexField() { return 'qcc_title'; } function getQueryInfo() { $dbr = $this->getDatabase(); $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400; $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds ); $tables = [ 'querycachetwo', 'user', 'recentchanges' ]; $conds = [ 'qcc_type' => 'activeusers', 'qcc_namespace' => NS_USER, 'user_name = qcc_title', 'rc_user_text = qcc_title', 'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Don't count wikidata. 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ), // Don't count categorization changes. 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ), 'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ), ]; if ( $this->requestedUser != '' ) { $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser ); } if ( $this->groups !== [] ) { $tables[] = 'user_groups'; $conds[] = 'ug_user = user_id'; $conds['ug_group'] = $this->groups; $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ); } if ( $this->excludegroups !== [] ) { foreach ( $this->excludegroups as $group ) { $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText( 'user_groups', '1', [ 'ug_user = user_id', 'ug_group' => $group, 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ) ] ) . ')'; } } if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText( 'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ] ) . ')'; } if ( $dbr->implicitGroupby() ) { $options = [ 'GROUP BY' => [ 'qcc_title' ] ]; } else { $options = [ 'GROUP BY' => [ 'user_name', 'user_id', 'qcc_title' ] ]; } return [ 'tables' => $tables, 'fields' => [ 'user_name', 'user_id', 'recentedits' => 'COUNT(*)', 'qcc_title' ], 'options' => $options, 'conds' => $conds ]; } function doBatchLookups() { parent::doBatchLookups(); $uids = []; foreach ( $this->mResult as $row ) { $uids[] = $row->user_id; } // Fetch the block status of the user for showing "(blocked)" text and for // striking out names of suppressed users when privileged user views the list. // Although the first query already hits the block table for un-privileged, this // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct. $dbr = $this->getDatabase(); $res = $dbr->select( 'ipblocks', [ 'ipb_user', 'MAX(ipb_deleted) AS block_status' ], [ 'ipb_user' => $uids ], __METHOD__, [ 'GROUP BY' => [ 'ipb_user' ] ] ); $this->blockStatusByUid = []; foreach ( $res as $row ) { $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1 } $this->mResult->seek( 0 ); } function formatRow( $row ) { $userName = $row->user_name; $ulinks = Linker::userLink( $row->user_id, $userName ); $ulinks .= Linker::userToolLinks( $row->user_id, $userName ); $lang = $this->getLanguage(); $list = []; $user = User::newFromId( $row->user_id ); $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache ); foreach ( $ugms as $ugm ) { $list[] = $this->buildGroupLink( $ugm, $userName ); } $groups = $lang->commaList( $list ); $item = $lang->specialList( $ulinks, $groups ); $isBlocked = isset( $this->blockStatusByUid[$row->user_id] ); if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) { $item = "$item"; } $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits ) ->params( $userName )->numParams( $this->RCMaxAge )->escaped(); $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : ''; return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" ); } }