2 # Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
3 # Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
5 # http://www.mediawiki.org/
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
24 * @subpackage SpecialPage
30 require_once('QueryPage.php');
33 * This class is used to get a list of user. The ones with specials
34 * rights (sysop, bureaucrat, developer) will have them displayed
35 * next to their names.
38 * @subpackage SpecialPage
40 class ListUsersPage
extends QueryPage
{
41 var $requestedGroup = '';
42 var $requestedUser = '';
43 var $previousResult = null;
44 var $concatGroups = '';
49 function isSyndicated() { return false; }
52 * Show a drop down list to select a group as well as a user name
56 function getPageHeader( ) {
59 // Various variables used for the form
60 $action = htmlspecialchars( $wgScript );
61 $title = Title
::makeTitle( NS_SPECIAL
, 'Listusers' );
62 $special = htmlspecialchars( $title->getPrefixedDBkey() );
65 $out = '<form method="get" action="'.$action.'">' .
66 '<input type="hidden" name="title" value="'.$special.'" />' .
67 wfMsg( 'grouplevels-editgroup-name' ) . '<select name="group">';
69 // get all group names and IDs
70 $groups =& Group
::getAllGroups();
72 // we want a default empty group
73 $out.= '<option value=""></option>';
75 // build the dropdown list menu using datas from the database
76 foreach ( $groups as $group ) {
77 $selected = ($group->getId() == $this->requestedGroup
) ?
' selected ' : '' ;
78 $out.= '<option value="'.$group->getId().'" '.$selected.'>'.$group->getExpandedName().'</option>';
82 $out .= wfMsg( 'specialloguserlabel' ) . '<input type="text" name="username" /> ';
84 // OK button, end of form.
85 $out .= '<input type="submit" /></form>';
86 // congratulations the form is now build
91 $dbr =& wfGetDB( DB_SLAVE
);
92 /* system showing possible actions for users
93 $user = $dbr->tableName( 'user' );
94 $user_rights = $dbr->tableName( 'user_rights' );
95 $userspace = Namespace::getUser();
96 return "SELECT ur_rights as type, $userspace as namespace, user_name as title, " .
97 "user_name as value FROM $user LEFT JOIN $user_rights ON user_id = ur_user";
99 /** Show groups instead */
100 $user = $dbr->tableName( 'user' );
101 $user_groups = $dbr->tableName( 'user_groups' );
103 $userspace = NS_USER
;
104 $sql = "SELECT CONCAT('Listusers ', ug_group) as type, $userspace AS namespace, user_name AS title, user_name as value " .
106 "LEFT JOIN $user_groups ON user_id =ug_user ";
108 if($this->requestedGroup
!= '') {
109 $sql .= "WHERE ug_group = '" . IntVal( $this->requestedGroup
) . "' ";
110 if($this->requestedUser
!= '') {
111 $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser
) . ' ';
114 if($this->requestedUser
!='') {
115 $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser
) . ' ';
123 * When calling formatResult we output the previous result instead of the
124 * current one. We need an additional step to flush out the last result.
126 function tryLastResult( ) {
130 function sortDescending() {
134 function appendGroups($group) {
135 $this->concatGroups
.= $group.' ';
138 function clearGroups() {
139 $this->concatGroups
= '';
142 var $previousResult = false;
143 var $concatGroups = '';
145 function formatResult( $skin, $result ) {
149 if( is_object( $this->previousResult
) &&
150 (is_null( $result ) ||
( $this->previousResult
->title
!= $result->title
) ) ) {
151 // Different username, give back name(group1,group2)
152 $name = $skin->makeLink( $wgContLang->getNsText($this->previousResult
->namespace) . ':' . $this->previousResult
->title
, $this->previousResult
->title
);
153 $name .= $this->concatGroups ?
' ('.substr($this->concatGroups
,0,-1).')' : '';
154 $this->clearGroups();
157 if( is_object( $result ) && $result->type
!= '') {
158 $group = Group
::newFromId( intval( strstr( $result->type
, ' ' ) ) );
160 $groupName = $group->getExpandedName();
161 $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $groupName ) );
165 $this->previousResult
= $result;
173 function wfSpecialListusers() {
176 list( $limit, $offset ) = wfCheckLimits();
178 $slu = new ListUsersPage();
181 * Get some parameters
183 $slu->requestedGroup
= $wgRequest->getVal('group');
184 $slu->requestedUser
= $wgRequest->getVal('username');
186 return $slu->doQuery( $offset, $limit );