MediaWiki  1.27.2
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  function __construct( IContextSource $context = null, $group = null, $par = null ) {
59  parent::__construct( $context );
60 
61  $this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
62  $un = $this->getRequest()->getText( 'username', $par );
63  $this->requestedUser = '';
64  if ( $un != '' ) {
66  if ( !is_null( $username ) ) {
67  $this->requestedUser = $username->getText();
68  }
69  }
70 
71  $this->setupOptions();
72  }
73 
74  public function setupOptions() {
75  $this->opts = new FormOptions();
76 
77  $this->opts->add( 'hidebots', false, FormOptions::BOOL );
78  $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
79 
80  $this->opts->fetchValuesFromRequest( $this->getRequest() );
81 
82  if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
83  $this->hideRights[] = 'bot';
84  }
85  if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
86  $this->hideGroups[] = 'sysop';
87  }
88  }
89 
90  function getIndexField() {
91  return 'qcc_title';
92  }
93 
94  function getQueryInfo() {
95  $dbr = $this->getDatabase();
96 
97  $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
98  $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX ) - $activeUserSeconds );
99  $conds = [
100  'qcc_type' => 'activeusers',
101  'qcc_namespace' => NS_USER,
102  'user_name = qcc_title',
103  'rc_user_text = qcc_title',
104  'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL ), // Don't count wikidata.
105  'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE ), // Don't count categorization changes.
106  'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
107  'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
108  ];
109  if ( $this->requestedUser != '' ) {
110  $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser );
111  }
112  if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
113  $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
114  'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
115  ) . ')';
116  }
117 
118  if ( $dbr->implicitGroupby() ) {
119  $options = [ 'GROUP BY' => [ 'qcc_title' ] ];
120  } else {
121  $options = [ 'GROUP BY' => [ 'user_name', 'user_id', 'qcc_title' ] ];
122  }
123 
124  return [
125  'tables' => [ 'querycachetwo', 'user', 'recentchanges' ],
126  'fields' => [ 'user_name', 'user_id', 'recentedits' => 'COUNT(*)', 'qcc_title' ],
127  'options' => $options,
128  'conds' => $conds
129  ];
130  }
131 
132  function doBatchLookups() {
133  parent::doBatchLookups();
134 
135  $uids = [];
136  foreach ( $this->mResult as $row ) {
137  $uids[] = $row->user_id;
138  }
139  // Fetch the block status of the user for showing "(blocked)" text and for
140  // striking out names of suppressed users when privileged user views the list.
141  // Although the first query already hits the block table for un-privileged, this
142  // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
143  $dbr = $this->getDatabase();
144  $res = $dbr->select( 'ipblocks',
145  [ 'ipb_user', 'MAX(ipb_deleted) AS block_status' ],
146  [ 'ipb_user' => $uids ],
147  __METHOD__,
148  [ 'GROUP BY' => [ 'ipb_user' ] ]
149  );
150  $this->blockStatusByUid = [];
151  foreach ( $res as $row ) {
152  $this->blockStatusByUid[$row->ipb_user] = $row->block_status; // 0 or 1
153  }
154  $this->mResult->seek( 0 );
155  }
156 
157  function formatRow( $row ) {
158  $userName = $row->user_name;
159 
160  $ulinks = Linker::userLink( $row->user_id, $userName );
161  $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
162 
163  $lang = $this->getLanguage();
164 
165  $list = [];
166  $user = User::newFromId( $row->user_id );
167 
168  // User right filter
169  foreach ( $this->hideRights as $right ) {
170  // Calling User::getRights() within the loop so that
171  // if the hideRights() filter is empty, we don't have to
172  // trigger the lazy-init of the big userrights array in the
173  // User object
174  if ( in_array( $right, $user->getRights() ) ) {
175  return '';
176  }
177  }
178 
179  // User group filter
180  // Note: This is a different loop than for user rights,
181  // because we're reusing it to build the group links
182  // at the same time
183  $groups_list = self::getGroups( intval( $row->user_id ), $this->userGroupCache );
184  foreach ( $groups_list as $group ) {
185  if ( in_array( $group, $this->hideGroups ) ) {
186  return '';
187  }
188  $list[] = self::buildGroupLink( $group, $userName );
189  }
190 
191  $groups = $lang->commaList( $list );
192 
193  $item = $lang->specialList( $ulinks, $groups );
194 
195  $isBlocked = isset( $this->blockStatusByUid[$row->user_id] );
196  if ( $isBlocked && $this->blockStatusByUid[$row->user_id] == 1 ) {
197  $item = "<span class=\"deleted\">$item</span>";
198  }
199  $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
200  ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
201  $blocked = $isBlocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
202 
203  return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
204  }
205 
206  function getPageHeader() {
207  $self = $this->getTitle();
208  $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
209 
210  # Form tag
211  $out = Xml::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] );
212  $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
213  $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
214 
215  # Username field (with autocompletion support)
216  $this->getOutput()->addModules( 'mediawiki.userSuggest' );
218  $this->msg( 'activeusers-from' )->text(),
219  'username',
220  'offset',
221  20,
222  $this->requestedUser,
223  [
224  'class' => 'mw-ui-input-inline mw-autocomplete-user',
225  'tabindex' => 1,
226  ] + (
227  // Set autofocus on blank input
228  $this->requestedUser === '' ? [ 'autofocus' => '' ] : []
229  )
230  ) . '<br />';
231 
232  $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
233  'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ), [ 'tabindex' => 2 ] );
234 
236  $this->msg( 'activeusers-hidesysops' )->text(),
237  'hidesysops',
238  'hidesysops',
239  $this->opts->getValue( 'hidesysops' ),
240  [ 'tabindex' => 3 ]
241  ) . '<br />';
242 
243  # Submit button and form bottom
245  $this->msg( 'activeusers-submit' )->text(),
246  [ 'tabindex' => 4 ]
247  ) . "\n";
248  $out .= Xml::closeElement( 'fieldset' );
249  $out .= Xml::closeElement( 'form' );
250 
251  return $out;
252  }
253 
254 }
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
const RC_CATEGORIZE
Definition: Defines.php:173
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
Definition: FormOptions.php:50
Interface for objects which can provide a MediaWiki context on request.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:762
getLanguage()
Get the Language object.
This class is used to get a list of user.
Definition: UsersPager.php:33
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
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:210
if(!isset($args[0])) $lang
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:759
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:591
static inputLabel($label, $name, $id, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field with a label.
Definition: Xml.php:381
IContextSource $context
getTitle()
Get the Title object.
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:460
getDatabase()
Get the Database object in use.
Definition: IndexPager.php:187
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getRequest()
Get the WebRequest object.
static fieldset($legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:578
static closeElement($element)
Shortcut to close an XML element.
Definition: Xml.php:118
msg()
Get a Message object with context set Parameters are the same as wfMessage()
if($limit) $timestamp
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1004
$self
$res
Definition: database.txt:21
getConfig()
Get the Config object.
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:548
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
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:242
static userLink($userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1102
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:762
__construct(IContextSource $context=null, $group=null, $par=null)
static userToolLinks($userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:1133
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1004
$count
static checkLabel($label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:420
const RC_EXTERNAL
Definition: Defines.php:172
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
getUser()
Get the User object.
getOutput()
Get the OutputPage object.