95302c84579905200a83396578f31b5f855fafc8
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() {
71 $dbr = wfGetDB( DB_SLAVE
);
72 $conds = array( 'rc_user > 0' ); // Users - no anons
73 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
74 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
76 if( $this->requestedUser
!= '' ) {
77 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
81 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
82 'fields' => array( 'rc_user_text AS user_name', // inheritance
83 'rc_user_text', // for Pager
85 'COUNT(*) AS recentedits',
86 'MAX(ipb_user) AS blocked'
89 'GROUP BY' => 'rc_user_text, user_id',
90 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
92 'join_conds' => array(
93 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
94 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
101 function formatRow( $row ) {
103 $userName = $row->user_name
;
105 $ulinks = $this->getSkin()->userLink( $row->user_id
, $userName );
106 $ulinks .= $this->getSkin()->userToolLinks( $row->user_id
, $userName );
109 foreach( self
::getGroups( $row->user_id
) as $group ) {
110 if (isset($this->groups
[$group]))
112 $list[] = self
::buildGroupLink( $group );
114 $groups = $wgLang->commaList( $list );
116 $item = wfSpecialList( $ulinks, $groups );
117 $count = wfMsgExt( 'activeusers-count',
119 $wgLang->formatNum( $row->recentedits
),
121 $wgLang->formatNum ( $this->RCMaxAge
)
123 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
125 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
128 function getPageHeader() {
129 global $wgScript, $wgRequest;
131 $self = $this->getTitle();
132 $limit = $this->mLimit ? Xml
::hidden( 'limit', $this->mLimit
) : '';
134 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
135 $out .= Xml
::fieldset( wfMsg( 'activeusers' ) ) . "\n";
136 $out .= Xml
::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
138 $out .= Xml
::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser
) . '<br />';# Username field
140 $out .= Xml
::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts
->getValue( 'hidebots' ) );
142 $out .= Xml
::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts
->getValue( 'hidesysops' ) ) . '<br />';
144 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
145 $out .= Xml
::closeElement( 'fieldset' );
146 $out .= Xml
::closeElement( 'form' );
153 * @ingroup SpecialPage
155 class SpecialActiveUsers
extends SpecialPage
{
160 public function __construct() {
161 parent
::__construct( 'Activeusers' );
165 * Show the special page
167 * @param $par Mixed: parameter passed to the page or null
169 public function execute( $par ) {
170 global $wgOut, $wgLang, $wgRCMaxAge;
173 $this->outputHeader();
175 $up = new ActiveUsersPager();
177 # getBody() first to check, if empty
178 $usersbody = $up->getBody();
180 $s = Html
::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
181 wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
184 $s .= $up->getPageHeader();
186 $s .= $up->getNavigationBar();
187 $s .= Html
::rawElement( 'ul', array(), $usersbody );
188 $s .= $up->getNavigationBar();
190 $s .= Html
::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
193 $wgOut->addHTML( $s );