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 $this->requestedUser
= $wgRequest->getText( 'username', $this->mOffset
);
44 parent
::__construct();
48 function getIndexField() {
52 function getQueryInfo() {
54 if ($this->requestedGroup
!= "") {
55 $conds['ug_group'] = $this->requestedGroup
;
57 if ($this->requestedUser
!= "") {
58 $conds[] = 'user_name >= ' . wfGetDB()->addQuotes( $this->requestedUser
);
61 list ($user,$user_groups) = wfGetDB()->tableNamesN('user','user_groups');
64 'tables' => " $user LEFT JOIN $user_groups ON user_id=ug_user ",
65 'fields' => array('user_name',
66 'MAX(user_id) AS user_id',
67 'COUNT(ug_group) AS numgroups',
68 'MAX(ug_group) AS singlegroup'),
69 'options' => array('GROUP BY' => 'user_name'),
74 function formatRow($row) {
75 $userPage = Title
::makeTitle(NS_USER
, $row->user_name
);
76 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
78 if ($row->numgroups
> 1 ||
( $this->requestedGroup
and $row->numgroups
== 1) ) {
79 $dbr = wfGetDB(DB_SLAVE
);
80 $result = $dbr->select( 'user_groups', 'ug_group',
81 array( 'ug_user' => $row->user_id
),
82 'UsersPager::formatRow' );
83 while ( $group = $dbr->fetchObject($result)) {
84 $groups[$group->ug_group
] = User
::getGroupMember ( $group->ug_group
);
86 $dbr->freeResult($result);
87 } elseif ($row->numgroups
== 1 ) { // MAX hack inside query :)
88 $groups[$row->singlegroup
] = User
::getGroupMember( $row->singlegroup
);
91 if ( count($groups) > 0 ) {
92 foreach( $groups as $group => $desc ) {
93 $list[] = User
::makeGroupLinkHTML( $group, $desc);
95 $groups = implode( ', ', $list);
99 return '<li>' . wfSpecialList ($name, $groups) .'</li>';
103 if (!$this->mQueryDone
) {
106 $batch = new LinkBatch
;
109 $this->mResult
->rewind();
111 while ( $row = $this->mResult
->fetchObject() ) {
112 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_name
) );
115 $this->mResult
->rewind();
116 return parent
::getBody();
119 function getPageHeader( ) {
120 $self = $this->getTitle();
123 $out = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
125 # Group drop-down list
126 $out .= wfElement( 'label', array( 'for' => 'group' ), wfMsg( 'group' ) ) . ' ';
127 $out .= wfOpenElement( 'select', array( 'name' => 'group', 'id' => 'group' ) );
128 $out .= wfElement( 'option', array( 'value' => '' ), wfMsg( 'group-all' ) ); # Item for "all groups"
129 $groups = User
::getAllGroups();
130 foreach( $groups as $group ) {
131 $attribs = array( 'value' => $group );
132 if( $group == $this->requestedGroup
)
133 $attribs['selected'] = 'selected';
134 $out .= wfElement( 'option', $attribs, User
::getGroupName( $group ) );
136 $out .= wfCloseElement( 'select' ) . ' ';;# . wfElement( 'br' );
139 $out .= wfElement( 'label', array( 'for' => 'offset' ), wfMsg( 'listusersfrom' ) ) . ' ';
140 $out .= wfElement( 'input', array( 'type' => 'text', 'id' => 'username', 'name' => 'username',
141 'value' => $this->requestedUser
) ) . ' ';
144 $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'limit', 'value' => $this->mLimit
) );
146 # Submit button and form bottom
147 $out .= wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'allpagessubmit' ) ) );
148 $out .= wfCloseElement( 'form' );
154 * Preserve group and username offset parameters when paging
157 function getDefaultQuery() {
158 $query = parent
::getDefaultQuery();
159 if( $this->requestedGroup
!= '' )
160 $query['group'] = $this->requestedGroup
;
161 if( $this->requestedUser
!= '' )
162 $query['username'] = $this->requestedUser
;
169 * $par string (optional) A group to list users from
171 function wfSpecialListusers( $par = null ) {
172 global $wgRequest, $wgOut;
174 list( $limit, $offset ) = wfCheckLimits();
176 $groupTarget = isset($par) ?
$par : $wgRequest->getVal( 'group' );
178 $up = new UsersPager($par);
180 # getBody() first to check, if empty
181 $usersbody = $up->getBody();
182 $s = $up->getPageHeader();
184 $s .= $up->getNavigationBar();
185 $s .= '<ul>' . $usersbody . '</ul>';
186 $s .= $up->getNavigationBar() ;
188 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
190 $wgOut->addHTML( $s );