MediaWiki REL1_29
ActiveUsersPager.php
Go to the documentation of this file.
1<?php
32
36 protected $opts;
37
41 protected $groups;
42
47
53 parent::__construct( $context );
54
55 $this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
56 $this->requestedUser = '';
57
58 $un = $opts->getValue( 'username' );
59 if ( $un != '' ) {
60 $username = Title::makeTitleSafe( NS_USER, $un );
61 if ( !is_null( $username ) ) {
62 $this->requestedUser = $username->getText();
63 }
64 }
65
66 $this->groups = $opts->getValue( 'groups' );
67 $this->excludegroups = $opts->getValue( 'excludegroups' );
68 // Backwards-compatibility with old URLs
69 if ( $opts->getValue( 'hidebots' ) ) {
70 $this->excludegroups[] = 'bot';
71 }
72 if ( $opts->getValue( 'hidesysops' ) ) {
73 $this->excludegroups[] = 'sysop';
74 }
75 }
76
77 function getIndexField() {
78 return 'qcc_title';
79 }
80
81 function getQueryInfo() {
82 $dbr = $this->getDatabase();
83
84 $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
85 $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds );
86 $tables = [ 'querycachetwo', 'user', 'recentchanges' ];
87 $conds = [
88 'qcc_type' => 'activeusers',
89 'qcc_namespace' => NS_USER,
90 'user_name = qcc_title',
91 'rc_user_text = qcc_title',
92 'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Don't count wikidata.
93 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ), // Don't count categorization changes.
94 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
95 'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
96 ];
97 if ( $this->requestedUser != '' ) {
98 $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser );
99 }
100 if ( $this->groups !== [] ) {
101 $tables[] = 'user_groups';
102 $conds[] = 'ug_user = user_id';
103 $conds['ug_group'] = $this->groups;
104 $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() );
105 }
106 if ( $this->excludegroups !== [] ) {
107 foreach ( $this->excludegroups as $group ) {
108 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
109 'user_groups', '1', [
110 'ug_user = user_id',
111 'ug_group' => $group,
112 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
113 ]
114 ) . ')';
115 }
116 }
117 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
118 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
119 'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
120 ) . ')';
121 }
122
123 return [
124 'tables' => $tables,
125 'fields' => [
126 'qcc_title',
127 'user_name' => 'qcc_title',
128 'user_id' => 'MAX(user_id)',
129 'recentedits' => 'COUNT(*)'
130 ],
131 'options' => [ 'GROUP BY' => [ 'qcc_title' ] ],
132 'conds' => $conds
133 ];
134 }
135
136 function doBatchLookups() {
137 parent::doBatchLookups();
138
139 $uids = [];
140 foreach ( $this->mResult as $row ) {
141 $uids[] = $row->user_id;
142 }
143 // Fetch the block status of the user for showing "(blocked)" text and for
144 // striking out names of suppressed users when privileged user views the list.
145 // Although the first query already hits the block table for un-privileged, this
146 // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
147 $dbr = $this->getDatabase();
148 $res = $dbr->select( 'ipblocks',
149 [ 'ipb_user', 'MAX(ipb_deleted) AS block_status' ],
150 [ 'ipb_user' => $uids ],
151 __METHOD__,
152 [ 'GROUP BY' => [ 'ipb_user' ] ]
153 );
154 $this->blockStatusByUid = [];
155 foreach ( $res as $row ) {
156 $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1
157 }
158 $this->mResult->seek( 0 );
159 }
160
161 function formatRow( $row ) {
162 $userName = $row->user_name;
163
164 $ulinks = Linker::userLink( $row->user_id, $userName );
165 $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
166
167 $lang = $this->getLanguage();
168
169 $list = [];
170 $user = User::newFromId( $row->user_id );
171
172 $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache );
173 foreach ( $ugms as $ugm ) {
174 $list[] = $this->buildGroupLink( $ugm, $userName );
175 }
176
177 $groups = $lang->commaList( $list );
178
179 $item = $lang->specialList( $ulinks, $groups );
180
181 $isBlocked = isset( $this->blockStatusByUid[$row->user_id] );
182 if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) {
183 $item = "<span class=\"deleted\">$item</span>";
184 }
185 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
186 ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
187 $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
188
189 return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
190 }
191
192}
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.
getUser()
Get the User object.
getConfig()
Get the Config object.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
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:888
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:921
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...
$res
Definition database.txt:21
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_USER
Definition Defines.php:64
const RC_EXTERNAL
Definition Defines.php:143
const RC_CATEGORIZE
Definition Defines.php:144
the array() calling protocol came about after MediaWiki 1.4rc1.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:249
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2728
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:1018
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)
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:785
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Interface for objects which can provide a MediaWiki context on request.
if(!isset( $args[0])) $lang