MediaWiki REL1_30
ActiveUsersPager.php
Go to the documentation of this file.
1<?php
30
34 protected $opts;
35
39 protected $groups;
40
45
51 parent::__construct( $context );
52
53 $this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
54 $this->requestedUser = '';
55
56 $un = $opts->getValue( 'username' );
57 if ( $un != '' ) {
58 $username = Title::makeTitleSafe( NS_USER, $un );
59 if ( !is_null( $username ) ) {
60 $this->requestedUser = $username->getText();
61 }
62 }
63
64 $this->groups = $opts->getValue( 'groups' );
65 $this->excludegroups = $opts->getValue( 'excludegroups' );
66 // Backwards-compatibility with old URLs
67 if ( $opts->getValue( 'hidebots' ) ) {
68 $this->excludegroups[] = 'bot';
69 }
70 if ( $opts->getValue( 'hidesysops' ) ) {
71 $this->excludegroups[] = 'sysop';
72 }
73 }
74
75 function getIndexField() {
76 return 'qcc_title';
77 }
78
79 function getQueryInfo() {
80 $dbr = $this->getDatabase();
81
82 $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
83 $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds );
84 $tables = [ 'querycachetwo', 'user', 'recentchanges' ];
85 $conds = [
86 'qcc_type' => 'activeusers',
87 'qcc_namespace' => NS_USER,
88 'user_name = qcc_title',
89 'rc_user_text = qcc_title',
90 'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Don't count wikidata.
91 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ), // Don't count categorization changes.
92 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
93 'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
94 ];
95 if ( $this->requestedUser != '' ) {
96 $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser );
97 }
98 if ( $this->groups !== [] ) {
99 $tables[] = 'user_groups';
100 $conds[] = 'ug_user = user_id';
101 $conds['ug_group'] = $this->groups;
102 $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() );
103 }
104 if ( $this->excludegroups !== [] ) {
105 foreach ( $this->excludegroups as $group ) {
106 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
107 'user_groups', '1', [
108 'ug_user = user_id',
109 'ug_group' => $group,
110 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
111 ]
112 ) . ')';
113 }
114 }
115 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
116 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
117 'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
118 ) . ')';
119 }
120
121 return [
122 'tables' => $tables,
123 'fields' => [
124 'qcc_title',
125 'user_name' => 'qcc_title',
126 'user_id' => 'MAX(user_id)',
127 'recentedits' => 'COUNT(*)'
128 ],
129 'options' => [ 'GROUP BY' => [ 'qcc_title' ] ],
130 'conds' => $conds
131 ];
132 }
133
134 function doBatchLookups() {
135 parent::doBatchLookups();
136
137 $uids = [];
138 foreach ( $this->mResult as $row ) {
139 $uids[] = $row->user_id;
140 }
141 // Fetch the block status of the user for showing "(blocked)" text and for
142 // striking out names of suppressed users when privileged user views the list.
143 // Although the first query already hits the block table for un-privileged, this
144 // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
145 $dbr = $this->getDatabase();
146 $res = $dbr->select( 'ipblocks',
147 [ 'ipb_user', 'MAX(ipb_deleted) AS block_status' ],
148 [ 'ipb_user' => $uids ],
149 __METHOD__,
150 [ 'GROUP BY' => [ 'ipb_user' ] ]
151 );
152 $this->blockStatusByUid = [];
153 foreach ( $res as $row ) {
154 $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1
155 }
156 $this->mResult->seek( 0 );
157 }
158
159 function formatRow( $row ) {
160 $userName = $row->user_name;
161
162 $ulinks = Linker::userLink( $row->user_id, $userName );
163 $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
164
165 $lang = $this->getLanguage();
166
167 $list = [];
168 $user = User::newFromId( $row->user_id );
169
170 $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache );
171 foreach ( $ugms as $ugm ) {
172 $list[] = $this->buildGroupLink( $ugm, $userName );
173 }
174
175 $groups = $lang->commaList( $list );
176
177 $item = $lang->specialList( $ulinks, $groups );
178
179 $isBlocked = isset( $this->blockStatusByUid[$row->user_id] );
180 if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) {
181 $item = "<span class=\"deleted\">$item</span>";
182 }
183 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
184 ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
185 $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
186
187 return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
188 }
189
190}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This class is used to get a list of active users.
__construct(IContextSource $context=null, FormOptions $opts)
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getUser()
Get the User object.
getConfig()
Get the Config object.
getLanguage()
Get the Language object.
Helper class to keep track of options when mixing links and form elements.
getValue( $name)
Get the value for the given option name.
getDatabase()
Get the Database object in use.
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:893
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:926
This class is used to get a list of user.
buildGroupLink( $group, $username)
Format a link to a group description page.
static getGroupMemberships( $uid, $cache=null)
Get an associative array containing groups the specified user belongs to, and the relevant UserGroupM...
if(! $regexes) $dbr
Definition cleanup.php:94
$res
Definition database.txt:21
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1013
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing groups(accessed through $special->getFilterGroup)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2780
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:783
const NS_USER
Definition Defines.php:67
const RC_EXTERNAL
Definition Defines.php:146
const RC_CATEGORIZE
Definition Defines.php:147
Interface for objects which can provide a MediaWiki context on request.
if(!isset( $args[0])) $lang