3 * Implements Special:Listusers
5 * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
6 * Domas Mituzas, Antoine Musso, Jens Frank, Zhengzhu,
7 * 2006 Rob Church <robchur@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 * @ingroup SpecialPage
29 * This class is used to get a list of user. The ones with specials
30 * rights (sysop, bureaucrat, developer) will have them displayed
31 * next to their names.
33 * @ingroup SpecialPage
35 class UsersPager
extends AlphabeticPager
{
38 * @param $context IContextSource
39 * @param array $par (Default null)
40 * @param $including boolean Whether this page is being transcluded in
43 function __construct( IContextSource
$context = null, $par = null, $including = null ) {
45 $this->setContext( $context );
48 $request = $this->getRequest();
49 $par = ( $par !== null ) ?
$par : '';
50 $parms = explode( '/', $par );
51 $symsForAll = array( '*', 'user' );
53 if ( $parms[0] != '' &&
54 ( in_array( $par, User
::getAllGroups() ) ||
in_array( $par, $symsForAll ) )
56 $this->requestedGroup
= $par;
57 $un = $request->getText( 'username' );
58 } elseif ( count( $parms ) == 2 ) {
59 $this->requestedGroup
= $parms[0];
62 $this->requestedGroup
= $request->getVal( 'group' );
63 $un = ( $par != '' ) ?
$par : $request->getText( 'username' );
66 if ( in_array( $this->requestedGroup
, $symsForAll ) ) {
67 $this->requestedGroup
= '';
69 $this->editsOnly
= $request->getBool( 'editsOnly' );
70 $this->creationSort
= $request->getBool( 'creationSort' );
71 $this->including
= $including;
73 $this->requestedUser
= '';
76 $username = Title
::makeTitleSafe( NS_USER
, $un );
78 if ( !is_null( $username ) ) {
79 $this->requestedUser
= $username->getText();
83 parent
::__construct();
89 function getIndexField() {
90 return $this->creationSort ?
'user_id' : 'user_name';
96 function getQueryInfo() {
97 $dbr = wfGetDB( DB_SLAVE
);
100 // Don't show hidden names
101 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
102 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
107 if ( $this->requestedGroup
!= '' ) {
108 $conds['ug_group'] = $this->requestedGroup
;
111 if ( $this->requestedUser
!= '' ) {
112 # Sorted either by account creation or name
113 if ( $this->creationSort
) {
114 $conds[] = 'user_id >= ' . intval( User
::idFromName( $this->requestedUser
) );
116 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser
);
120 if ( $this->editsOnly
) {
121 $conds[] = 'user_editcount > 0';
124 $options['GROUP BY'] = $this->creationSort ?
'user_id' : 'user_name';
127 'tables' => array( 'user', 'user_groups', 'ipblocks' ),
129 'user_name' => $this->creationSort ?
'MAX(user_name)' : 'user_name',
130 'user_id' => $this->creationSort ?
'user_id' : 'MAX(user_id)',
131 'edits' => 'MAX(user_editcount)',
132 'numgroups' => 'COUNT(ug_group)',
133 'singlegroup' => 'MAX(ug_group)', // the usergroup if there is only one
134 'creation' => 'MIN(user_registration)',
135 'ipb_deleted' => 'MAX(ipb_deleted)' // block/hide status
137 'options' => $options,
138 'join_conds' => array(
139 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ),
150 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
159 function formatRow( $row ) {
160 if ( $row->user_id
== 0 ) { #Bug 16487
164 $userName = $row->user_name
;
166 $ulinks = Linker
::userLink( $row->user_id
, $userName );
167 $ulinks .= Linker
::userToolLinksRedContribs(
173 $lang = $this->getLanguage();
176 $groups_list = self
::getGroups( $row->user_id
);
178 if ( !$this->including
&& count( $groups_list ) > 0 ) {
180 foreach ( $groups_list as $group ) {
181 $list[] = self
::buildGroupLink( $group, $userName );
183 $groups = $lang->commaList( $list );
186 $item = $lang->specialList( $ulinks, $groups );
188 if ( $row->ipb_deleted
) {
189 $item = "<span class=\"deleted\">$item</span>";
194 if ( !$this->including
&& $wgEdititis ) {
195 // @fixme i18n issue: Hardcoded square brackets.
197 $this->msg( 'usereditcount' )->numParams( $row->edits
)->escaped() .
202 # Some rows may be null
203 if ( !$this->including
&& $row->creation
) {
204 $user = $this->getUser();
205 $d = $lang->userDate( $row->creation
, $user );
206 $t = $lang->userTime( $row->creation
, $user );
207 $created = $this->msg( 'usercreated', $d, $t, $row->user_name
)->escaped();
208 $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped();
210 $blocked = !is_null( $row->ipb_deleted
) ?
211 ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() :
214 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
216 return Html
::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" );
219 function doBatchLookups() {
220 $batch = new LinkBatch();
221 # Give some pointers to make user links
222 foreach ( $this->mResult
as $row ) {
223 $batch->add( NS_USER
, $row->user_name
);
224 $batch->add( NS_USER_TALK
, $row->user_name
);
227 $this->mResult
->rewind();
233 function getPageHeader() {
236 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() );
239 $out = Xml
::openElement(
241 array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' )
243 Xml
::fieldset( $this->msg( 'listusers' )->text() ) .
244 Html
::hidden( 'title', $self );
247 $out .= Xml
::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' .
250 $this->requestedUser
,
255 'autofocus' => $this->requestedUser
=== ''
259 # Group drop-down list
260 $out .= Xml
::label( $this->msg( 'group' )->text(), 'group' ) . ' ' .
261 Xml
::openElement( 'select', array( 'name' => 'group', 'id' => 'group' ) ) .
262 Xml
::option( $this->msg( 'group-all' )->text(), '' );
263 foreach ( $this->getAllGroups() as $group => $groupText ) {
264 $out .= Xml
::option( $groupText, $group, $group == $this->requestedGroup
);
266 $out .= Xml
::closeElement( 'select' ) . '<br />';
267 $out .= Xml
::checkLabel(
268 $this->msg( 'listusers-editsonly' )->text(),
274 $out .= Xml
::checkLabel(
275 $this->msg( 'listusers-creationsort' )->text(),
282 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
284 # Submit button and form bottom
285 $out .= Html
::hidden( 'limit', $this->mLimit
);
286 $out .= Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() );
287 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
288 $out .= Xml
::closeElement( 'fieldset' ) .
289 Xml
::closeElement( 'form' );
295 * Get a list of all explicit groups
298 function getAllGroups() {
300 foreach ( User
::getAllGroups() as $group ) {
301 $result[$group] = User
::getGroupName( $group );
309 * Preserve group and username offset parameters when paging
312 function getDefaultQuery() {
313 $query = parent
::getDefaultQuery();
314 if ( $this->requestedGroup
!= '' ) {
315 $query['group'] = $this->requestedGroup
;
317 if ( $this->requestedUser
!= '' ) {
318 $query['username'] = $this->requestedUser
;
320 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
326 * Get a list of groups the specified user belongs to
328 * @param $uid Integer: user id
331 protected static function getGroups( $uid ) {
332 $user = User
::newFromId( $uid );
333 $groups = array_diff( $user->getEffectiveGroups(), User
::getImplicitGroups() );
339 * Format a link to a group description page
341 * @param string $group group name
342 * @param string $username Username
345 protected static function buildGroupLink( $group, $username ) {
346 return User
::makeGroupLinkHtml(
348 htmlspecialchars( User
::getGroupMember( $group, $username ) )
354 * @ingroup SpecialPage
356 class SpecialListUsers
extends IncludableSpecialPage
{
360 public function __construct() {
361 parent
::__construct( 'Listusers' );
365 * Show the special page
367 * @param string $par (optional) A group to list users from
369 public function execute( $par ) {
371 $this->outputHeader();
373 $up = new UsersPager( $this->getContext(), $par, $this->including() );
375 # getBody() first to check, if empty
376 $usersbody = $up->getBody();
379 if ( !$this->including() ) {
380 $s = $up->getPageHeader();
384 $s .= $up->getNavigationBar();
385 $s .= Html
::rawElement( 'ul', array(), $usersbody );
386 $s .= $up->getNavigationBar();
388 $s .= $this->msg( 'listusers-noresult' )->parseAsBlock();
391 $this->getOutput()->addHTML( $s );
394 protected function getGroupName() {