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
{
35 function __construct( $group = null ) {
36 global $wgRequest, $wgActiveUserDays;
37 $this->RCMaxAge
= $wgActiveUserDays;
38 $un = $wgRequest->getText( 'username' );
39 $this->requestedUser
= '';
41 $username = Title
::makeTitleSafe( NS_USER
, $un );
42 if( !is_null( $username ) ) {
43 $this->requestedUser
= $username->getText();
47 $this->setupOptions();
49 parent
::__construct();
52 public function setupOptions() {
55 $this->opts
= new FormOptions();
57 $this->opts
->add( 'hidebots', false, FormOptions
::BOOL );
58 $this->opts
->add( 'hidesysops', false, FormOptions
::BOOL );
60 $this->opts
->fetchValuesFromRequest( $wgRequest );
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;
69 function getIndexField() {
70 return 'rc_user_text';
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 )}'";
80 if( $this->requestedUser
!= '' ) {
81 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
85 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
86 'fields' => array( 'rc_user_text AS user_name', // inheritance
87 'rc_user_text', // for Pager
89 'COUNT(*) AS recentedits',
90 'MAX(ipb_user) AS blocked'
93 'GROUP BY' => 'rc_user_text, user_id',
94 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
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' ),
105 function formatRow( $row ) {
107 $userName = $row->user_name
;
109 $ulinks = $this->getSkin()->userLink( $row->user_id
, $userName );
110 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id
, $userName );
113 foreach( self
::getGroups( $row->user_id
) as $group ) {
114 if (isset($this->groups
[$group]))
116 $list[] = self
::buildGroupLink( $group );
118 $groups = $wgLang->commaList( $list );
120 $item = wfSpecialList( $ulinks, $groups );
121 $count = wfMsgExt( 'activeusers-count',
123 $wgLang->formatNum( $row->recentedits
),
125 $wgLang->formatNum ( $this->RCMaxAge
)
127 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
129 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
132 function getPageHeader() {
135 $self = $this->getTitle();
136 $limit = $this->mLimit ? Xml
::hidden( 'limit', $this->mLimit
) : '';
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";
142 $out .= Xml
::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser
) . '<br />';# Username field
144 $out .= Xml
::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts
->getValue( 'hidebots' ) );
146 $out .= Xml
::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts
->getValue( 'hidesysops' ) ) . '<br />';
148 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
149 $out .= Xml
::closeElement( 'fieldset' );
150 $out .= Xml
::closeElement( 'form' );
157 * @ingroup SpecialPage
159 class SpecialActiveUsers
extends SpecialPage
{
164 public function __construct() {
165 parent
::__construct( 'Activeusers' );
169 * Show the special page
171 * @param $par Mixed: parameter passed to the page or null
173 public function execute( $par ) {
174 global $wgOut, $wgLang, $wgActiveUserDays;
177 $this->outputHeader();
179 $up = new ActiveUsersPager();
181 # getBody() first to check, if empty
182 $usersbody = $up->getBody();
184 $s = Html
::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
185 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgActiveUserDays ) )
188 $s .= $up->getPageHeader();
190 $s .= $up->getNavigationBar();
191 $s .= Html
::rawElement( 'ul', array(), $usersbody );
192 $s .= $up->getNavigationBar();
194 $s .= Html
::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
197 $wgOut->addHTML( $s );