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