Add the other existing $skin.css/.js to the message files too to be consistent
[lhc/web/wiklou.git] / includes / SpecialListusers.php
1 <?php
2
3 # Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
4 # Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
5 #
6 # © 2006 Rob Church <robchur@gmail.com>
7 #
8 # http://www.mediawiki.org/
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 # http://www.gnu.org/copyleft/gpl.html
24 /**
25 * @file
26 * @ingroup SpecialPage
27 */
28
29 /**
30 * This class is used to get a list of user. The ones with specials
31 * rights (sysop, bureaucrat, developer) will have them displayed
32 * next to their names.
33 *
34 * @ingroup SpecialPage
35 */
36 class UsersPager extends AlphabeticPager {
37
38 function __construct($group=null) {
39 global $wgRequest;
40 $this->requestedGroup = $group != "" ? $group : $wgRequest->getVal( 'group' );
41 $un = $wgRequest->getText( 'username' );
42 $this->requestedUser = '';
43 if ( $un != '' ) {
44 $username = Title::makeTitleSafe( NS_USER, $un );
45 if( ! is_null( $username ) ) {
46 $this->requestedUser = $username->getText();
47 }
48 }
49 parent::__construct();
50 }
51
52
53 function getIndexField() {
54 return 'user_name';
55 }
56
57 function getQueryInfo() {
58 $dbr = wfGetDB( DB_SLAVE );
59 $conds=array();
60 // don't show hidden names
61 $conds[]='ipb_deleted IS NULL OR ipb_deleted = 0';
62 if ($this->requestedGroup != "") {
63 $conds['ug_group'] = $this->requestedGroup;
64 $useIndex = '';
65 } else {
66 $useIndex = $dbr->useIndexClause('user_name');
67 }
68 if ($this->requestedUser != "") {
69 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
70 }
71
72 list ($user,$user_groups,$ipblocks) = $dbr->tableNamesN('user','user_groups','ipblocks');
73
74 $query = array(
75 'tables' => " $user $useIndex LEFT JOIN $user_groups ON user_id=ug_user
76 LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
77 'fields' => array('user_name',
78 'MAX(user_id) AS user_id',
79 'COUNT(ug_group) AS numgroups',
80 'MAX(ug_group) AS singlegroup'),
81 'options' => array('GROUP BY' => 'user_name'),
82 'conds' => $conds
83 );
84
85 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
86 return $query;
87 }
88
89 function formatRow( $row ) {
90 $userPage = Title::makeTitle( NS_USER, $row->user_name );
91 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
92
93 if( $row->numgroups > 1 || ( $this->requestedGroup && $row->numgroups == 1 ) ) {
94 $list = array();
95 foreach( self::getGroups( $row->user_id ) as $group )
96 $list[] = self::buildGroupLink( $group );
97 $groups = implode( ', ', $list );
98 } elseif( $row->numgroups == 1 ) {
99 $groups = self::buildGroupLink( $row->singlegroup );
100 } else {
101 $groups = '';
102 }
103
104 $item = wfSpecialList( $name, $groups );
105 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
106 return "<li>{$item}</li>";
107 }
108
109 function getBody() {
110 if (!$this->mQueryDone) {
111 $this->doQuery();
112 }
113 $batch = new LinkBatch;
114
115 $this->mResult->rewind();
116
117 while ( $row = $this->mResult->fetchObject() ) {
118 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
119 }
120 $batch->execute();
121 $this->mResult->rewind();
122 return parent::getBody();
123 }
124
125 function getPageHeader( ) {
126 global $wgScript, $wgRequest;
127 $self = $this->getTitle();
128
129 # Form tag
130 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
131 '<fieldset>' .
132 Xml::element( 'legend', array(), wfMsg( 'listusers' ) );
133 $out .= Xml::hidden( 'title', $self->getPrefixedDbKey() );
134
135 # Username field
136 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
137 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
138
139 # Group drop-down list
140 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
141 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
142 Xml::option( wfMsg( 'group-all' ), '' );
143 foreach( $this->getAllGroups() as $group => $groupText )
144 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
145 $out .= Xml::closeElement( 'select' ) . ' ';
146
147 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
148
149 # Submit button and form bottom
150 if( $this->mLimit )
151 $out .= Xml::hidden( 'limit', $this->mLimit );
152 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
153 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
154 $out .= '</fieldset>' .
155 Xml::closeElement( 'form' );
156
157 return $out;
158 }
159
160 function getAllGroups() {
161 $result = array();
162 foreach( User::getAllGroups() as $group ) {
163 $result[$group] = User::getGroupName( $group );
164 }
165 return $result;
166 }
167
168 /**
169 * Preserve group and username offset parameters when paging
170 * @return array
171 */
172 function getDefaultQuery() {
173 $query = parent::getDefaultQuery();
174 if( $this->requestedGroup != '' )
175 $query['group'] = $this->requestedGroup;
176 if( $this->requestedUser != '' )
177 $query['username'] = $this->requestedUser;
178 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
179 return $query;
180 }
181
182 /**
183 * Get a list of groups the specified user belongs to
184 *
185 * @param int $uid
186 * @return array
187 */
188 protected static function getGroups( $uid ) {
189 $dbr = wfGetDB( DB_SLAVE );
190 $groups = array();
191 $res = $dbr->select( 'user_groups', 'ug_group', array( 'ug_user' => $uid ), __METHOD__ );
192 if( $res && $dbr->numRows( $res ) > 0 ) {
193 while( $row = $dbr->fetchObject( $res ) )
194 $groups[] = $row->ug_group;
195 $dbr->freeResult( $res );
196 }
197 return $groups;
198 }
199
200 /**
201 * Format a link to a group description page
202 *
203 * @param string $group
204 * @return string
205 */
206 protected static function buildGroupLink( $group ) {
207 static $cache = array();
208 if( !isset( $cache[$group] ) )
209 $cache[$group] = User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
210 return $cache[$group];
211 }
212 }
213
214 /**
215 * constructor
216 * $par string (optional) A group to list users from
217 */
218 function wfSpecialListusers( $par = null ) {
219 global $wgRequest, $wgOut;
220
221 $up = new UsersPager($par);
222
223 # getBody() first to check, if empty
224 $usersbody = $up->getBody();
225 $s = $up->getPageHeader();
226 if( $usersbody ) {
227 $s .= $up->getNavigationBar();
228 $s .= '<ul>' . $usersbody . '</ul>';
229 $s .= $up->getNavigationBar() ;
230 } else {
231 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
232 };
233
234 $wgOut->addHTML( $s );
235 }