*(bug 20717) Added checkboxes to users with bot and ssop group membership
[lhc/web/wiklou.git] / includes / specials / SpecialActiveusers.php
1 <?php
2 # Copyright (C) 2008 Aaron Schulz
3 #
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 /**
22 * This class is used to get a list of active users. The ones with specials
23 * rights (sysop, bureaucrat, developer) will have them displayed
24 * next to their names.
25 *
26 * @file
27 * @ingroup SpecialPage
28 */
29 class ActiveUsersPager extends UsersPager {
30
31 function __construct( $group = null ) {
32 global $wgRequest, $wgRCMaxAge;
33 $this->RCMaxAge = ceil( $wgRCMaxAge / ( 3600 * 24 ) ); // Constant
34
35 $un = $wgRequest->getText( 'username' );
36 $this->requestedUser = '';
37 if ( $un != '' ) {
38 $username = Title::makeTitleSafe( NS_USER, $un );
39 if( !is_null( $username ) ) {
40 $this->requestedUser = $username->getText();
41 }
42 }
43
44 $this->setupOptions();
45
46 parent::__construct();
47 }
48
49 public function setupOptions() {
50 global $wgRequest;
51
52 $this->opts = new FormOptions();
53
54 $this->opts->add( 'hidebots', false, FormOptions::BOOL );
55 $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
56
57 $this->opts->fetchValuesFromRequest( $wgRequest );
58
59 $this->groups = array();
60 if ($this->opts->getValue('hidebots') == 1)
61 $this->groups['bot'] = true;
62 if ($this->opts->getValue('hidesysops') == 1)
63 $this->groups['sysop'] = true;
64 }
65
66 function getIndexField() {
67 return 'rc_user_text';
68 }
69
70 function getQueryInfo() {
71 global $wgDBtype;
72
73 $dbr = wfGetDB( DB_SLAVE );
74 $conds = array( 'rc_user > 0' ); // Users - no anons
75 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
76 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
77
78 if( $this->requestedUser != '' ) {
79 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
80 }
81
82 $query = array(
83 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
84 'fields' => array( 'rc_user_text AS user_name', // inheritance
85 'rc_user_text', // for Pager
86 'MAX(user_id) AS user_id',
87 'COUNT(*) AS recentedits',
88 'MAX(ipb_user) AS blocked'
89 ),
90 'options' => array(
91 'GROUP BY' => ( $dbr->implicitGroupby() || $wgDBtype == 'sqlite' ) ? 'rc_user_text' : 'rc_user_text, user_id',
92 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
93 ),
94 'join_conds' => array(
95 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
96 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
97 ),
98 'conds' => $conds
99 );
100 return $query;
101 }
102
103 function formatRow( $row ) {
104 global $wgLang;
105 $userName = $row->user_name;
106
107 $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
108 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
109
110 $list = array();
111 foreach( self::getGroups( $row->user_id ) as $group ) {
112 if (isset($this->groups[$group]))
113 return;
114 $list[] = self::buildGroupLink( $group );
115 }
116 $groups = $wgLang->commaList( $list );
117
118 $item = wfSpecialList( $ulinks, $groups );
119 $count = wfMsgExt( 'activeusers-count',
120 array( 'parsemag' ),
121 $wgLang->formatNum( $row->recentedits ),
122 $userName,
123 $wgLang->formatNum ( $this->RCMaxAge )
124 );
125 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
126
127 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
128 }
129
130 function getPageHeader() {
131 global $wgScript, $wgRequest;
132
133 $self = $this->getTitle();
134 $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
135
136 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
137 $out .= Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n";
138 $out .= Xml::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
139
140 $out .= Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
141
142 $out .= Xml::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
143
144 $out .= Xml::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
145
146 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
147 $out .= Xml::closeElement( 'fieldset' );
148 $out .= Xml::closeElement( 'form' );
149
150 return $out;
151 }
152 }
153
154 /**
155 * @ingroup SpecialPage
156 */
157 class SpecialActiveUsers extends SpecialPage {
158
159 /**
160 * Constructor
161 */
162 public function __construct() {
163 parent::__construct( 'Activeusers' );
164 }
165
166 /**
167 * Show the special page
168 *
169 * @param $par Mixed: parameter passed to the page or null
170 */
171 public function execute( $par ) {
172 global $wgOut, $wgLang, $wgRCMaxAge;
173
174 $this->setHeaders();
175
176 $up = new ActiveUsersPager();
177
178 # getBody() first to check, if empty
179 $usersbody = $up->getBody();
180
181 $s = Html::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
182 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
183 );
184
185 $s .= $up->getPageHeader();
186 if( $usersbody ) {
187 $s .= $up->getNavigationBar();
188 $s .= Html::rawElement( 'ul', array(), $usersbody );
189 $s .= $up->getNavigationBar();
190 } else {
191 $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
192 }
193
194 $wgOut->addHTML( $s );
195 }
196
197 }