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
27 * @subpackage SpecialPage
33 require_once('QueryPage.php');
36 * This class is used to get a list of user. The ones with specials
37 * rights (sysop, bureaucrat, developer) will have them displayed
38 * next to their names.
41 * @subpackage SpecialPage
43 class ListUsersPage
extends QueryPage
{
44 var $requestedGroup = '';
45 var $requestedUser = '';
50 function isSyndicated() { return false; }
53 * Not expensive, this class won't work properly with the caching system anyway
55 function isExpensive() {
60 * Fetch user page links and cache their existence
62 function preprocessResults( &$db, &$res ) {
63 $batch = new LinkBatch
;
64 while ( $row = $db->fetchObject( $res ) ) {
65 $batch->addObj( Title
::makeTitleSafe( $row->namespace, $row->title
) );
69 // Back to start for display
70 if( $db->numRows( $res ) > 0 ) {
71 // If there are no rows we get an error seeking.
72 $db->dataSeek( $res, 0 );
77 * Show a drop down list to select a group as well as a user name
81 function getPageHeader( ) {
82 $self = $this->getTitle();
85 $out = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
87 # Group drop-down list
88 $out .= wfElement( 'label', array( 'for' => 'group' ), wfMsg( 'group' ) ) . ' ';
89 $out .= wfOpenElement( 'select', array( 'name' => 'group' ) );
90 $out .= wfElement( 'option', array( 'value' => '' ), wfMsg( 'group-all' ) ); # Item for "all groups"
91 $groups = User
::getAllGroups();
92 foreach( $groups as $group ) {
93 $attribs = array( 'value' => $group );
94 if( $group == $this->requestedGroup
)
95 $attribs['selected'] = 'selected';
96 $out .= wfElement( 'option', $attribs, User
::getGroupName( $group ) );
98 $out .= wfCloseElement( 'select' ) . ' ';;# . wfElement( 'br' );
101 $out .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'specialloguserlabel' ) ) . ' ';
102 $out .= wfElement( 'input', array( 'type' => 'text', 'id' => 'username', 'name' => 'username',
103 'value' => $this->requestedUser
) ) . ' ';
105 # Preserve offset and limit
107 $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'offset', 'value' => $this->offset
) );
109 $out .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'limit', 'value' => $this->limit
) );
111 # Submit button and form bottom
112 $out .= wfElement( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'allpagessubmit' ) ) );
113 $out .= wfCloseElement( 'form' );
119 $dbr =& wfGetDB( DB_SLAVE
);
120 $user = $dbr->tableName( 'user' );
121 $user_groups = $dbr->tableName( 'user_groups' );
123 // We need to get an 'atomic' list of users, so that we
124 // don't break the list half-way through a user's group set
125 // and so that lists by group will show all group memberships.
127 // On MySQL 4.1 we could use GROUP_CONCAT to grab group
128 // assignments together with users pretty easily. On other
129 // versions, it's not so easy to do it consistently.
130 // For now we'll just grab the number of memberships, so
131 // we can then do targetted checks on those who are in
132 // non-default groups as we go down the list.
134 $userspace = NS_USER
;
135 $sql = "SELECT 'Listusers' as type, $userspace AS namespace, user_name AS title, " .
136 "user_name as value, user_id, COUNT(ug_group) as numgroups " .
138 "LEFT JOIN $user_groups ON user_id=ug_user " .
139 $this->userQueryWhere( $dbr ) .
140 " GROUP BY user_name";
145 function userQueryWhere( &$dbr ) {
146 $conds = $this->userQueryConditions();
147 return empty( $conds )
149 : "WHERE " . $dbr->makeList( $conds, LIST_AND
);
152 function userQueryConditions() {
154 if( $this->requestedGroup
!= '' ) {
155 $conds['ug_group'] = $this->requestedGroup
;
157 if( $this->requestedUser
!= '' ) {
158 $conds['user_name'] = $this->requestedUser
;
163 function linkParameters() {
165 if( $this->requestedGroup
!= '' ) {
166 $conds['group'] = $this->requestedGroup
;
168 if( $this->requestedUser
!= '' ) {
169 $conds['username'] = $this->requestedUser
;
174 function sortDescending() {
178 function formatResult( $skin, $result ) {
179 $userPage = Title
::makeTitle( $result->namespace, $result->title
);
180 $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
183 if( !isset( $result->numgroups
) ||
$result->numgroups
> 0 ) {
184 $dbr =& wfGetDB( DB_SLAVE
);
185 $result = $dbr->select( 'user_groups',
187 array( 'ug_user' => $result->user_id
),
188 'ListUsersPage::formatResult' );
190 while( $row = $dbr->fetchObject( $result ) ) {
191 $groups[$row->ug_group
] = User
::getGroupMember( $row->ug_group
);
193 $dbr->freeResult( $result );
195 if( count( $groups ) > 0 ) {
196 foreach( $groups as $group => $desc ) {
197 if( $page = User
::getGroupPage( $group ) ) {
198 $list[] = $skin->makeLinkObj( $page, htmlspecialchars( $desc ) );
200 $list[] = htmlspecialchars( $desc );
203 $groups = implode( ', ', $list );
210 return wfSpecialList( $name, $groups );
216 * $par string (optional) A group to list users from
218 function wfSpecialListusers( $par = null ) {
219 global $wgRequest, $wgContLang;
221 list( $limit, $offset ) = wfCheckLimits();
224 $slu = new ListUsersPage();
227 * Get some parameters
229 $groupTarget = isset($par) ?
$par : $wgRequest->getVal( 'group' );
230 $slu->requestedGroup
= $groupTarget;
232 # 'Validate' the username first
233 $username = $wgRequest->getText( 'username', '' );
234 $user = User
::newFromName( $username );
235 $slu->requestedUser
= is_object( $user ) ?
$user->getName() : '';
237 return $slu->doQuery( $offset, $limit );