* Documentation, OBSOLETE => @deprecated
[lhc/web/wiklou.git] / includes / SpecialListusers.php
1 <?php
2 # Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
3 # Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
4 #
5 # http://www.mediawiki.org/
6 #
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.
11 #
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.
16 #
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
21 /**
22 *
23 * @package MediaWiki
24 * @subpackage SpecialPage
25 */
26
27 /**
28 *
29 */
30 require_once('QueryPage.php');
31
32 /**
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.
36 *
37 * @package MediaWiki
38 * @subpackage SpecialPage
39 */
40 class ListUsersPage extends QueryPage {
41 var $requestedGroup = '';
42 var $requestedUser = '';
43 var $previousResult = null;
44 var $concatGroups = '';
45
46 function getName() {
47 return 'Listusers';
48 }
49 function isSyndicated() { return false; }
50
51 /**
52 * Show a drop down list to select a group as well as a user name
53 * search box.
54 * @todo localize
55 */
56 function getPageHeader( ) {
57 global $wgScript;
58
59 // Various variables used for the form
60 $action = htmlspecialchars( $wgScript );
61 $title = Title::makeTitle( NS_SPECIAL, 'Listusers' );
62 $special = htmlspecialchars( $title->getPrefixedDBkey() );
63
64 // form header
65 $out = '<form method="get" action="'.$action.'">' .
66 '<input type="hidden" name="title" value="'.$special.'" />' .
67 wfMsgHtml( 'groups-editgroup-name' ) . '<select name="group">';
68
69 // get all group names and IDs
70 $groups = User::getAllGroups();
71
72 // we want a default empty group
73 $out.= '<option value=""></option>';
74
75 // build the dropdown list menu using datas from the database
76 foreach ( $groups as $group ) {
77 $selected = ($group == $this->requestedGroup);
78 $out .= wfElement( 'option',
79 array_merge(
80 array( 'value' => $group ),
81 $selected ? array( 'selected' => 'selected' ) : array() ),
82 User::getGroupName( $group ) );
83 }
84 $out .= '</select> ';
85
86 $out .= wfMsgHtml( 'specialloguserlabel' ) . '<input type="text" name="username" /> ';
87
88 // OK button, end of form.
89 $out .= '<input type="submit" /></form>';
90 // congratulations the form is now build
91 return $out;
92 }
93
94 function getSQL() {
95 $dbr =& wfGetDB( DB_SLAVE );
96 $user = $dbr->tableName( 'user' );
97 $user_groups = $dbr->tableName( 'user_groups' );
98
99 // We need to get an 'atomic' list of users, so that we
100 // don't break the list half-way through a user's group set
101 // and so that lists by group will show all group memberships.
102 //
103 // On MySQL 4.1 we could use GROUP_CONCAT to grab group
104 // assignments together with users pretty easily. On other
105 // versions, it's not so easy to do it consistently.
106 // For now we'll just grab the number of memberships, so
107 // we can then do targetted checks on those who are in
108 // non-default groups as we go down the list.
109
110 $userspace = NS_USER;
111 $sql = "SELECT 'Listusers' as type, $userspace AS namespace, user_name AS title, " .
112 "user_name as value, user_id, COUNT(ug_group) as numgroups " .
113 "FROM $user ".
114 "LEFT JOIN $user_groups ON user_id=ug_user " .
115 $this->userQueryWhere( $dbr ) .
116 " GROUP BY user_name";
117
118 return $sql;
119 }
120
121 function userQueryWhere( &$dbr ) {
122 $conds = $this->userQueryConditions();
123 return empty( $conds )
124 ? ""
125 : "WHERE " . $dbr->makeList( $conds, LIST_AND );
126 }
127
128 function userQueryConditions() {
129 $conds = array();
130 if( $this->requestedGroup != '' ) {
131 $conds['ug_group'] = $this->requestedGroup;
132 }
133 if( $this->requestedUser != '' ) {
134 $conds['user_name'] = $this->requestedUser;
135 }
136 return $conds;
137 }
138
139 function linkParameters() {
140 $conds = array();
141 if( $this->requestedGroup != '' ) {
142 $conds['group'] = $this->requestedGroup;
143 }
144 if( $this->requestedUser != '' ) {
145 $conds['username'] = $this->requestedUser;
146 }
147 return $conds;
148 }
149
150 function sortDescending() {
151 return false;
152 }
153
154 function formatResult( $skin, $result ) {
155 global $wgContLang;
156
157 $userPage = Title::makeTitle( $result->namespace, $result->title );
158 $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
159
160 if( !isset( $result->numgroups ) || $result->numgroups > 0 ) {
161 $dbr =& wfGetDB( DB_SLAVE );
162 $result = $dbr->select( 'user_groups',
163 array( 'ug_group' ),
164 array( 'ug_user' => $result->user_id ),
165 'ListUsersPage::formatResult' );
166 $groups = array();
167 while( $row = $dbr->fetchObject( $result ) ) {
168 $groups[] = User::getGroupName( $row->ug_group );
169 }
170 $dbr->freeResult( $result );
171
172 if( count( $groups ) > 0 ) {
173 $name .= ' (' .
174 $skin->makeLink( wfMsgForContent( 'administrators' ),
175 htmlspecialchars( implode( ', ', $groups ) ) ) .
176 ')';
177 }
178 }
179
180 return $name;
181 }
182 }
183
184 /**
185 * constructor
186 */
187 function wfSpecialListusers() {
188 global $wgRequest;
189
190 list( $limit, $offset ) = wfCheckLimits();
191
192 $slu = new ListUsersPage();
193
194 /**
195 * Get some parameters
196 */
197 $slu->requestedGroup = $wgRequest->getVal('group');
198 $slu->requestedUser = $wgRequest->getVal('username');
199
200 return $slu->doQuery( $offset, $limit );
201 }
202
203 ?>