MediaWiki  1.28.3
ActiveUsersPager.php
Go to the documentation of this file.
1 <?php
32 
36  protected $opts;
37 
41  protected $hideGroups = [];
42 
46  protected $hideRights = [];
47 
52 
58  parent::__construct( $context );
59 
60  $this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
61  $this->requestedUser = '';
62 
63  $un = $opts->getValue( 'username' );
64  if ( $un != '' ) {
66  if ( !is_null( $username ) ) {
67  $this->requestedUser = $username->getText();
68  }
69  }
70 
71  if ( $opts->getValue( 'hidebots' ) == 1 ) {
72  $this->hideRights[] = 'bot';
73  }
74  if ( $opts->getValue( 'hidesysops' ) == 1 ) {
75  $this->hideGroups[] = 'sysop';
76  }
77  }
78 
79  function getIndexField() {
80  return 'qcc_title';
81  }
82 
83  function getQueryInfo() {
84  $dbr = $this->getDatabase();
85 
86  $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
87  $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds );
88  $conds = [
89  'qcc_type' => 'activeusers',
90  'qcc_namespace' => NS_USER,
91  'user_name = qcc_title',
92  'rc_user_text = qcc_title',
93  'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Don't count wikidata.
94  'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ), // Don't count categorization changes.
95  'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
96  'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
97  ];
98  if ( $this->requestedUser != '' ) {
99  $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser );
100  }
101  if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
102  $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
103  'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
104  ) . ')';
105  }
106 
107  return [
108  'tables' => [ 'querycachetwo', 'user', 'recentchanges' ],
109  'fields' => [ 'user_name', 'user_id', 'recentedits' => 'COUNT(*)', 'qcc_title' ],
110  'options' => [ 'GROUP BY' => [ 'qcc_title' ] ],
111  'conds' => $conds
112  ];
113  }
114 
115  function doBatchLookups() {
116  parent::doBatchLookups();
117 
118  $uids = [];
119  foreach ( $this->mResult as $row ) {
120  $uids[] = $row->user_id;
121  }
122  // Fetch the block status of the user for showing "(blocked)" text and for
123  // striking out names of suppressed users when privileged user views the list.
124  // Although the first query already hits the block table for un-privileged, this
125  // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
126  $dbr = $this->getDatabase();
127  $res = $dbr->select( 'ipblocks',
128  [ 'ipb_user', 'MAX(ipb_deleted) AS block_status' ],
129  [ 'ipb_user' => $uids ],
130  __METHOD__,
131  [ 'GROUP BY' => [ 'ipb_user' ] ]
132  );
133  $this->blockStatusByUid = [];
134  foreach ( $res as $row ) {
135  $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1
136  }
137  $this->mResult->seek( 0 );
138  }
139 
140  function formatRow( $row ) {
141  $userName = $row->user_name;
142 
143  $ulinks = Linker::userLink( $row->user_id, $userName );
144  $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
145 
146  $lang = $this->getLanguage();
147 
148  $list = [];
149  $user = User::newFromId( $row->user_id );
150 
151  // User right filter
152  foreach ( $this->hideRights as $right ) {
153  // Calling User::getRights() within the loop so that
154  // if the hideRights() filter is empty, we don't have to
155  // trigger the lazy-init of the big userrights array in the
156  // User object
157  if ( in_array( $right, $user->getRights() ) ) {
158  return '';
159  }
160  }
161 
162  // User group filter
163  // Note: This is a different loop than for user rights,
164  // because we're reusing it to build the group links
165  // at the same time
166  $groups_list = self::getGroups( intval( $row->user_id ), $this->userGroupCache );
167  foreach ( $groups_list as $group ) {
168  if ( in_array( $group, $this->hideGroups ) ) {
169  return '';
170  }
171  $list[] = self::buildGroupLink( $group, $userName );
172  }
173 
174  $groups = $lang->commaList( $list );
175 
176  $item = $lang->specialList( $ulinks, $groups );
177 
178  $isBlocked = isset( $this->blockStatusByUid[$row->user_id] );
179  if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) {
180  $item = "<span class=\"deleted\">$item</span>";
181  }
182  $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
183  ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
184  $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
185 
186  return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
187  }
188 
189 }
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
const RC_CATEGORIZE
Definition: Defines.php:140
Interface for objects which can provide a MediaWiki context on request.
getLanguage()
Get the Language object.
This class is used to get a list of user.
Definition: UsersPager.php:33
This class is used to get a list of active users.
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
if(!isset($args[0])) $lang
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:548
IContextSource $context
getDatabase()
Get the Database object in use.
Definition: IndexPager.php:187
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: defines.php:6
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
if($limit) $timestamp
$res
Definition: database.txt:21
getConfig()
Get the Config object.
getValue($name)
Get the value for the given option name.
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:535
__construct(IContextSource $context=null, FormOptions $opts)
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
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:246
static userLink($userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:984
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
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:806
static userToolLinks($userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:1017
$count
const RC_EXTERNAL
Definition: Defines.php:139
getUser()
Get the User object.