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