Give the username field an identifier so the label is "linked" to it again
[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 *
26 * @addtogroup 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 * @addtogroup SpecialPage
35 */
36
37 class UsersPager extends AlphabeticPager {
38
39 function __construct($group=null) {
40 global $wgRequest;
41 $this->requestedGroup = $group != "" ? $group : $wgRequest->getVal( 'group' );
42 $un = $wgRequest->getText( 'username' );
43 $this->requestedUser = '';
44 if ( $un != '' ) {
45 $username = Title::makeTitleSafe( NS_USER, $un );
46 if( ! is_null( $username ) ) {
47 $this->requestedUser = $username->getText();
48 }
49 }
50 parent::__construct();
51 }
52
53
54 function getIndexField() {
55 return 'user_name';
56 }
57
58 function getQueryInfo() {
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 }
65 if ($this->requestedUser != "") {
66 $conds[] = 'user_name >= ' . wfGetDB()->addQuotes( $this->requestedUser );
67 }
68
69 list ($user,$user_groups,$ipblocks) = wfGetDB()->tableNamesN('user','user_groups','ipblocks');
70
71 return array(
72 'tables' => " $user LEFT JOIN $user_groups ON user_id=ug_user LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
73 'fields' => array('user_name',
74 'MAX(user_id) AS user_id',
75 'COUNT(ug_group) AS numgroups',
76 'MAX(ug_group) AS singlegroup'),
77 'options' => array('GROUP BY' => 'user_name'),
78 'conds' => $conds
79 );
80
81 }
82
83 function formatRow($row) {
84 $userPage = Title::makeTitle(NS_USER, $row->user_name);
85 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
86 $groups = array();
87 if ($row->numgroups > 1 || ( $this->requestedGroup and $row->numgroups == 1) ) {
88 $dbr = wfGetDB(DB_SLAVE);
89 $result = $dbr->select( 'user_groups', 'ug_group',
90 array( 'ug_user' => $row->user_id ),
91 'UsersPager::formatRow' );
92 while ( $group = $dbr->fetchObject($result)) {
93 $groups[$group->ug_group] = User::getGroupMember ( $group->ug_group );
94 }
95 $dbr->freeResult($result);
96 } elseif ($row->numgroups == 1 ) { // MAX hack inside query :)
97 $groups[$row->singlegroup] = User::getGroupMember( $row->singlegroup );
98 }
99
100 if ( count($groups) > 0 ) {
101 foreach( $groups as $group => $desc ) {
102 $list[] = User::makeGroupLinkHTML( $group, $desc);
103 }
104 $groups = implode( ', ', $list);
105 } else {
106 $groups ='';
107 }
108 //$ulink = $skin->userLink( $result->user, $result->user_text ) . ' ' . $skin->userToolLinks( $result->user, $result->user_text );
109 return '<li>' . wfSpecialList ($name, $groups) .'</li>';
110 }
111
112 function getBody() {
113 if (!$this->mQueryDone) {
114 $this->doQuery();
115 }
116 $batch = new LinkBatch;
117 $db = $this->mDb;
118
119 $this->mResult->rewind();
120
121 while ( $row = $this->mResult->fetchObject() ) {
122 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
123 }
124 $batch->execute();
125 $this->mResult->rewind();
126 return parent::getBody();
127 }
128
129 function getPageHeader( ) {
130 global $wgRequest;
131 $self = $this->getTitle();
132
133 # Form tag
134 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $self->getLocalUrl() ) ) .
135 '<fieldset>' .
136 Xml::element( 'legend', array(), wfMsg( 'listusers' ) );
137
138 # Username field
139 $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
140 Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
141
142 if( $this->mLimit )
143 $out .= Xml::hidden( 'limit', $this->mLimit );
144
145 # Group drop-down list
146 $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
147 Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) .
148 Xml::option( wfMsg( 'group-all' ), '' ); # Item for "all groups"
149
150 $groups = User::getAllGroups();
151 foreach( $groups as $group ) {
152 $attribs = array( 'value' => $group );
153 $attribs['selected'] = ( $group == $this->requestedGroup ) ? 'selected' : '';
154 $out .= Xml::option( User::getGroupName( $group ), $attribs['value'], $attribs['selected'] );
155 }
156 $out .= Xml::closeElement( 'select' ) . ' ';
157
158 # Submit button and form bottom
159 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
160 '</fieldset>' .
161 Xml::closeElement( 'form' );
162
163 return $out;
164 }
165
166 /**
167 * Preserve group and username offset parameters when paging
168 * @return array
169 */
170 function getDefaultQuery() {
171 $query = parent::getDefaultQuery();
172 if( $this->requestedGroup != '' )
173 $query['group'] = $this->requestedGroup;
174 if( $this->requestedUser != '' )
175 $query['username'] = $this->requestedUser;
176 return $query;
177 }
178 }
179
180 /**
181 * constructor
182 * $par string (optional) A group to list users from
183 */
184 function wfSpecialListusers( $par = null ) {
185 global $wgRequest, $wgOut;
186
187 list( $limit, $offset ) = wfCheckLimits();
188
189 $groupTarget = isset($par) ? $par : $wgRequest->getVal( 'group' );
190
191 $up = new UsersPager($par);
192
193 # getBody() first to check, if empty
194 $usersbody = $up->getBody();
195 $s = $up->getPageHeader();
196 if( $usersbody ) {
197 $s .= $up->getNavigationBar();
198 $s .= '<ul>' . $usersbody . '</ul>';
199 $s .= $up->getNavigationBar() ;
200 } else {
201 $s .= '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
202 };
203 $wgOut->addHTML( $s );
204 }
205
206 ?>