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