Whitelist the <wbr> element.
[mediawiki.git] / includes / specials / SpecialListusers.php
blob75b8490594c932faf4f535f250e5a6bc66656216
1 <?php
2 /**
3 * Implements Special:Listusers
5 * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
6 * Domas Mituzas, Antoine Musso, 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 /**
38 * @param $context IContextSource
39 * @param array $par (Default null)
40 * @param $including boolean Whether this page is being transcluded in
41 * another page
43 function __construct( IContextSource $context = null, $par = null, $including = null ) {
44 if ( $context ) {
45 $this->setContext( $context );
48 $request = $this->getRequest();
49 $par = ( $par !== null ) ? $par : '';
50 $parms = explode( '/', $par );
51 $symsForAll = array( '*', 'user' );
53 if ( $parms[0] != '' &&
54 ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) )
55 ) {
56 $this->requestedGroup = $par;
57 $un = $request->getText( 'username' );
58 } elseif ( count( $parms ) == 2 ) {
59 $this->requestedGroup = $parms[0];
60 $un = $parms[1];
61 } else {
62 $this->requestedGroup = $request->getVal( 'group' );
63 $un = ( $par != '' ) ? $par : $request->getText( 'username' );
66 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
67 $this->requestedGroup = '';
69 $this->editsOnly = $request->getBool( 'editsOnly' );
70 $this->creationSort = $request->getBool( 'creationSort' );
71 $this->including = $including;
73 $this->requestedUser = '';
75 if ( $un != '' ) {
76 $username = Title::makeTitleSafe( NS_USER, $un );
78 if ( !is_null( $username ) ) {
79 $this->requestedUser = $username->getText();
83 parent::__construct();
86 /**
87 * @return string
89 function getIndexField() {
90 return $this->creationSort ? 'user_id' : 'user_name';
93 /**
94 * @return Array
96 function getQueryInfo() {
97 $dbr = wfGetDB( DB_SLAVE );
98 $conds = array();
100 // Don't show hidden names
101 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
102 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
105 $options = array();
107 if ( $this->requestedGroup != '' ) {
108 $conds['ug_group'] = $this->requestedGroup;
111 if ( $this->requestedUser != '' ) {
112 # Sorted either by account creation or name
113 if ( $this->creationSort ) {
114 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
115 } else {
116 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
120 if ( $this->editsOnly ) {
121 $conds[] = 'user_editcount > 0';
124 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name';
126 $query = array(
127 'tables' => array( 'user', 'user_groups', 'ipblocks' ),
128 'fields' => array(
129 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name',
130 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)',
131 'edits' => 'MAX(user_editcount)',
132 'numgroups' => 'COUNT(ug_group)',
133 'singlegroup' => 'MAX(ug_group)', // the usergroup if there is only one
134 'creation' => 'MIN(user_registration)',
135 'ipb_deleted' => 'MAX(ipb_deleted)' // block/hide status
137 'options' => $options,
138 'join_conds' => array(
139 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ),
140 'ipblocks' => array(
141 'LEFT JOIN', array(
142 'user_id=ipb_user',
143 'ipb_auto' => 0
147 'conds' => $conds
150 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
152 return $query;
156 * @param $row Object
157 * @return String
159 function formatRow( $row ) {
160 if ( $row->user_id == 0 ) { #Bug 16487
161 return '';
164 $userName = $row->user_name;
166 $ulinks = Linker::userLink( $row->user_id, $userName );
167 $ulinks .= Linker::userToolLinksRedContribs(
168 $row->user_id,
169 $userName,
170 (int)$row->edits
173 $lang = $this->getLanguage();
175 $groups = '';
176 $groups_list = self::getGroups( $row->user_id );
178 if ( !$this->including && count( $groups_list ) > 0 ) {
179 $list = array();
180 foreach ( $groups_list as $group ) {
181 $list[] = self::buildGroupLink( $group, $userName );
183 $groups = $lang->commaList( $list );
186 $item = $lang->specialList( $ulinks, $groups );
188 if ( $row->ipb_deleted ) {
189 $item = "<span class=\"deleted\">$item</span>";
192 $edits = '';
193 global $wgEdititis;
194 if ( !$this->including && $wgEdititis ) {
195 // @fixme i18n issue: Hardcoded square brackets.
196 $edits = ' [' .
197 $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() .
198 ']';
201 $created = '';
202 # Some rows may be null
203 if ( !$this->including && $row->creation ) {
204 $user = $this->getUser();
205 $d = $lang->userDate( $row->creation, $user );
206 $t = $lang->userTime( $row->creation, $user );
207 $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped();
208 $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped();
210 $blocked = !is_null( $row->ipb_deleted ) ?
211 ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() :
214 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
216 return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" );
219 function doBatchLookups() {
220 $batch = new LinkBatch();
221 # Give some pointers to make user links
222 foreach ( $this->mResult as $row ) {
223 $batch->add( NS_USER, $row->user_name );
224 $batch->add( NS_USER_TALK, $row->user_name );
226 $batch->execute();
227 $this->mResult->rewind();
231 * @return string
233 function getPageHeader() {
234 global $wgScript;
236 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() );
238 # Form tag
239 $out = Xml::openElement(
240 'form',
241 array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' )
243 Xml::fieldset( $this->msg( 'listusers' )->text() ) .
244 Html::hidden( 'title', $self );
246 # Username field
247 $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' .
248 Html::input(
249 'username',
250 $this->requestedUser,
251 'text',
252 array(
253 'id' => 'offset',
254 'size' => 20,
255 'autofocus' => $this->requestedUser === ''
257 ) . ' ';
259 # Group drop-down list
260 $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' .
261 Xml::openElement( 'select', array( 'name' => 'group', 'id' => 'group' ) ) .
262 Xml::option( $this->msg( 'group-all' )->text(), '' );
263 foreach ( $this->getAllGroups() as $group => $groupText ) {
264 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
266 $out .= Xml::closeElement( 'select' ) . '<br />';
267 $out .= Xml::checkLabel(
268 $this->msg( 'listusers-editsonly' )->text(),
269 'editsOnly',
270 'editsOnly',
271 $this->editsOnly
273 $out .= '&#160;';
274 $out .= Xml::checkLabel(
275 $this->msg( 'listusers-creationsort' )->text(),
276 'creationSort',
277 'creationSort',
278 $this->creationSort
280 $out .= '<br />';
282 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
284 # Submit button and form bottom
285 $out .= Html::hidden( 'limit', $this->mLimit );
286 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() );
287 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
288 $out .= Xml::closeElement( 'fieldset' ) .
289 Xml::closeElement( 'form' );
291 return $out;
295 * Get a list of all explicit groups
296 * @return array
298 function getAllGroups() {
299 $result = array();
300 foreach ( User::getAllGroups() as $group ) {
301 $result[$group] = User::getGroupName( $group );
303 asort( $result );
305 return $result;
309 * Preserve group and username offset parameters when paging
310 * @return array
312 function getDefaultQuery() {
313 $query = parent::getDefaultQuery();
314 if ( $this->requestedGroup != '' ) {
315 $query['group'] = $this->requestedGroup;
317 if ( $this->requestedUser != '' ) {
318 $query['username'] = $this->requestedUser;
320 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
322 return $query;
326 * Get a list of groups the specified user belongs to
328 * @param $uid Integer: user id
329 * @return array
331 protected static function getGroups( $uid ) {
332 $user = User::newFromId( $uid );
333 $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() );
335 return $groups;
339 * Format a link to a group description page
341 * @param string $group group name
342 * @param string $username Username
343 * @return string
345 protected static function buildGroupLink( $group, $username ) {
346 return User::makeGroupLinkHtml(
347 $group,
348 htmlspecialchars( User::getGroupMember( $group, $username ) )
354 * @ingroup SpecialPage
356 class SpecialListUsers extends IncludableSpecialPage {
358 * Constructor
360 public function __construct() {
361 parent::__construct( 'Listusers' );
365 * Show the special page
367 * @param string $par (optional) A group to list users from
369 public function execute( $par ) {
370 $this->setHeaders();
371 $this->outputHeader();
373 $up = new UsersPager( $this->getContext(), $par, $this->including() );
375 # getBody() first to check, if empty
376 $usersbody = $up->getBody();
378 $s = '';
379 if ( !$this->including() ) {
380 $s = $up->getPageHeader();
383 if ( $usersbody ) {
384 $s .= $up->getNavigationBar();
385 $s .= Html::rawElement( 'ul', array(), $usersbody );
386 $s .= $up->getNavigationBar();
387 } else {
388 $s .= $this->msg( 'listusers-noresult' )->parseAsBlock();
391 $this->getOutput()->addHTML( $s );
394 protected function getGroupName() {
395 return 'users';