MediaWiki  1.32.0
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 != '' ) {
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  $rcQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
83 
84  $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
85  $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds );
86  $tables = [ 'querycachetwo', 'user', 'rc' => [ 'recentchanges' ] + $rcQuery['tables'] ];
87  $jconds = [
88  'user' => [ 'JOIN', 'user_name = qcc_title' ],
89  'rc' => [ 'JOIN', $rcQuery['fields']['rc_user_text'] . ' = qcc_title' ],
90  ] + $rcQuery['joins'];
91  $conds = [
92  'qcc_type' => 'activeusers',
93  'qcc_namespace' => NS_USER,
94  'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Don't count wikidata.
95  'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ), // Don't count categorization changes.
96  'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
97  'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
98  ];
99  if ( $this->requestedUser != '' ) {
100  $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser );
101  }
102  if ( $this->groups !== [] ) {
103  $tables[] = 'user_groups';
104  $jconds['user_groups'] = [ 'JOIN', [ 'ug_user = user_id' ] ];
105  $conds['ug_group'] = $this->groups;
106  $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() );
107  }
108  if ( $this->excludegroups !== [] ) {
109  foreach ( $this->excludegroups as $group ) {
110  $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
111  'user_groups', '1', [
112  'ug_user = user_id',
113  'ug_group' => $group,
114  'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
115  ]
116  ) . ')';
117  }
118  }
119  if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
120  $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
121  'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
122  ) . ')';
123  }
124 
125  return [
126  'tables' => $tables,
127  'fields' => [
128  'qcc_title',
129  'user_name' => 'qcc_title',
130  'user_id' => 'MAX(user_id)',
131  'recentedits' => 'COUNT(*)'
132  ],
133  'options' => [ 'GROUP BY' => [ 'qcc_title' ] ],
134  'conds' => $conds,
135  'join_conds' => $jconds,
136  ];
137  }
138 
139  function doBatchLookups() {
140  parent::doBatchLookups();
141 
142  $uids = [];
143  foreach ( $this->mResult as $row ) {
144  $uids[] = $row->user_id;
145  }
146  // Fetch the block status of the user for showing "(blocked)" text and for
147  // striking out names of suppressed users when privileged user views the list.
148  // Although the first query already hits the block table for un-privileged, this
149  // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
150  $dbr = $this->getDatabase();
151  $res = $dbr->select( 'ipblocks',
152  [ 'ipb_user', 'MAX(ipb_deleted) AS block_status' ],
153  [ 'ipb_user' => $uids ],
154  __METHOD__,
155  [ 'GROUP BY' => [ 'ipb_user' ] ]
156  );
157  $this->blockStatusByUid = [];
158  foreach ( $res as $row ) {
159  $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1
160  }
161  $this->mResult->seek( 0 );
162  }
163 
164  function formatRow( $row ) {
165  $userName = $row->user_name;
166 
167  $ulinks = Linker::userLink( $row->user_id, $userName );
168  $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
169 
170  $lang = $this->getLanguage();
171 
172  $list = [];
173  $user = User::newFromId( $row->user_id );
174 
175  $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache );
176  foreach ( $ugms as $ugm ) {
177  $list[] = $this->buildGroupLink( $ugm, $userName );
178  }
179 
180  $groups = $lang->commaList( $list );
181 
182  $item = $lang->specialList( $ulinks, $groups );
183 
184  $isBlocked = isset( $this->blockStatusByUid[$row->user_id] );
185  if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) {
186  $item = "<span class=\"deleted\">$item</span>";
187  }
188  $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
189  ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
190  $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
191 
192  return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
193  }
194 
195 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
ActiveUsersPager\__construct
__construct(IContextSource $context=null, FormOptions $opts)
Definition: ActiveUsersPager.php:50
$user
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 account $user
Definition: hooks.txt:244
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:615
RC_EXTERNAL
const RC_EXTERNAL
Definition: Defines.php:145
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:876
ActiveUsersPager\getQueryInfo
getQueryInfo()
Definition: ActiveUsersPager.php:79
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:180
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
UsersPager\buildGroupLink
buildGroupLink( $group, $username)
Format a link to a group description page.
Definition: UsersPager.php:425
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1954
ActiveUsersPager\$blockStatusByUid
array $blockStatusByUid
Definition: ActiveUsersPager.php:44
$tables
this hook is for auditing only 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
IndexPager\getDatabase
getDatabase()
Get the Database object in use.
Definition: IndexPager.php:191
$res
$res
Definition: database.txt:21
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
php
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:35
$dbr
$dbr
Definition: testCompression.php:50
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:128
ActiveUsersPager
This class is used to get a list of active users.
Definition: ActiveUsersPager.php:29
UsersPager
This class is used to get a list of user.
Definition: UsersPager.php:33
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ActiveUsersPager\formatRow
formatRow( $row)
Definition: ActiveUsersPager.php:164
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:573
ActiveUsersPager\getIndexField
getIndexField()
Definition: ActiveUsersPager.php:75
Linker\userToolLinks
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:914
groups
this hook is for auditing only 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)
ActiveUsersPager\$opts
FormOptions $opts
Definition: ActiveUsersPager.php:34
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
UsersPager\getGroupMemberships
static getGroupMemberships( $uid, $cache=null)
Get an associative array containing groups the specified user belongs to, and the relevant UserGroupM...
Definition: UsersPager.php:409
as
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
Definition: distributors.txt:9
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
NS_USER
const NS_USER
Definition: Defines.php:66
ActiveUsersPager\$groups
string[] $groups
Definition: ActiveUsersPager.php:39
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:146
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
ActiveUsersPager\doBatchLookups
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
Definition: ActiveUsersPager.php:139
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:813