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 SpecialListUsers
extends QueryPage
{
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 } else if ( 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();
65 $this->limit
= $wgRequest->getVal( 'limit' );
66 $this->offset
= $wgRequest->getVal( 'offset' );
68 parent
::__construct( 'Listusers' );
71 function isExpensive() { return false; }
72 function isCacheable() { return false; }
73 function isSyndicated() { return false; }
74 function sortDescending() { return false; }
76 function openList( $offset ) {
77 return "\n<ul class='special'>\n";
80 function closeList() {
84 function linkParameters() {
86 'group' => $this->requestedGroup
,
87 'editsOnly' => $this->editsOnly
,
88 'creationSort' => $this->creationSort
,
89 'requestedUser' => $this->requestedUser
,
93 function getQueryInfo() {
96 $dbr = wfGetDB( DB_SLAVE
);
97 $conds = $jconds = array();
98 $tables = array( 'user' );
100 // Don't show hidden names
101 if( !$wgUser->isAllowed('hideuser') ) {
102 $tables[] = 'ipblocks';
103 $conds[] = 'ipb_deleted IS NULL';
104 $jconds['ipblocks'] = array( 'LEFT JOIN', array(
105 # Unique index on (ipb_address,ipb_user,ipb_auto)
106 'ipb_address = user_name',
107 'ipb_user = user_id',
113 if( $this->requestedGroup
!= '' ) {
114 $tables[] = 'user_groups';
115 $conds['ug_group'] = $this->requestedGroup
;
116 # Unique index on (ug_user,ug_group)
117 $jconds['user_groups'] = array( 'LEFT JOIN', 'user_id = ug_user' );
120 if( $this->requestedUser
!= '' ) {
121 # Sorted either by account creation or name
122 if( $this->creationSort
) {
123 $conds[] = 'user_id >= ' . intval( User
::idFromName( $this->requestedUser
) );
125 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser
);
129 if( $this->editsOnly
) {
130 $conds[] = 'user_editcount > 0';
136 'join_conds' => $jconds,
140 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
144 function formatResult( $skin, $row ) {
147 if ( $row->user_id
== 0 ){
152 $user = User
::newFromId( $row->user_id
);
154 $user->getUserpage(),
158 $groups_list = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() );
159 if( count( $groups_list ) > 0 ) {
161 foreach( $groups_list as $group )
162 $list[] = self
::buildGroupLink( $group );
163 $groups = $wgLang->commaList( $list );
168 $item = wfSpecialList( $name, $groups );
169 if( isset( $row->ipb_deleted
) ) {
170 $item = "<span class=\"deleted\">$item</span>";
175 $editCount = $wgLang->formatNum( $row->edits
);
176 $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
182 # Some rows may be NULL
183 if( $row->user_registration
) {
184 $d = $wgLang->date( wfTimestamp( TS_MW
, $row->user_registration
), true );
185 $t = $wgLang->time( wfTimestamp( TS_MW
, $row->user_registration
), true );
186 $created = ' (' . wfMessage( 'usercreated', $d, $t ) . ')';
189 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
190 return "{$item}{$edits}{$created}";
193 function getOrderFields() {
194 return $this->creationSort ?
array( 'user_id' ) : array( 'user_name' );
198 * Cache page existence for performance
200 function preprocessResults( $db, $res ) {
201 $batch = new LinkBatch
;
202 foreach ( $res as $row ) {
203 $batch->add( NS_USER
, $row->user_name
);
204 $batch->add( NS_USER_TALK
, $row->user_name
);
208 // Back to start for display
209 if ( $db->numRows( $res ) > 0 ) {
210 // If there are no rows we get an error seeking.
211 $db->dataSeek( $res, 0 );
215 function getPageHeader( ) {
217 $self = $this->getTitle();
220 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
221 Xml
::fieldset( wfMsg( 'listusers' ) ) .
222 Html
::hidden( 'title', $self->getPrefixedDbKey() );
225 $out .= Xml
::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
226 Xml
::input( 'username', 20, $this->requestedUser
, array( 'id' => 'offset' ) ) . ' ';
228 # Group drop-down list
229 $out .= Xml
::label( wfMsg( 'group' ), 'group' ) . ' ' .
230 Xml
::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
231 Xml
::option( wfMsg( 'group-all' ), '' );
233 $groups = array_unique( array_diff( User
::getAllGroups(), array( '*', 'user' ) ) );
234 foreach( $groups as $group ){
236 User
::getGroupName( $group ),
238 $group == $this->requestedGroup
242 $out .= Xml
::closeElement( 'select' ) . '<br />';
243 $out .= Xml
::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly
);
245 $out .= Xml
::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort
);
248 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
250 # Submit button and form bottom
251 $out .= Html
::hidden( 'limit', $this->limit
);
252 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
253 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
254 $out .= Xml
::closeElement( 'fieldset' ) .
255 Xml
::closeElement( 'form' );
261 * Format a link to a group description page
263 * @param $group String: group name
266 protected static function buildGroupLink( $group ) {
267 static $cache = array();
268 if( !isset( $cache[$group] ) )
269 $cache[$group] = User
::makeGroupLinkHtml( $group, htmlspecialchars( User
::getGroupMember( $group ) ) );
270 return $cache[$group];