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 * @addtogroup 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 * @addtogroup SpecialPage
37 class UsersPager
extends AlphabeticPager
{
39 function __construct($group=null) {
41 $this->requestedGroup
= $group != "" ?
$group : $wgRequest->getVal( 'group' );
42 $un = $wgRequest->getText( 'username' );
43 $this->requestedUser
= '';
45 $username = Title
::makeTitleSafe( NS_USER
, $un );
46 if( ! is_null( $username ) ) {
47 $this->requestedUser
= $username->getText();
50 parent
::__construct();
54 function getIndexField() {
58 function getQueryInfo() {
60 // don't show hidden names
61 $conds[]='ipb_deleted IS NULL OR ipb_deleted = 0';
62 if ($this->requestedGroup
!= "") {
63 $conds['ug_group'] = $this->requestedGroup
;
65 if ($this->requestedUser
!= "") {
66 $conds[] = 'user_name >= ' . wfGetDB()->addQuotes( $this->requestedUser
);
69 list ($user,$user_groups,$ipblocks) = wfGetDB()->tableNamesN('user','user_groups','ipblocks');
72 'tables' => " $user LEFT JOIN $user_groups ON user_id=ug_user LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
73 'fields' => array('user_name',
74 'MAX(user_id) AS user_id',
75 'COUNT(ug_group) AS numgroups',
76 'MAX(ug_group) AS singlegroup'),
77 'options' => array('GROUP BY' => 'user_name'),
83 function formatRow( $row ) {
84 $userPage = Title
::makeTitle( NS_USER
, $row->user_name
);
85 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
87 if( $row->numgroups
> 1 ||
( $this->requestedGroup
&& $row->numgroups
== 1 ) ) {
89 foreach( self
::getGroups( $row->user_id
) as $group )
90 $list[] = self
::buildGroupLink( $group );
91 $groups = implode( ', ', $list );
92 } elseif( $row->numgroups
== 1 ) {
93 $groups = self
::buildGroupLink( $row->singlegroup
);
98 return '<li>' . wfSpecialList( $name, $groups ) . '</li>';
102 if (!$this->mQueryDone
) {
105 $batch = new LinkBatch
;
107 $this->mResult
->rewind();
109 while ( $row = $this->mResult
->fetchObject() ) {
110 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
113 $this->mResult
->rewind();
114 return parent
::getBody();
117 function getPageHeader( ) {
118 global $wgScript, $wgRequest;
119 $self = $this->getTitle();
122 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
124 Xml
::element( 'legend', array(), wfMsg( 'listusers' ) );
125 $out .= Xml
::hidden( 'title', $self->getPrefixedDbKey() );
128 $out .= Xml
::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
129 Xml
::input( 'username', 20, $this->requestedUser
, array( 'id' => 'offset' ) ) . ' ';
131 # Group drop-down list
132 $out .= Xml
::label( wfMsg( 'group' ), 'group' ) . ' ' .
133 Xml
::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
134 Xml
::option( wfMsg( 'group-all' ), '' );
135 foreach( User
::getAllGroups() as $group )
136 $out .= Xml
::option( User
::getGroupName( $group ), $group, $group == $this->requestedGroup
);
137 $out .= Xml
::closeElement( 'select' ) . ' ';
139 # Submit button and form bottom
141 $out .= Xml
::hidden( 'limit', $this->mLimit
);
142 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
144 Xml
::closeElement( 'form' );
150 * Preserve group and username offset parameters when paging
153 function getDefaultQuery() {
154 $query = parent
::getDefaultQuery();
155 if( $this->requestedGroup
!= '' )
156 $query['group'] = $this->requestedGroup
;
157 if( $this->requestedUser
!= '' )
158 $query['username'] = $this->requestedUser
;
163 * Get a list of groups the specified user belongs to
168 private static function getGroups( $uid ) {
169 $dbr = wfGetDB( DB_SLAVE
);
171 $res = $dbr->select( 'user_groups', 'ug_group', array( 'ug_user' => $uid ), __METHOD__
);
172 if( $res && $dbr->numRows( $res ) > 0 ) {
173 while( $row = $dbr->fetchObject( $res ) )
174 $groups[] = $row->ug_group
;
175 $dbr->freeResult( $res );
181 * Format a link to a group description page
183 * @param string $group
186 private static function buildGroupLink( $group ) {
187 static $cache = array();
188 if( !isset( $cache[$group] ) )
189 $cache[$group] = User
::makeGroupLinkHtml( $group, User
::getGroupMember( $group ) );
190 return $cache[$group];
196 * $par string (optional) A group to list users from
198 function wfSpecialListusers( $par = null ) {
199 global $wgRequest, $wgOut;
201 $up = new UsersPager($par);
203 # getBody() first to check, if empty
204 $usersbody = $up->getBody();
205 $s = $up->getPageHeader();
207 $s .= $up->getNavigationBar();
208 $s .= '<ul>' . $usersbody . '</ul>';
209 $s .= $up->getNavigationBar() ;
211 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
214 $wgOut->addHTML( $s );