a5f1b3c10976a0292d322ddafb15f02baa3e6b5e
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();
44 $this->setupOptions();
46 parent
::__construct();
49 public function setupOptions() {
52 $this->opts
= new FormOptions();
54 $this->opts
->add( 'hidebots', false, FormOptions
::BOOL );
55 $this->opts
->add( 'hidesysops', false, FormOptions
::BOOL );
57 $this->opts
->fetchValuesFromRequest( $wgRequest );
59 $this->groups
= array();
60 if ($this->opts
->getValue('hidebots') == 1)
61 $this->groups
['bot'] = true;
62 if ($this->opts
->getValue('hidesysops') == 1)
63 $this->groups
['sysop'] = true;
66 function getIndexField() {
67 return 'rc_user_text';
70 function getQueryInfo() {
73 $dbr = wfGetDB( DB_SLAVE
);
74 $conds = array( 'rc_user > 0' ); // Users - no anons
75 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
76 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
78 if( $this->requestedUser
!= '' ) {
79 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
83 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
84 'fields' => array( 'rc_user_text AS user_name', // inheritance
85 'rc_user_text', // for Pager
86 'MAX(user_id) AS user_id',
87 'COUNT(*) AS recentedits',
88 'MAX(ipb_user) AS blocked'
91 'GROUP BY' => ( $dbr->implicitGroupby() ||
$wgDBtype == 'sqlite' ) ?
'rc_user_text' : 'rc_user_text, user_id',
92 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
94 'join_conds' => array(
95 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
96 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
103 function formatRow( $row ) {
105 $userName = $row->user_name
;
107 $ulinks = $this->getSkin()->userLink( $row->user_id
, $userName );
108 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id
, $userName );
111 foreach( self
::getGroups( $row->user_id
) as $group ) {
112 if (isset($this->groups
[$group]))
114 $list[] = self
::buildGroupLink( $group );
116 $groups = $wgLang->commaList( $list );
118 $item = wfSpecialList( $ulinks, $groups );
119 $count = wfMsgExt( 'activeusers-count',
121 $wgLang->formatNum( $row->recentedits
),
123 $wgLang->formatNum ( $this->RCMaxAge
)
125 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
127 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
130 function getPageHeader() {
131 global $wgScript, $wgRequest;
133 $self = $this->getTitle();
134 $limit = $this->mLimit ? Xml
::hidden( 'limit', $this->mLimit
) : '';
136 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
137 $out .= Xml
::fieldset( wfMsg( 'activeusers' ) ) . "\n";
138 $out .= Xml
::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
140 $out .= Xml
::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser
) . '<br />';# Username field
142 $out .= Xml
::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts
->getValue( 'hidebots' ) );
144 $out .= Xml
::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts
->getValue( 'hidesysops' ) ) . '<br />';
146 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
147 $out .= Xml
::closeElement( 'fieldset' );
148 $out .= Xml
::closeElement( 'form' );
155 * @ingroup SpecialPage
157 class SpecialActiveUsers
extends SpecialPage
{
162 public function __construct() {
163 parent
::__construct( 'Activeusers' );
167 * Show the special page
169 * @param $par Mixed: parameter passed to the page or null
171 public function execute( $par ) {
172 global $wgOut, $wgLang, $wgRCMaxAge;
176 $up = new ActiveUsersPager();
178 # getBody() first to check, if empty
179 $usersbody = $up->getBody();
181 $s = Html
::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
182 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
185 $s .= $up->getPageHeader();
187 $s .= $up->getNavigationBar();
188 $s .= Html
::rawElement( 'ul', array(), $usersbody );
189 $s .= $up->getNavigationBar();
191 $s .= Html
::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
194 $wgOut->addHTML( $s );