3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
23 * This class is used to get a list of active users. The ones with specials
24 * rights (sysop, bureaucrat, developer) will have them displayed
25 * next to their names.
29 class ActiveUsersPager
extends UsersPager
{
44 private $blockStatusByUid;
50 private $excludegroups;
53 * @param IContextSource|null $context
54 * @param FormOptions $opts
56 public function __construct( IContextSource
$context = null, FormOptions
$opts ) {
57 parent
::__construct( $context );
59 $this->RCMaxAge
= $this->getConfig()->get( 'ActiveUserDays' );
60 $this->requestedUser
= '';
62 $un = $opts->getValue( 'username' );
64 $username = Title
::makeTitleSafe( NS_USER
, $un );
65 if ( !is_null( $username ) ) {
66 $this->requestedUser
= $username->getText();
70 $this->groups
= $opts->getValue( 'groups' );
71 $this->excludegroups
= $opts->getValue( 'excludegroups' );
72 // Backwards-compatibility with old URLs
73 if ( $opts->getValue( 'hidebots' ) ) {
74 $this->excludegroups
[] = 'bot';
76 if ( $opts->getValue( 'hidesysops' ) ) {
77 $this->excludegroups
[] = 'sysop';
81 function getIndexField() {
85 function getQueryInfo( $data = null ) {
86 $dbr = $this->getDatabase();
88 $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
89 $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX
) - $activeUserSeconds );
90 $fname = __METHOD__
. ' (' . $this->getSqlComment() . ')';
92 // Inner subselect to pull the active users out of querycachetwo
93 $tables = [ 'querycachetwo', 'user', 'actor' ];
94 $fields = [ 'qcc_title', 'user_id', 'actor_id' ];
96 'user' => [ 'JOIN', 'user_name = qcc_title' ],
97 'actor' => [ 'JOIN', 'actor_user = user_id' ],
100 'qcc_type' => 'activeusers',
101 'qcc_namespace' => NS_USER
,
104 if ( $data !== null ) {
105 $options['ORDER BY'] = 'qcc_title ' . $data['order'];
106 $options['LIMIT'] = $data['limit'];
107 $conds = array_merge( $conds, $data['conds'] );
109 if ( $this->requestedUser
!= '' ) {
110 $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser
);
112 if ( $this->groups
!== [] ) {
113 $tables['ug1'] = 'user_groups';
114 $jconds['ug1'] = [ 'JOIN', 'ug1.ug_user = user_id' ];
115 $conds['ug1.ug_group'] = $this->groups
;
116 $conds[] = 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() );
118 if ( $this->excludegroups
!== [] ) {
119 $tables['ug2'] = 'user_groups';
120 $jconds['ug2'] = [ 'LEFT JOIN', [
121 'ug2.ug_user = user_id',
122 'ug2.ug_group' => $this->excludegroups
,
123 'ug2.ug_expiry IS NULL OR ug2.ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ),
125 $conds['ug2.ug_user'] = null;
127 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
128 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
129 'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
132 $subquery = $dbr->buildSelectSubquery( $tables, $fields, $conds, $fname, $options, $jconds );
134 // Outer query to select the recent edit counts for the selected active users
135 $tables = [ 'qcc_users' => $subquery, 'recentchanges' ];
136 $jconds = [ 'recentchanges' => [ 'LEFT JOIN', [
137 'rc_actor = actor_id',
138 'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL
), // Don't count wikidata.
139 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
), // Don't count categorization changes.
140 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
141 'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
149 'user_name' => 'qcc_title',
150 'user_id' => 'user_id',
151 'recentedits' => 'COUNT(rc_id)'
153 'options' => [ 'GROUP BY' => [ 'qcc_title', 'user_id' ] ],
155 'join_conds' => $jconds,
159 protected function buildQueryInfo( $offset, $limit, $order ) {
160 $fname = __METHOD__
. ' (' . $this->getSqlComment() . ')';
162 $sortColumns = array_merge( [ $this->mIndexField
], $this->mExtraSortFields
);
163 if ( $order === self
::QUERY_ASCENDING
) {
165 $orderBy = $sortColumns;
166 $operator = $this->mIncludeOffset ?
'>=' : '>';
170 foreach ( $sortColumns as $col ) {
171 $orderBy[] = $col . ' DESC';
173 $operator = $this->mIncludeOffset ?
'<=' : '<';
175 $info = $this->getQueryInfo( [
176 'limit' => intval( $limit ),
179 $offset != '' ?
[ $this->mIndexField
. $operator . $this->mDb
->addQuotes( $offset ) ] : [],
182 $tables = $info['tables'];
183 $fields = $info['fields'];
184 $conds = $info['conds'];
185 $options = $info['options'];
186 $join_conds = $info['join_conds'];
187 $options['ORDER BY'] = $orderBy;
188 return [ $tables, $fields, $conds, $fname, $options, $join_conds ];
191 protected function doBatchLookups() {
192 parent
::doBatchLookups();
195 foreach ( $this->mResult
as $row ) {
196 $uids[] = $row->user_id
;
198 // Fetch the block status of the user for showing "(blocked)" text and for
199 // striking out names of suppressed users when privileged user views the list.
200 // Although the first query already hits the block table for un-privileged, this
201 // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
202 $dbr = $this->getDatabase();
203 $res = $dbr->select( 'ipblocks',
204 [ 'ipb_user', 'MAX(ipb_deleted) AS deleted, MAX(ipb_sitewide) AS sitewide' ],
205 [ 'ipb_user' => $uids ],
207 [ 'GROUP BY' => [ 'ipb_user' ] ]
209 $this->blockStatusByUid
= [];
210 foreach ( $res as $row ) {
211 $this->blockStatusByUid
[$row->ipb_user
] = [
212 'deleted' => $row->deleted
,
213 'sitewide' => $row->sitewide
,
216 $this->mResult
->seek( 0 );
219 function formatRow( $row ) {
220 $userName = $row->user_name
;
222 $ulinks = Linker
::userLink( $row->user_id
, $userName );
223 $ulinks .= Linker
::userToolLinks(
226 // Should the contributions link be red if the user has no edits (using default)
228 // Customisation flags (using default 0)
230 // User edit count (using default)
232 // do not wrap the message in parentheses (CSS will provide these)
236 $lang = $this->getLanguage();
240 $ugms = self
::getGroupMemberships( intval( $row->user_id
), $this->userGroupCache
);
241 foreach ( $ugms as $ugm ) {
242 $list[] = $this->buildGroupLink( $ugm, $userName );
245 $groups = $lang->commaList( $list );
247 $item = $lang->specialList( $ulinks, $groups );
249 // If there is a block, 'deleted' and 'sitewide' are both set on
250 // $this->blockStatusByUid[$row->user_id].
252 $isBlocked = isset( $this->blockStatusByUid
[$row->user_id
] );
254 if ( $this->blockStatusByUid
[$row->user_id
]['deleted'] == 1 ) {
255 $item = "<span class=\"deleted\">$item</span>";
257 if ( $this->blockStatusByUid
[$row->user_id
]['sitewide'] == 1 ) {
258 $blocked = ' ' . $this->msg( 'listusers-blocked', $userName )->escaped();
261 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits
)
262 ->params( $userName )->numParams( $this->RCMaxAge
)->escaped();
264 return Html
::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );