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
36 class ListUsersPage
extends QueryPage
{
37 var $requestedGroup = '';
38 var $requestedUser = '';
43 function isSyndicated() { return false; }
46 * Not expensive, this class won't work properly with the caching system anyway
48 function isExpensive() {
53 * Fetch user page links and cache their existence
55 function preprocessResults( &$db, &$res ) {
56 $batch = new LinkBatch
;
57 while ( $row = $db->fetchObject( $res ) ) {
58 $batch->addObj( Title
::makeTitleSafe( $row->namespace, $row->title
) );
62 // Back to start for display
63 if( $db->numRows( $res ) > 0 ) {
64 // If there are no rows we get an error seeking.
65 $db->dataSeek( $res, 0 );
70 * Show a drop down list to select a group as well as a user name
74 function getPageHeader( ) {
75 $self = $this->getTitle();
78 $out = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
80 # Group drop-down list
81 $out .= wfElement( 'label', array( 'for' => 'group' ), wfMsg( 'group' ) ) . ' ';
82 $out .= wfOpenElement( 'select', array( 'name' => 'group', 'id' => 'group' ) );
83 $out .= wfElement( 'option', array( 'value' => '' ), wfMsg( 'group-all' ) ); # Item for "all groups"
84 $groups = User
::getAllGroups();
85 foreach( $groups as $group ) {
86 $attribs = array( 'value' => $group );
87 if( $group == $this->requestedGroup
)
88 $attribs['selected'] = 'selected';
89 $out .= wfElement( 'option', $attribs, User
::getGroupName( $group ) );
91 $out .= wfCloseElement( 'select' ) . ' ';;# . wfElement( 'br' );
94 $out .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'listusersfrom' ) ) . ' ';
95 $out .= wfElement( 'input', array( 'type' => 'text', 'id' => 'username', 'name' => 'username',
96 'value' => $this->requestedUser
) ) . ' ';
98 # Preserve offset and limit
100 $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'offset', 'value' => $this->offset
) );
102 $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'limit', 'value' => $this->limit
) );
104 # Submit button and form bottom
105 $out .= wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'allpagessubmit' ) ) );
106 $out .= wfCloseElement( 'form' );
113 $dbr =& wfGetDB( DB_SLAVE
);
114 $user = $dbr->tableName( 'user' );
115 $user_groups = $dbr->tableName( 'user_groups' );
117 // We need to get an 'atomic' list of users, so that we
118 // don't break the list half-way through a user's group set
119 // and so that lists by group will show all group memberships.
121 // On MySQL 4.1 we could use GROUP_CONCAT to grab group
122 // assignments together with users pretty easily. On other
123 // versions, it's not so easy to do it consistently.
124 // For now we'll just grab the number of memberships, so
125 // we can then do targetted checks on those who are in
126 // non-default groups as we go down the list.
128 $userspace = NS_USER
;
129 $sql = "SELECT 'Listusers' as type, $userspace AS namespace, user_name AS title, " .
130 "user_name as value, user_id, COUNT(ug_group) as numgroups " .
132 "LEFT JOIN $user_groups ON user_id=ug_user " .
133 $this->userQueryWhere( $dbr ) .
134 " GROUP BY user_name";
135 if ( $wgDBtype != 'mysql' ) {
141 function userQueryWhere( &$dbr ) {
142 $conds = $this->userQueryConditions( $dbr );
143 return empty( $conds )
145 : "WHERE " . $dbr->makeList( $conds, LIST_AND
);
148 function userQueryConditions( $dbr ) {
150 if( $this->requestedGroup
!= '' ) {
151 $conds['ug_group'] = $this->requestedGroup
;
153 if( $this->requestedUser
!= '' ) {
154 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser
);
159 function linkParameters() {
161 if( $this->requestedGroup
!= '' ) {
162 $conds['group'] = $this->requestedGroup
;
164 if( $this->requestedUser
!= '' ) {
165 $conds['username'] = $this->requestedUser
;
170 function sortDescending() {
174 function formatResult( $skin, $result ) {
175 $userPage = Title
::makeTitle( $result->namespace, $result->title
);
176 $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
179 if( !isset( $result->numgroups
) ||
$result->numgroups
> 0 ) {
180 $dbr =& wfGetDB( DB_SLAVE
);
181 $result = $dbr->select( 'user_groups',
183 array( 'ug_user' => $result->user_id
),
184 'ListUsersPage::formatResult' );
186 while( $row = $dbr->fetchObject( $result ) ) {
187 $groups[$row->ug_group
] = User
::getGroupMember( $row->ug_group
);
189 $dbr->freeResult( $result );
191 if( count( $groups ) > 0 ) {
192 foreach( $groups as $group => $desc ) {
193 $list[] = User
::makeGroupLinkHTML( $group, $desc );
195 $groups = implode( ', ', $list );
202 return wfSpecialList( $name, $groups );
208 * $par string (optional) A group to list users from
210 function wfSpecialListusers( $par = null ) {
213 list( $limit, $offset ) = wfCheckLimits();
216 $slu = new ListUsersPage();
219 * Get some parameters
221 $groupTarget = isset($par) ?
$par : $wgRequest->getVal( 'group' );
222 $slu->requestedGroup
= $groupTarget;
224 # 'Validate' the username first
225 $username = $wgRequest->getText( 'username', '' );
226 $user = User
::newFromName( $username );
227 $slu->requestedUser
= is_object( $user ) ?
$user->getName() : '';
229 return $slu->doQuery( $offset, $limit );