Remove unneeded commented code, that I accidently added in r82461
[mediawiki.git] / includes / specials / SpecialListusers.php
blob15660886b2af0a8fcd8a5c4c878e2ba3445c9e16
1 <?php
2 /**
3 * Implements Special:Listusers
5 * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
6 * Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu,
7 * 2006 Rob Church <robchur@gmail.com>
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.
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.
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
24 * @file
25 * @ingroup SpecialPage
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.
33 * @ingroup SpecialPage
35 class UsersPager extends AlphabeticPager {
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' );
51 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
52 $this->requestedGroup = '';
54 $this->editsOnly = $wgRequest->getBool( 'editsOnly' );
55 $this->creationSort = $wgRequest->getBool( 'creationSort' );
57 $this->requestedUser = '';
58 if ( $un != '' ) {
59 $username = Title::makeTitleSafe( NS_USER, $un );
60 if( ! is_null( $username ) ) {
61 $this->requestedUser = $username->getText();
64 parent::__construct();
68 function getIndexField() {
69 return $this->creationSort ? 'user_id' : 'user_name';
72 function getQueryInfo() {
73 global $wgUser;
74 $dbr = wfGetDB( DB_SLAVE );
75 $conds = array();
76 // Don't show hidden names
77 if( !$wgUser->isAllowed('hideuser') ) {
78 $conds[] = 'ipb_deleted IS NULL';
81 $options = array();
83 if( $this->requestedGroup != '' ) {
84 $conds['ug_group'] = $this->requestedGroup;
85 } else {
86 //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name';
88 if( $this->requestedUser != '' ) {
89 # Sorted either by account creation or name
90 if( $this->creationSort ) {
91 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
92 } else {
93 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
96 if( $this->editsOnly ) {
97 $conds[] = 'user_editcount > 0';
100 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name';
102 $query = array(
103 'tables' => array( 'user', 'user_groups', 'ipblocks'),
104 'fields' => array(
105 $this->creationSort ? 'MAX(user_name) AS user_name' : 'user_name',
106 $this->creationSort ? 'user_id' : 'MAX(user_id) AS user_id',
107 'MAX(user_editcount) AS edits',
108 'COUNT(ug_group) AS numgroups',
109 'MAX(ug_group) AS singlegroup', // the usergroup if there is only one
110 'MIN(user_registration) AS creation',
111 'MAX(ipb_deleted) AS ipb_deleted' // block/hide status
113 'options' => $options,
114 'join_conds' => array(
115 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ),
116 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0' ),
118 'conds' => $conds
121 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
122 return $query;
125 function formatRow( $row ) {
126 global $wgLang;
128 if ($row->user_id == 0) #Bug 16487
129 return '';
131 $userPage = Title::makeTitle( NS_USER, $row->user_name );
132 $name = $this->getSkin()->link( $userPage, htmlspecialchars( $userPage->getText() ) );
134 $groups_list = self::getGroups( $row->user_id );
135 if( count( $groups_list ) > 0 ) {
136 $list = array();
137 foreach( $groups_list as $group )
138 $list[] = self::buildGroupLink( $group );
139 $groups = $wgLang->commaList( $list );
140 } else {
141 $groups = '';
144 $item = wfSpecialList( $name, $groups );
145 if( $row->ipb_deleted ) {
146 $item = "<span class=\"deleted\">$item</span>";
149 global $wgEdititis;
150 if ( $wgEdititis ) {
151 $editCount = $wgLang->formatNum( $row->edits );
152 $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
153 } else {
154 $edits = '';
157 $created = '';
158 # Some rows may be NULL
159 if( $row->creation ) {
160 $d = $wgLang->date( wfTimestamp( TS_MW, $row->creation ), true );
161 $t = $wgLang->time( wfTimestamp( TS_MW, $row->creation ), true );
162 $created = ' (' . wfMsg( 'usercreated', $d, $t ) . ')';
163 $created = htmlspecialchars( $created );
166 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
167 return "<li>{$item}{$edits}{$created}</li>";
170 function getBody() {
171 if( !$this->mQueryDone ) {
172 $this->doQuery();
174 $this->mResult->rewind();
175 $batch = new LinkBatch;
176 foreach ( $this->mResult as $row ) {
177 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
179 $batch->execute();
180 $this->mResult->rewind();
181 return parent::getBody();
184 function getPageHeader( ) {
185 global $wgScript;
186 $self = $this->getTitle();
188 # Form tag
189 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
190 Xml::fieldset( wfMsg( 'listusers' ) ) .
191 Html::hidden( 'title', $self->getPrefixedDbKey() );
193 # Username field
194 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
195 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
197 # Group drop-down list
198 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
199 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
200 Xml::option( wfMsg( 'group-all' ), '' );
201 foreach( $this->getAllGroups() as $group => $groupText )
202 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
203 $out .= Xml::closeElement( 'select' ) . '<br />';
204 $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
205 $out .= '&#160;';
206 $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
207 $out .= '<br />';
209 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
211 # Submit button and form bottom
212 $out .= Html::hidden( 'limit', $this->mLimit );
213 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
214 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
215 $out .= Xml::closeElement( 'fieldset' ) .
216 Xml::closeElement( 'form' );
218 return $out;
222 * Get a list of all explicit groups
223 * @return array
225 function getAllGroups() {
226 $result = array();
227 foreach( User::getAllGroups() as $group ) {
228 $result[$group] = User::getGroupName( $group );
230 asort( $result );
231 return $result;
235 * Preserve group and username offset parameters when paging
236 * @return array
238 function getDefaultQuery() {
239 $query = parent::getDefaultQuery();
240 if( $this->requestedGroup != '' )
241 $query['group'] = $this->requestedGroup;
242 if( $this->requestedUser != '' )
243 $query['username'] = $this->requestedUser;
244 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
245 return $query;
249 * Get a list of groups the specified user belongs to
251 * @param $uid Integer: user id
252 * @return array
254 protected static function getGroups( $uid ) {
255 $user = User::newFromId( $uid );
256 $groups = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() );
257 return $groups;
261 * Format a link to a group description page
263 * @param $group String: group name
264 * @return string
266 protected 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];
275 * constructor
276 * $par string (optional) A group to list users from
278 function wfSpecialListusers( $par = null ) {
279 global $wgOut;
281 $up = new UsersPager($par);
283 # getBody() first to check, if empty
284 $usersbody = $up->getBody();
285 $s = Xml::openElement( 'div', array('class' => 'mw-spcontent') );
286 $s .= $up->getPageHeader();
287 if( $usersbody ) {
288 $s .= $up->getNavigationBar();
289 $s .= '<ul>' . $usersbody . '</ul>';
290 $s .= $up->getNavigationBar() ;
291 } else {
292 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
294 $s .= Xml::closeElement( 'div' );
295 $wgOut->addHTML( $s );