7b6590332f45a6365b3a92ebf50af63519bdee0f
[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 /**
36 * @var FormOptions
37 */
38 protected $opts;
39
40 /**
41 * @var Array
42 */
43 protected $groups;
44
45 function __construct( IContextSource $context = null, $group = null ) {
46 global $wgActiveUserDays;
47
48 parent::__construct( $context );
49
50 $this->RCMaxAge = $wgActiveUserDays;
51 $un = $this->getRequest()->getText( 'username' );
52 $this->requestedUser = '';
53 if ( $un != '' ) {
54 $username = Title::makeTitleSafe( NS_USER, $un );
55 if( !is_null( $username ) ) {
56 $this->requestedUser = $username->getText();
57 }
58 }
59
60 $this->setupOptions();
61 }
62
63 public function setupOptions() {
64 $this->opts = new FormOptions();
65
66 $this->opts->add( 'hidebots', false, FormOptions::BOOL );
67 $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
68
69 $this->opts->fetchValuesFromRequest( $this->getRequest() );
70
71 $this->groups = array();
72 if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
73 $this->groups['bot'] = true;
74 }
75 if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
76 $this->groups['sysop'] = true;
77 }
78 }
79
80 function getIndexField() {
81 return 'rc_user_text';
82 }
83
84 function getQueryInfo() {
85 $dbr = wfGetDB( DB_SLAVE );
86 $conds = array( 'rc_user > 0' ); // Users - no anons
87 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
88 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
89 $conds[] = "rc_timestamp >= '{$dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 )}'";
90
91 if( $this->requestedUser != '' ) {
92 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
93 }
94
95 $query = array(
96 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
97 'fields' => array( 'rc_user_text AS user_name', // inheritance
98 'rc_user_text', // for Pager
99 'user_id',
100 'COUNT(*) AS recentedits',
101 'MAX(ipb_user) AS blocked'
102 ),
103 'options' => array(
104 'GROUP BY' => 'rc_user_text, user_id',
105 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
106 ),
107 'join_conds' => array(
108 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
109 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
110 ),
111 'conds' => $conds
112 );
113 return $query;
114 }
115
116 function formatRow( $row ) {
117 $userName = $row->user_name;
118
119 $ulinks = Linker::userLink( $row->user_id, $userName );
120 $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
121
122 $lang = $this->getLanguage();
123
124 $list = array();
125 foreach( self::getGroups( $row->user_id ) as $group ) {
126 if ( isset( $this->groups[$group] ) ) {
127 return;
128 }
129 $list[] = self::buildGroupLink( $group, $userName );
130 }
131 $groups = $lang->commaList( $list );
132
133 $item = $lang->specialList( $ulinks, $groups );
134 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
135 ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
136 $blocked = $row->blocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
137
138 return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
139 }
140
141 function getPageHeader() {
142 global $wgScript;
143
144 $self = $this->getTitle();
145 $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
146
147 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
148 $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
149 $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
150
151 $out .= Xml::inputLabel( $this->msg( 'activeusers-from' )->text(),
152 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
153
154 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
155 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
156
157 $out .= Xml::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
158 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
159
160 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom
161 $out .= Xml::closeElement( 'fieldset' );
162 $out .= Xml::closeElement( 'form' );
163
164 return $out;
165 }
166 }
167
168 /**
169 * @ingroup SpecialPage
170 */
171 class SpecialActiveUsers extends SpecialPage {
172
173 /**
174 * Constructor
175 */
176 public function __construct() {
177 parent::__construct( 'Activeusers' );
178 }
179
180 /**
181 * Show the special page
182 *
183 * @param $par Mixed: parameter passed to the page or null
184 */
185 public function execute( $par ) {
186 global $wgActiveUserDays;
187
188 $this->setHeaders();
189 $this->outputHeader();
190
191 $out = $this->getOutput();
192 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
193 array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
194
195 $up = new ActiveUsersPager( $this->getContext() );
196
197 # getBody() first to check, if empty
198 $usersbody = $up->getBody();
199
200 $out->addHTML( $up->getPageHeader() );
201 if ( $usersbody ) {
202 $out->addHTML(
203 $up->getNavigationBar() .
204 Html::rawElement( 'ul', array(), $usersbody ) .
205 $up->getNavigationBar()
206 );
207 } else {
208 $out->addWikiMsg( 'activeusers-noresult' );
209 }
210 }
211
212 }