369e79620fed82f4f519f36713cb717c773db35a
[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 if ($this->opts->getValue('hidesysops') == 1)
66 $this->groups['sysop'] = true;
67 }
68
69 function getIndexField() {
70 return 'rc_user_text';
71 }
72
73 function getQueryInfo() {
74 $dbr = wfGetDB( DB_SLAVE );
75 $conds = array( 'rc_user > 0' ); // Users - no anons
76 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
77 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
78 $conds[] = "rc_timestamp >= '{$dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 )}'";
79
80 if( $this->requestedUser != '' ) {
81 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
82 }
83
84 $query = array(
85 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
86 'fields' => array( 'rc_user_text AS user_name', // inheritance
87 'rc_user_text', // for Pager
88 'user_id',
89 'COUNT(*) AS recentedits',
90 'MAX(ipb_user) AS blocked'
91 ),
92 'options' => array(
93 'GROUP BY' => 'rc_user_text, user_id',
94 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
95 ),
96 'join_conds' => array(
97 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
98 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
99 ),
100 'conds' => $conds
101 );
102 return $query;
103 }
104
105 function formatRow( $row ) {
106 global $wgLang;
107 $userName = $row->user_name;
108
109 $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
110 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
111
112 $list = array();
113 foreach( self::getGroups( $row->user_id ) as $group ) {
114 if (isset($this->groups[$group]))
115 return;
116 $list[] = self::buildGroupLink( $group );
117 }
118 $groups = $wgLang->commaList( $list );
119
120 $item = wfSpecialList( $ulinks, $groups );
121 $count = wfMsgExt( 'activeusers-count',
122 array( 'parsemag' ),
123 $wgLang->formatNum( $row->recentedits ),
124 $userName,
125 $wgLang->formatNum ( $this->RCMaxAge )
126 );
127 $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
128
129 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
130 }
131
132 function getPageHeader() {
133 global $wgScript;
134
135 $self = $this->getTitle();
136 $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
137
138 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
139 $out .= Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n";
140 $out .= Xml::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
141
142 $out .= Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
143
144 $out .= Xml::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
145
146 $out .= Xml::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
147
148 $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
149 $out .= Xml::closeElement( 'fieldset' );
150 $out .= Xml::closeElement( 'form' );
151
152 return $out;
153 }
154 }
155
156 /**
157 * @ingroup SpecialPage
158 */
159 class SpecialActiveUsers extends SpecialPage {
160
161 /**
162 * Constructor
163 */
164 public function __construct() {
165 parent::__construct( 'Activeusers' );
166 }
167
168 /**
169 * Show the special page
170 *
171 * @param $par Mixed: parameter passed to the page or null
172 */
173 public function execute( $par ) {
174 global $wgOut, $wgLang, $wgActiveUserDays;
175
176 $this->setHeaders();
177 $this->outputHeader();
178
179 $up = new ActiveUsersPager();
180
181 # getBody() first to check, if empty
182 $usersbody = $up->getBody();
183
184 $s = Html::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
185 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgActiveUserDays ) )
186 );
187
188 $s .= $up->getPageHeader();
189 if( $usersbody ) {
190 $s .= $up->getNavigationBar();
191 $s .= Html::rawElement( 'ul', array(), $usersbody );
192 $s .= $up->getNavigationBar();
193 } else {
194 $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
195 }
196
197 $wgOut->addHTML( $s );
198 }
199
200 }