MediaWiki REL1_33
UsersPager.php
Go to the documentation of this file.
1<?php
34
38 protected $userGroupCache;
39
46 public function __construct( IContextSource $context = null, $par = null, $including = null ) {
47 if ( $context ) {
48 $this->setContext( $context );
49 }
50
51 $request = $this->getRequest();
52 $par = ( $par !== null ) ? $par : '';
53 $parms = explode( '/', $par );
54 $symsForAll = [ '*', 'user' ];
55
56 if ( $parms[0] != '' &&
57 ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) )
58 ) {
59 $this->requestedGroup = $par;
60 $un = $request->getText( 'username' );
61 } elseif ( count( $parms ) == 2 ) {
62 $this->requestedGroup = $parms[0];
63 $un = $parms[1];
64 } else {
65 $this->requestedGroup = $request->getVal( 'group' );
66 $un = ( $par != '' ) ? $par : $request->getText( 'username' );
67 }
68
69 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
70 $this->requestedGroup = '';
71 }
72 $this->editsOnly = $request->getBool( 'editsOnly' );
73 $this->temporaryGroupsOnly = $request->getBool( 'temporaryGroupsOnly' );
74 $this->creationSort = $request->getBool( 'creationSort' );
75 $this->including = $including;
76 $this->mDefaultDirection = $request->getBool( 'desc' )
79
80 $this->requestedUser = '';
81
82 if ( $un != '' ) {
83 $username = Title::makeTitleSafe( NS_USER, $un );
84
85 if ( !is_null( $username ) ) {
86 $this->requestedUser = $username->getText();
87 }
88 }
89
90 parent::__construct();
91 }
92
96 function getIndexField() {
97 return $this->creationSort ? 'user_id' : 'user_name';
98 }
99
103 function getQueryInfo() {
105 $conds = [];
106
107 // Don't show hidden names
108 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
109 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
110 }
111
112 $options = [];
113
114 if ( $this->requestedGroup != '' || $this->temporaryGroupsOnly ) {
115 $conds[] = 'ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ) .
116 ( !$this->temporaryGroupsOnly ? ' OR ug_expiry IS NULL' : '' );
117 }
118
119 if ( $this->requestedGroup != '' ) {
120 $conds['ug_group'] = $this->requestedGroup;
121 }
122
123 if ( $this->requestedUser != '' ) {
124 # Sorted either by account creation or name
125 if ( $this->creationSort ) {
126 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
127 } else {
128 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
129 }
130 }
131
132 if ( $this->editsOnly ) {
133 $conds[] = 'user_editcount > 0';
134 }
135
136 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name';
137
138 $query = [
139 'tables' => [ 'user', 'user_groups', 'ipblocks' ],
140 'fields' => [
141 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name',
142 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)',
143 'edits' => 'MAX(user_editcount)',
144 'creation' => 'MIN(user_registration)',
145 'ipb_deleted' => 'MAX(ipb_deleted)', // block/hide status
146 'ipb_sitewide' => 'MAX(ipb_sitewide)'
147 ],
148 'options' => $options,
149 'join_conds' => [
150 'user_groups' => [ 'LEFT JOIN', 'user_id=ug_user' ],
151 'ipblocks' => [
152 'LEFT JOIN', [
153 'user_id=ipb_user',
154 'ipb_auto' => 0
155 ]
156 ],
157 ],
158 'conds' => $conds
159 ];
160
161 Hooks::run( 'SpecialListusersQueryInfo', [ $this, &$query ] );
162
163 return $query;
164 }
165
170 function formatRow( $row ) {
171 if ( $row->user_id == 0 ) { # T18487
172 return '';
173 }
174
175 $userName = $row->user_name;
176
177 $ulinks = Linker::userLink( $row->user_id, $userName );
179 $row->user_id,
180 $userName,
181 (int)$row->edits
182 );
183
184 $lang = $this->getLanguage();
185
186 $groups = '';
187 $ugms = self::getGroupMemberships( intval( $row->user_id ), $this->userGroupCache );
188
189 if ( !$this->including && count( $ugms ) > 0 ) {
190 $list = [];
191 foreach ( $ugms as $ugm ) {
192 $list[] = $this->buildGroupLink( $ugm, $userName );
193 }
194 $groups = $lang->commaList( $list );
195 }
196
197 $item = $lang->specialList( $ulinks, $groups );
198
199 if ( $row->ipb_deleted ) {
200 $item = "<span class=\"deleted\">$item</span>";
201 }
202
203 $edits = '';
204 if ( !$this->including && $this->getConfig()->get( 'Edititis' ) ) {
205 $count = $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped();
206 $edits = $this->msg( 'word-separator' )->escaped() . $this->msg( 'brackets', $count )->escaped();
207 }
208
209 $created = '';
210 # Some rows may be null
211 if ( !$this->including && $row->creation ) {
212 $user = $this->getUser();
213 $d = $lang->userDate( $row->creation, $user );
214 $t = $lang->userTime( $row->creation, $user );
215 $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped();
216 $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped();
217 }
218
219 $blocked = !is_null( $row->ipb_deleted ) && $row->ipb_sitewide === '1' ?
220 ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() :
221 '';
222
223 Hooks::run( 'SpecialListusersFormatRow', [ &$item, $row ] );
224
225 return Html::rawElement( 'li', [], "{$item}{$edits}{$created}{$blocked}" );
226 }
227
228 protected function doBatchLookups() {
229 $batch = new LinkBatch();
230 $userIds = [];
231 # Give some pointers to make user links
232 foreach ( $this->mResult as $row ) {
233 $batch->add( NS_USER, $row->user_name );
234 $batch->add( NS_USER_TALK, $row->user_name );
235 $userIds[] = $row->user_id;
236 }
237
238 // Lookup groups for all the users
240 $groupRes = $dbr->select(
241 'user_groups',
242 UserGroupMembership::selectFields(),
243 [ 'ug_user' => $userIds ],
244 __METHOD__
245 );
246 $cache = [];
247 $groups = [];
248 foreach ( $groupRes as $row ) {
249 $ugm = UserGroupMembership::newFromRow( $row );
250 if ( !$ugm->isExpired() ) {
251 $cache[$row->ug_user][$row->ug_group] = $ugm;
252 $groups[$row->ug_group] = true;
253 }
254 }
255
256 // Give extensions a chance to add things like global user group data
257 // into the cache array to ensure proper output later on
258 Hooks::run( 'UsersPagerDoBatchLookups', [ $dbr, $userIds, &$cache, &$groups ] );
259
260 $this->userGroupCache = $cache;
261
262 // Add page of groups to link batch
263 foreach ( $groups as $group => $unused ) {
264 $groupPage = UserGroupMembership::getGroupPage( $group );
265 if ( $groupPage ) {
266 $batch->addObj( $groupPage );
267 }
268 }
269
270 $batch->execute();
271 $this->mResult->rewind();
272 }
273
277 function getPageHeader() {
278 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() );
279
280 $groupOptions = [ $this->msg( 'group-all' )->text() => '' ];
281 foreach ( $this->getAllGroups() as $group => $groupText ) {
282 $groupOptions[ $groupText ] = $group;
283 }
284
286 'user' => [
287 'class' => HTMLUserTextField::class,
288 'label' => $this->msg( 'listusersfrom' )->text(),
289 'name' => 'username',
290 'default' => $this->requestedUser,
291 ],
292 'dropdown' => [
293 'label' => $this->msg( 'group' )->text(),
294 'name' => 'group',
295 'default' => $this->requestedGroup,
296 'class' => HTMLSelectField::class,
297 'options' => $groupOptions,
298 ],
299 'editsOnly' => [
300 'type' => 'check',
301 'label' => $this->msg( 'listusers-editsonly' )->text(),
302 'name' => 'editsOnly',
303 'id' => 'editsOnly',
304 'default' => $this->editsOnly
305 ],
306 'temporaryGroupsOnly' => [
307 'type' => 'check',
308 'label' => $this->msg( 'listusers-temporarygroupsonly' )->text(),
309 'name' => 'temporaryGroupsOnly',
310 'id' => 'temporaryGroupsOnly',
311 'default' => $this->temporaryGroupsOnly
312 ],
313 'creationSort' => [
314 'type' => 'check',
315 'label' => $this->msg( 'listusers-creationsort' )->text(),
316 'name' => 'creationSort',
317 'id' => 'creationSort',
318 'default' => $this->creationSort
319 ],
320 'desc' => [
321 'type' => 'check',
322 'label' => $this->msg( 'listusers-desc' )->text(),
323 'name' => 'desc',
324 'id' => 'desc',
325 'default' => $this->mDefaultDirection
326 ],
327 'limithiddenfield' => [
328 'class' => HTMLHiddenField::class,
329 'name' => 'limit',
330 'default' => $this->mLimit
331 ]
332 ];
333
334 $beforeSubmitButtonHookOut = '';
335 Hooks::run( 'SpecialListusersHeaderForm', [ $this, &$beforeSubmitButtonHookOut ] );
336
337 if ( $beforeSubmitButtonHookOut !== '' ) {
338 $formDescriptor[ 'beforeSubmitButtonHookOut' ] = [
339 'class' => HTMLInfoField::class,
340 'raw' => true,
341 'default' => $beforeSubmitButtonHookOut
342 ];
343 }
344
345 $formDescriptor[ 'submit' ] = [
346 'class' => HTMLSubmitField::class,
347 'buttonlabel-message' => 'listusers-submit',
348 ];
349
350 $beforeClosingFieldsetHookOut = '';
351 Hooks::run( 'SpecialListusersHeader', [ $this, &$beforeClosingFieldsetHookOut ] );
352
353 if ( $beforeClosingFieldsetHookOut !== '' ) {
354 $formDescriptor[ 'beforeClosingFieldsetHookOut' ] = [
355 'class' => HTMLInfoField::class,
356 'raw' => true,
358 ];
359 }
360
361 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
362 $htmlForm
363 ->setMethod( 'get' )
364 ->setAction( Title::newFromText( $self )->getLocalURL() )
365 ->setId( 'mw-listusers-form' )
366 ->setFormIdentifier( 'mw-listusers-form' )
367 ->suppressDefaultSubmit()
368 ->setWrapperLegendMsg( 'listusers' );
369 return $htmlForm->prepareForm()->getHTML( true );
370 }
371
376 function getAllGroups() {
377 $result = [];
378 foreach ( User::getAllGroups() as $group ) {
379 $result[$group] = UserGroupMembership::getGroupName( $group );
380 }
381 asort( $result );
382
383 return $result;
384 }
385
390 function getDefaultQuery() {
391 $query = parent::getDefaultQuery();
392 if ( $this->requestedGroup != '' ) {
393 $query['group'] = $this->requestedGroup;
394 }
395 if ( $this->requestedUser != '' ) {
396 $query['username'] = $this->requestedUser;
397 }
398 Hooks::run( 'SpecialListusersDefaultQuery', [ $this, &$query ] );
399
400 return $query;
401 }
402
411 protected static function getGroupMemberships( $uid, $cache = null ) {
412 if ( $cache === null ) {
413 $user = User::newFromId( $uid );
414 return $user->getGroupMemberships();
415 } else {
416 return $cache[$uid] ?? [];
417 }
418 }
419
427 protected function buildGroupLink( $group, $username ) {
428 return UserGroupMembership::getLink( $group, $this->getContext(), 'html', $username );
429 }
430}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
IndexPager with an alphabetic list and a formatted navigation bar.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
IContextSource $context
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
int $mLimit
The maximum number of entries to show.
bool $mDefaultDirection
$mDefaultDirection gives the direction to use when sorting results: DIR_ASCENDING or DIR_DESCENDING.
const DIR_ASCENDING
Backwards-compatible constant for $mDefaultDirection field (do not change)
const DIR_DESCENDING
Backwards-compatible constant for $mDefaultDirection field (do not change)
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:892
static userToolLinksRedContribs( $userId, $userText, $edits=null, $useParentheses=true)
Alias for userToolLinks( $userId, $userText, true );.
Definition Linker.php:1004
static getAllGroups()
Return the set of defined explicit groups.
Definition User.php:5131
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:609
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition User.php:905
This class is used to get a list of user.
getAllGroups()
Get a list of all explicit groups.
__construct(IContextSource $context=null, $par=null, $including=null)
array[] $userGroupCache
A array with user ids as key and a array of groups as value.
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...
formatRow( $row)
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
getDefaultQuery()
Preserve group and username offset parameters when paging.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
namespace being checked & $result
Definition hooks.txt:2340
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 $request
Definition hooks.txt:2843
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead & $formDescriptor
Definition hooks.txt:2157
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1999
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition hooks.txt:783
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:782
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1617
const NS_USER_TALK
Definition Defines.php:76
Interface for objects which can provide a MediaWiki context on request.
$batch
Definition linkcache.txt:23
$cache
Definition mcc.php:33
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))
const DB_REPLICA
Definition defines.php:25
if(!isset( $args[0])) $lang