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
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
;
83 $userPage = Title
::makeTitle( NS_USER
, $userName );
84 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
87 foreach( self
::getGroups( $row->user_id
) as $group )
88 $list[] = self
::buildGroupLink( $group );
89 $groups = $wgLang->commaList( $list );
91 $item = wfSpecialList( $name, $groups );
92 $count = wfMsgExt( 'activeusers-count',
94 $wgLang->formatNum( $row->recentedits
),
96 $wgLang->formatNum ( $this->RCMaxAge
)
98 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
100 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
103 function getPageHeader() {
104 global $wgScript, $wgRequest;
105 $self = $this->getTitle();
106 $limit = $this->mLimit ? Xml
::hidden( 'limit', $this->mLimit
) : '';
108 return Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . # Form tag
109 Xml
::fieldset( wfMsg( 'activeusers' ) ) . "\n" .
110 Xml
::hidden( 'title', $self->getPrefixedDBkey() ) .
112 Xml
::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser
) . ' ' . # Username field
113 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .# Submit button and form bottom
114 Xml
::closeElement( 'fieldset' ) .
115 Xml
::closeElement( 'form' );
120 * @ingroup SpecialPage
122 class SpecialActiveUsers
extends SpecialPage
{
127 public function __construct() {
128 parent
::__construct( 'Activeusers' );
132 * Show the special page
134 * @param $par Mixed: parameter passed to the page or null
136 public function execute( $par ) {
141 $up = new ActiveUsersPager();
143 # getBody() first to check, if empty
144 $usersbody = $up->getBody();
145 $s = $up->getPageHeader();
147 $s .= $up->getNavigationBar();
148 $s .= Html
::rawElement( 'ul', array(), $usersbody );
149 $s .= $up->getNavigationBar();
151 $s .= Html
::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
154 $wgOut->addHTML( $s );