3 # Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
4 # Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
6 # © 2006 Rob Church <robchur@gmail.com>
8 # http://www.mediawiki.org/
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 # http://www.gnu.org/copyleft/gpl.html
26 * @ingroup SpecialPage
30 * This class is used to get a list of user. The ones with specials
31 * rights (sysop, bureaucrat, developer) will have them displayed
32 * next to their names.
34 * @ingroup SpecialPage
36 class UsersPager
extends AlphabeticPager
{
38 function __construct( $par=null ) {
40 $parms = explode( '/', ($par = ( $par !== null ) ?
$par : '' ) );
41 $symsForAll = array( '*', 'user' );
42 if ( $parms[0] != '' && ( in_array( $par, User
::getAllGroups() ) ||
in_array( $par, $symsForAll ) ) ) {
43 $this->requestedGroup
= $par;
44 $un = $wgRequest->getText( 'username' );
45 } else if ( count( $parms ) == 2 ) {
46 $this->requestedGroup
= $parms[0];
49 $this->requestedGroup
= $wgRequest->getVal( 'group' );
50 $un = ( $par != '' ) ?
$par : $wgRequest->getText( 'username' );
52 if ( in_array( $this->requestedGroup
, $symsForAll ) ) {
53 $this->requestedGroup
= '';
55 $this->editsOnly
= $wgRequest->getBool( 'editsOnly' );
57 $this->requestedUser
= '';
59 $username = Title
::makeTitleSafe( NS_USER
, $un );
60 if( ! is_null( $username ) ) {
61 $this->requestedUser
= $username->getText();
64 parent
::__construct();
68 function getIndexField() {
72 function getQueryInfo() {
73 $dbr = wfGetDB( DB_SLAVE
);
75 // Don't show hidden names
76 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
77 if ($this->requestedGroup
!= "") {
78 $conds['ug_group'] = $this->requestedGroup
;
81 $useIndex = $dbr->useIndexClause('user_name');
83 if ($this->requestedUser
!= "") {
84 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser
);
86 if( $this->editsOnly
) {
87 $conds[] = 'user_editcount > 0';
90 list ($user,$user_groups,$ipblocks) = $dbr->tableNamesN('user','user_groups','ipblocks');
93 'tables' => " $user $useIndex LEFT JOIN $user_groups ON user_id=ug_user
94 LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
95 'fields' => array('user_name',
96 'MAX(user_id) AS user_id',
97 'COUNT(ug_group) AS numgroups',
98 'MAX(ug_group) AS singlegroup'),
99 'options' => array('GROUP BY' => 'user_name'),
103 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
107 function formatRow( $row ) {
108 $userPage = Title
::makeTitle( NS_USER
, $row->user_name
);
109 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
111 if( $row->numgroups
> 1 ||
( $this->requestedGroup
&& $row->numgroups
== 1 ) ) {
113 foreach( self
::getGroups( $row->user_id
) as $group )
114 $list[] = self
::buildGroupLink( $group );
115 $groups = implode( ', ', $list );
116 } elseif( $row->numgroups
== 1 ) {
117 $groups = self
::buildGroupLink( $row->singlegroup
);
122 $item = wfSpecialList( $name, $groups );
123 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
124 return "<li>{$item}</li>";
128 if( !$this->mQueryDone
) {
131 $this->mResult
->rewind();
132 $batch = new LinkBatch
;
133 while ( $row = $this->mResult
->fetchObject() ) {
134 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
137 $this->mResult
->rewind();
138 return parent
::getBody();
141 function getPageHeader( ) {
142 global $wgScript, $wgRequest;
143 $self = $this->getTitle();
146 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
148 Xml
::element( 'legend', array(), wfMsg( 'listusers' ) );
149 $out .= Xml
::hidden( 'title', $self->getPrefixedDbKey() );
152 $out .= Xml
::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
153 Xml
::input( 'username', 20, $this->requestedUser
, array( 'id' => 'offset' ) ) . ' ';
155 # Group drop-down list
156 $out .= Xml
::label( wfMsg( 'group' ), 'group' ) . ' ' .
157 Xml
::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
158 Xml
::option( wfMsg( 'group-all' ), '' );
159 foreach( $this->getAllGroups() as $group => $groupText )
160 $out .= Xml
::option( $groupText, $group, $group == $this->requestedGroup
);
161 $out .= Xml
::closeElement( 'select' ) . '<br/>';
162 $out .= Xml
::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly
);
165 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
167 # Submit button and form bottom
169 $out .= Xml
::hidden( 'limit', $this->mLimit
);
170 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
171 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
172 $out .= '</fieldset>' .
173 Xml
::closeElement( 'form' );
178 function getAllGroups() {
180 foreach( User
::getAllGroups() as $group ) {
181 $result[$group] = User
::getGroupName( $group );
187 * Preserve group and username offset parameters when paging
190 function getDefaultQuery() {
191 $query = parent
::getDefaultQuery();
192 if( $this->requestedGroup
!= '' )
193 $query['group'] = $this->requestedGroup
;
194 if( $this->requestedUser
!= '' )
195 $query['username'] = $this->requestedUser
;
196 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
201 * Get a list of groups the specified user belongs to
206 protected static function getGroups( $uid ) {
207 $dbr = wfGetDB( DB_SLAVE
);
209 $res = $dbr->select( 'user_groups', 'ug_group', array( 'ug_user' => $uid ), __METHOD__
);
210 if( $res && $dbr->numRows( $res ) > 0 ) {
211 while( $row = $dbr->fetchObject( $res ) )
212 $groups[] = $row->ug_group
;
213 $dbr->freeResult( $res );
219 * Format a link to a group description page
221 * @param string $group
224 protected static function buildGroupLink( $group ) {
225 static $cache = array();
226 if( !isset( $cache[$group] ) )
227 $cache[$group] = User
::makeGroupLinkHtml( $group, User
::getGroupMember( $group ) );
228 return $cache[$group];
234 * $par string (optional) A group to list users from
236 function wfSpecialListusers( $par = null ) {
237 global $wgRequest, $wgOut;
239 $up = new UsersPager($par);
241 # getBody() first to check, if empty
242 $usersbody = $up->getBody();
243 $s = XML
::openElement( 'div', array('class' => 'mw-spcontent') );
244 $s .= $up->getPageHeader();
246 $s .= $up->getNavigationBar();
247 $s .= '<ul>' . $usersbody . '</ul>';
248 $s .= $up->getNavigationBar() ;
250 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
252 $s .= XML
::closeElement( 'div' );
253 $wgOut->addHTML( $s );