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