3 * Implements Special:Activeusers
5 * Copyright © 2008 Aaron Schulz
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.
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.
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
23 * @ingroup SpecialPage
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.
31 * @ingroup SpecialPage
33 class ActiveUsersPager
extends UsersPager
{
45 function __construct( $group = null ) {
46 global $wgRequest, $wgActiveUserDays;
47 $this->RCMaxAge
= $wgActiveUserDays;
48 $un = $wgRequest->getText( 'username' );
49 $this->requestedUser
= '';
51 $username = Title
::makeTitleSafe( NS_USER
, $un );
52 if( !is_null( $username ) ) {
53 $this->requestedUser
= $username->getText();
57 $this->setupOptions();
59 parent
::__construct();
63 return SpecialPage
::getTitleFor( 'Activeusers' );
66 public function setupOptions() {
69 $this->opts
= new FormOptions();
71 $this->opts
->add( 'hidebots', false, FormOptions
::BOOL );
72 $this->opts
->add( 'hidesysops', false, FormOptions
::BOOL );
74 $this->opts
->fetchValuesFromRequest( $wgRequest );
76 $this->groups
= array();
77 if ( $this->opts
->getValue( 'hidebots' ) == 1 ) {
78 $this->groups
['bot'] = true;
80 if ( $this->opts
->getValue( 'hidesysops' ) == 1 ) {
81 $this->groups
['sysop'] = true;
85 function getIndexField() {
86 return 'rc_user_text';
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 )}'";
96 if( $this->requestedUser
!= '' ) {
97 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
101 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
102 'fields' => array( 'rc_user_text AS user_name', // inheritance
103 'rc_user_text', // for Pager
105 'COUNT(*) AS recentedits',
106 'MAX(ipb_user) AS blocked'
109 'GROUP BY' => 'rc_user_text, user_id',
110 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
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' ),
121 function formatRow( $row ) {
123 $userName = $row->user_name
;
125 $ulinks = $this->getSkin()->userLink( $row->user_id
, $userName );
126 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id
, $userName );
129 foreach( self
::getGroups( $row->user_id
) as $group ) {
130 if ( isset( $this->groups
[$group] ) ) {
133 $list[] = self
::buildGroupLink( $group );
135 $groups = $wgLang->commaList( $list );
137 $item = wfSpecialList( $ulinks, $groups );
138 $count = wfMsgExt( 'activeusers-count',
140 $wgLang->formatNum( $row->recentedits
),
142 $wgLang->formatNum ( $this->RCMaxAge
)
144 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
146 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
149 function getPageHeader() {
152 $self = $this->getTitle();
153 $limit = $this->mLimit ? Html
::hidden( 'limit', $this->mLimit
) : '';
155 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
156 $out .= Xml
::fieldset( wfMsg( 'activeusers' ) ) . "\n";
157 $out .= Html
::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
159 $out .= Xml
::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser
) . '<br />';# Username field
161 $out .= Xml
::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts
->getValue( 'hidebots' ) );
163 $out .= Xml
::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts
->getValue( 'hidesysops' ) ) . '<br />';
165 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
166 $out .= Xml
::closeElement( 'fieldset' );
167 $out .= Xml
::closeElement( 'form' );
174 * @ingroup SpecialPage
176 class SpecialActiveUsers
extends SpecialPage
{
181 public function __construct() {
182 parent
::__construct( 'Activeusers' );
186 * Show the special page
188 * @param $par Mixed: parameter passed to the page or null
190 public function execute( $par ) {
191 global $wgOut, $wgLang, $wgActiveUserDays;
194 $this->outputHeader();
196 $up = new ActiveUsersPager();
198 # getBody() first to check, if empty
199 $usersbody = $up->getBody();
201 $s = Html
::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
202 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgActiveUserDays ) )
205 $s .= $up->getPageHeader();
207 $s .= $up->getNavigationBar();
208 $s .= Html
::rawElement( 'ul', array(), $usersbody );
209 $s .= $up->getNavigationBar();
211 $s .= Html
::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
214 $wgOut->addHTML( $s );