2 # Copyright (C) 2008 Aaron Schulz
4 # http://www.mediawiki.org/
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 * This class is used to get a list of active users. The ones with specials
23 * rights (sysop, bureaucrat, developer) will have them displayed
24 * next to their names.
27 * @ingroup SpecialPage
29 class ActiveUsersPager
extends UsersPager
{
31 function __construct( $group = null ) {
32 global $wgRequest, $wgRCMaxAge;
33 $this->RCMaxAge
= ceil( $wgRCMaxAge / ( 3600 * 24 ) ); // Constant
35 $un = $wgRequest->getText( 'username' );
36 $this->requestedUser
= '';
38 $username = Title
::makeTitleSafe( NS_USER
, $un );
39 if( !is_null( $username ) ) {
40 $this->requestedUser
= $username->getText();
43 parent
::__construct();
46 function getIndexField() {
47 return 'rc_user_text';
50 function getQueryInfo() {
51 $dbr = wfGetDB( DB_SLAVE
);
52 $conds = array( 'rc_user > 0' ); // Users - no anons
53 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
54 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
55 if( $this->requestedUser
!= '' ) {
56 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
60 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
61 'fields' => array( 'rc_user_text AS user_name', // inheritance
62 'rc_user_text', // for Pager
63 'MAX(user_id) AS user_id',
64 'COUNT(*) AS recentedits',
65 'MAX(ipb_user) AS blocked'
68 'GROUP BY' => 'rc_user_text',
69 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
71 'join_conds' => array(
72 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
73 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
80 function formatRow( $row ) {
82 $userName = $row->user_name
;
84 $ulinks = $this->getSkin()->userLink( $row->user_id
, $userName );
85 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id
, $userName );
88 foreach( self
::getGroups( $row->user_id
) as $group ) {
89 $list[] = self
::buildGroupLink( $group );
91 $groups = $wgLang->commaList( $list );
93 $item = wfSpecialList( $ulinks, $groups );
94 $count = wfMsgExt( 'activeusers-count',
96 $wgLang->formatNum( $row->recentedits
),
98 $wgLang->formatNum ( $this->RCMaxAge
)
100 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
102 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
105 function getPageHeader() {
106 global $wgScript, $wgRequest;
107 $self = $this->getTitle();
108 $limit = $this->mLimit ? Xml
::hidden( 'limit', $this->mLimit
) : '';
110 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . # Form tag
111 Xml
::fieldset( wfMsg( 'activeusers' ) ) . "\n" .
112 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
114 Xml
::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser
) . ' ' . # Username field
115 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .# Submit button and form bottom
116 Xml
::closeElement( 'fieldset' ) .
117 Xml
::closeElement( 'form' );
122 * @ingroup SpecialPage
124 class SpecialActiveUsers
extends SpecialPage
{
129 public function __construct() {
130 parent
::__construct( 'Activeusers' );
134 * Show the special page
136 * @param $par Mixed: parameter passed to the page or null
138 public function execute( $par ) {
139 global $wgOut, $wgLang, $wgRCMaxAge;
143 $up = new ActiveUsersPager();
145 # getBody() first to check, if empty
146 $usersbody = $up->getBody();
148 $s = Html
::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
149 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
152 $s .= $up->getPageHeader();
154 $s .= $up->getNavigationBar();
155 $s .= Html
::rawElement( 'ul', array(), $usersbody );
156 $s .= $up->getNavigationBar();
158 $s .= Html
::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
161 $wgOut->addHTML( $s );