3 * Implements Special:Listusers
5 * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
6 * Domas Mituzas, Ashar Voultoiz, 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
{
37 function __construct( $par=null ) {
39 $parms = explode( '/', ($par = ( $par !== null ) ?
$par : '' ) );
40 $symsForAll = array( '*', 'user' );
41 if ( $parms[0] != '' && ( in_array( $par, User
::getAllGroups() ) ||
in_array( $par, $symsForAll ) ) ) {
42 $this->requestedGroup
= $par;
43 $un = $wgRequest->getText( 'username' );
44 } elseif ( count( $parms ) == 2 ) {
45 $this->requestedGroup
= $parms[0];
48 $this->requestedGroup
= $wgRequest->getVal( 'group' );
49 $un = ( $par != '' ) ?
$par : $wgRequest->getText( 'username' );
51 if ( in_array( $this->requestedGroup
, $symsForAll ) ) {
52 $this->requestedGroup
= '';
54 $this->editsOnly
= $wgRequest->getBool( 'editsOnly' );
55 $this->creationSort
= $wgRequest->getBool( 'creationSort' );
57 $this->requestedUser
= '';
59 $username = Title
::makeTitleSafe( NS_USER
, $un );
60 if( ! is_null( $username ) ) {
61 $this->requestedUser
= $username->getText();
64 parent
::__construct();
68 return SpecialPage
::getTitleFor( 'Listusers' );
71 function getIndexField() {
72 return $this->creationSort ?
'user_id' : 'user_name';
75 function getQueryInfo() {
77 $dbr = wfGetDB( DB_SLAVE
);
79 // Don't show hidden names
80 if( !$wgUser->isAllowed('hideuser') ) {
81 $conds[] = 'ipb_deleted IS NULL';
86 if( $this->requestedGroup
!= '' ) {
87 $conds['ug_group'] = $this->requestedGroup
;
89 //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name';
91 if( $this->requestedUser
!= '' ) {
92 # Sorted either by account creation or name
93 if( $this->creationSort
) {
94 $conds[] = 'user_id >= ' . intval( User
::idFromName( $this->requestedUser
) );
96 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser
);
99 if( $this->editsOnly
) {
100 $conds[] = 'user_editcount > 0';
103 $options['GROUP BY'] = $this->creationSort ?
'user_id' : 'user_name';
106 'tables' => array( 'user', 'user_groups', 'ipblocks'),
108 $this->creationSort ?
'MAX(user_name) AS user_name' : 'user_name',
109 $this->creationSort ?
'user_id' : 'MAX(user_id) AS user_id',
110 'MAX(user_editcount) AS edits',
111 'COUNT(ug_group) AS numgroups',
112 'MAX(ug_group) AS singlegroup', // the usergroup if there is only one
113 'MIN(user_registration) AS creation',
114 'MAX(ipb_deleted) AS ipb_deleted' // block/hide status
116 'options' => $options,
117 'join_conds' => array(
118 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ),
119 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0' ),
124 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
128 function formatRow( $row ) {
131 if ($row->user_id
== 0) #Bug 16487
134 $userPage = Title
::makeTitle( NS_USER
, $row->user_name
);
135 $name = Linker
::link( $userPage, htmlspecialchars( $userPage->getText() ) );
137 $groups_list = self
::getGroups( $row->user_id
);
138 if( count( $groups_list ) > 0 ) {
140 foreach( $groups_list as $group )
141 $list[] = self
::buildGroupLink( $group );
142 $groups = $wgLang->commaList( $list );
147 $item = wfSpecialList( $name, $groups );
148 if( $row->ipb_deleted
) {
149 $item = "<span class=\"deleted\">$item</span>";
154 $editCount = $wgLang->formatNum( $row->edits
);
155 $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
161 # Some rows may be NULL
162 if( $row->creation
) {
163 $d = $wgLang->date( wfTimestamp( TS_MW
, $row->creation
), true );
164 $t = $wgLang->time( wfTimestamp( TS_MW
, $row->creation
), true );
165 $created = ' (' . wfMsg( 'usercreated', $d, $t ) . ')';
166 $created = htmlspecialchars( $created );
169 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
170 return "<li>{$item}{$edits}{$created}</li>";
174 if( !$this->mQueryDone
) {
177 $this->mResult
->rewind();
178 $batch = new LinkBatch
;
179 foreach ( $this->mResult
as $row ) {
180 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
183 $this->mResult
->rewind();
184 return parent
::getBody();
187 function getPageHeader( ) {
189 $self = $this->getTitle();
192 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
193 Xml
::fieldset( wfMsg( 'listusers' ) ) .
194 Html
::hidden( 'title', $self->getPrefixedDbKey() );
197 $out .= Xml
::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
198 Xml
::input( 'username', 20, $this->requestedUser
, array( 'id' => 'offset' ) ) . ' ';
200 # Group drop-down list
201 $out .= Xml
::label( wfMsg( 'group' ), 'group' ) . ' ' .
202 Xml
::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
203 Xml
::option( wfMsg( 'group-all' ), '' );
204 foreach( $this->getAllGroups() as $group => $groupText )
205 $out .= Xml
::option( $groupText, $group, $group == $this->requestedGroup
);
206 $out .= Xml
::closeElement( 'select' ) . '<br />';
207 $out .= Xml
::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly
);
209 $out .= Xml
::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort
);
212 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
214 # Submit button and form bottom
215 $out .= Html
::hidden( 'limit', $this->mLimit
);
216 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
217 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
218 $out .= Xml
::closeElement( 'fieldset' ) .
219 Xml
::closeElement( 'form' );
225 * Get a list of all explicit groups
228 function getAllGroups() {
230 foreach( User
::getAllGroups() as $group ) {
231 $result[$group] = User
::getGroupName( $group );
238 * Preserve group and username offset parameters when paging
241 function getDefaultQuery() {
242 $query = parent
::getDefaultQuery();
243 if( $this->requestedGroup
!= '' )
244 $query['group'] = $this->requestedGroup
;
245 if( $this->requestedUser
!= '' )
246 $query['username'] = $this->requestedUser
;
247 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
252 * Get a list of groups the specified user belongs to
254 * @param $uid Integer: user id
257 protected static function getGroups( $uid ) {
258 $user = User
::newFromId( $uid );
259 $groups = array_diff( $user->getEffectiveGroups(), User
::getImplicitGroups() );
264 * Format a link to a group description page
266 * @param $group String: group name
269 protected static function buildGroupLink( $group ) {
270 static $cache = array();
271 if( !isset( $cache[$group] ) )
272 $cache[$group] = User
::makeGroupLinkHtml( $group, htmlspecialchars( User
::getGroupMember( $group ) ) );
273 return $cache[$group];
278 * @ingroup SpecialPage
280 class SpecialListUsers
extends SpecialPage
{
285 public function __construct() {
286 parent
::__construct( 'Listusers' );
290 * Show the special page
292 * @param $par string (optional) A group to list users from
294 public function execute( $par ) {
298 $this->outputHeader();
300 $up = new UsersPager( $par );
302 # getBody() first to check, if empty
303 $usersbody = $up->getBody();
305 $s = $up->getPageHeader();
307 $s .= $up->getNavigationBar();
308 $s .= Html
::rawElement( 'ul', array(), $usersbody );
309 $s .= $up->getNavigationBar();
311 $s .= wfMessage( 'listusers-noresult' )->parseAsBlock();
314 $wgOut->addHTML( $s );