Follow-up r84814: revert redundant summary message addition.
[lhc/web/wiklou.git] / includes / specials / SpecialListusers.php
1 <?php
2 /**
3 * Implements Special:Listusers
4 *
5 * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
6 * Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu,
7 * 2006 Rob Church <robchur@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 * @ingroup SpecialPage
26 */
27
28 /**
29 * This class is used to get a list of user. The ones with specials
30 * rights (sysop, bureaucrat, developer) will have them displayed
31 * next to their names.
32 *
33 * @ingroup SpecialPage
34 */
35 class SpecialListUsers extends QueryPage {
36
37 function __construct( $par=null ) {
38 global $wgRequest;
39 $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
40 $symsForAll = array( '*', 'user' );
41 if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) {
42 $this->requestedGroup = $par;
43 $un = $wgRequest->getText( 'username' );
44 } else if ( count( $parms ) == 2 ) {
45 $this->requestedGroup = $parms[0];
46 $un = $parms[1];
47 } else {
48 $this->requestedGroup = $wgRequest->getVal( 'group' );
49 $un = ( $par != '' ) ? $par : $wgRequest->getText( 'username' );
50 }
51 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
52 $this->requestedGroup = '';
53 }
54 $this->editsOnly = $wgRequest->getBool( 'editsOnly' );
55 $this->creationSort = $wgRequest->getBool( 'creationSort' );
56
57 $this->requestedUser = '';
58 if ( $un != '' ) {
59 $username = Title::makeTitleSafe( NS_USER, $un );
60 if( ! is_null( $username ) ) {
61 $this->requestedUser = $username->getText();
62 }
63 }
64
65 $this->limit = $wgRequest->getVal( 'limit' );
66 $this->offset = $wgRequest->getVal( 'offset' );
67
68 parent::__construct( 'Listusers' );
69 }
70
71 function isExpensive() { return false; }
72 function isCacheable() { return false; }
73 function isSyndicated() { return false; }
74 function sortDescending() { return false; }
75
76 function openList( $offset ) {
77 return "\n<ul class='special'>\n";
78 }
79
80 function closeList() {
81 return "</ul>\n";
82 }
83
84 function linkParameters() {
85 return array(
86 'group' => $this->requestedGroup,
87 'editsOnly' => $this->editsOnly,
88 'creationSort' => $this->creationSort,
89 'requestedUser' => $this->requestedUser,
90 );
91 }
92
93 function getQueryInfo() {
94
95 global $wgUser;
96 $dbr = wfGetDB( DB_SLAVE );
97 $conds = $jconds = array();
98 $tables = array( 'user' );
99
100 // Don't show hidden names
101 if( !$wgUser->isAllowed('hideuser') ) {
102 $tables[] = 'ipblocks';
103 $conds[] = 'ipb_deleted IS NULL';
104 $jconds['ipblocks'] = array( 'LEFT JOIN', array(
105 # Unique index on (ipb_address,ipb_user,ipb_auto)
106 'ipb_address = user_name',
107 'ipb_user = user_id',
108 'ipb_auto = 0',
109 'ipb_deleted = 1',
110 ) );
111 }
112
113 if( $this->requestedGroup != '' ) {
114 $tables[] = 'user_groups';
115 $conds['ug_group'] = $this->requestedGroup;
116 # Unique index on (ug_user,ug_group)
117 $jconds['user_groups'] = array( 'LEFT JOIN', 'user_id = ug_user' );
118 }
119
120 if( $this->requestedUser != '' ) {
121 # Sorted either by account creation or name
122 if( $this->creationSort ) {
123 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
124 } else {
125 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
126 }
127 }
128
129 if( $this->editsOnly ) {
130 $conds[] = 'user_editcount > 0';
131 }
132
133 $query = array(
134 'tables' => $tables,
135 'fields' => '*',
136 'join_conds' => $jconds,
137 'conds' => $conds
138 );
139
140 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
141 return $query;
142 }
143
144 function formatResult( $skin, $row ) {
145 global $wgLang;
146
147 if ( $row->user_id == 0 ){
148 #Bug 16487
149 return false;
150 }
151
152 $user = User::newFromId( $row->user_id );
153 $name = $skin->link(
154 $user->getUserpage(),
155 $user->getName()
156 );
157
158 $groups_list = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() );
159 if( count( $groups_list ) > 0 ) {
160 $list = array();
161 foreach( $groups_list as $group )
162 $list[] = self::buildGroupLink( $group );
163 $groups = $wgLang->commaList( $list );
164 } else {
165 $groups = '';
166 }
167
168 $item = wfSpecialList( $name, $groups );
169 if( isset( $row->ipb_deleted ) ) {
170 $item = "<span class=\"deleted\">$item</span>";
171 }
172
173 global $wgEdititis;
174 if ( $wgEdititis ) {
175 $editCount = $wgLang->formatNum( $row->edits );
176 $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
177 } else {
178 $edits = '';
179 }
180
181 $created = '';
182 # Some rows may be NULL
183 if( $row->user_registration ) {
184 $d = $wgLang->date( wfTimestamp( TS_MW, $row->user_registration ), true );
185 $t = $wgLang->time( wfTimestamp( TS_MW, $row->user_registration ), true );
186 $created = ' (' . wfMessage( 'usercreated', $d, $t ) . ')';
187 }
188
189 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
190 return "{$item}{$edits}{$created}";
191 }
192
193 function getOrderFields() {
194 return $this->creationSort ? array( 'user_id' ) : array( 'user_name' );
195 }
196
197 /**
198 * Cache page existence for performance
199 */
200 function preprocessResults( $db, $res ) {
201 $batch = new LinkBatch;
202 foreach ( $res as $row ) {
203 $batch->add( NS_USER, $row->user_name );
204 $batch->add( NS_USER_TALK, $row->user_name );
205 }
206 $batch->execute();
207
208 // Back to start for display
209 if ( $db->numRows( $res ) > 0 ) {
210 // If there are no rows we get an error seeking.
211 $db->dataSeek( $res, 0 );
212 }
213 }
214
215 function getPageHeader( ) {
216 global $wgScript;
217 $self = $this->getTitle();
218
219 # Form tag
220 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
221 Xml::fieldset( wfMsg( 'listusers' ) ) .
222 Html::hidden( 'title', $self->getPrefixedDbKey() );
223
224 # Username field
225 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
226 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
227
228 # Group drop-down list
229 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
230 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
231 Xml::option( wfMsg( 'group-all' ), '' );
232
233 $groups = array_unique( array_diff( User::getAllGroups(), array( '*', 'user' ) ) );
234 foreach( $groups as $group ){
235 $out .= Xml::option(
236 User::getGroupName( $group ),
237 $group,
238 $group == $this->requestedGroup
239 );
240 }
241
242 $out .= Xml::closeElement( 'select' ) . '<br />';
243 $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
244 $out .= '&#160;';
245 $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
246 $out .= '<br />';
247
248 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
249
250 # Submit button and form bottom
251 $out .= Html::hidden( 'limit', $this->limit );
252 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
253 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
254 $out .= Xml::closeElement( 'fieldset' ) .
255 Xml::closeElement( 'form' );
256
257 return $out;
258 }
259
260 /**
261 * Format a link to a group description page
262 * Also called by SpecialActiveUsers
263 * @param $group String: group name
264 * @return string
265 */
266 public static function buildGroupLink( $group ) {
267 static $cache = array();
268 if( !isset( $cache[$group] ) )
269 $cache[$group] = User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group ) ) );
270 return $cache[$group];
271 }
272 }