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