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
{
45 function __construct( IContextSource
$context = null, $group = null ) {
46 global $wgActiveUserDays;
48 parent
::__construct( $context );
50 $this->RCMaxAge
= $wgActiveUserDays;
51 $un = $this->getRequest()->getText( 'username' );
52 $this->requestedUser
= '';
54 $username = Title
::makeTitleSafe( NS_USER
, $un );
55 if( !is_null( $username ) ) {
56 $this->requestedUser
= $username->getText();
60 $this->setupOptions();
63 public function setupOptions() {
64 $this->opts
= new FormOptions();
66 $this->opts
->add( 'hidebots', false, FormOptions
::BOOL );
67 $this->opts
->add( 'hidesysops', false, FormOptions
::BOOL );
69 $this->opts
->fetchValuesFromRequest( $this->getRequest() );
71 $this->groups
= array();
72 if ( $this->opts
->getValue( 'hidebots' ) == 1 ) {
73 $this->groups
['bot'] = true;
75 if ( $this->opts
->getValue( 'hidesysops' ) == 1 ) {
76 $this->groups
['sysop'] = true;
80 function getIndexField() {
81 return 'rc_user_text';
84 function getQueryInfo() {
85 $dbr = wfGetDB( DB_SLAVE
);
86 $conds = array( 'rc_user > 0' ); // Users - no anons
87 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
88 $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
89 $conds[] = "rc_timestamp >= '{$dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 )}'";
91 if( $this->requestedUser
!= '' ) {
92 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
96 'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
97 'fields' => array( 'rc_user_text AS user_name', // inheritance
98 'rc_user_text', // for Pager
100 'COUNT(*) AS recentedits',
101 'MAX(ipb_user) AS blocked'
104 'GROUP BY' => 'rc_user_text, user_id',
105 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
107 'join_conds' => array(
108 'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
109 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
116 function formatRow( $row ) {
117 $userName = $row->user_name
;
119 $ulinks = Linker
::userLink( $row->user_id
, $userName );
120 $ulinks .= Linker
::userToolLinks( $row->user_id
, $userName );
122 $lang = $this->getLanguage();
125 foreach( self
::getGroups( $row->user_id
) as $group ) {
126 if ( isset( $this->groups
[$group] ) ) {
129 $list[] = self
::buildGroupLink( $group, $userName );
131 $groups = $lang->commaList( $list );
133 $item = $lang->specialList( $ulinks, $groups );
134 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits
)
135 ->params( $userName )->numParams( $this->RCMaxAge
)->escaped();
136 $blocked = $row->blocked ?
' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
138 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
141 function getPageHeader() {
144 $self = $this->getTitle();
145 $limit = $this->mLimit ? Html
::hidden( 'limit', $this->mLimit
) : '';
147 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
148 $out .= Xml
::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
149 $out .= Html
::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
151 $out .= Xml
::inputLabel( $this->msg( 'activeusers-from' )->text(),
152 'username', 'offset', 20, $this->requestedUser
) . '<br />';# Username field
154 $out .= Xml
::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
155 'hidebots', 'hidebots', $this->opts
->getValue( 'hidebots' ) );
157 $out .= Xml
::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
158 'hidesysops', 'hidesysops', $this->opts
->getValue( 'hidesysops' ) ) . '<br />';
160 $out .= Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom
161 $out .= Xml
::closeElement( 'fieldset' );
162 $out .= Xml
::closeElement( 'form' );
169 * @ingroup SpecialPage
171 class SpecialActiveUsers
extends SpecialPage
{
176 public function __construct() {
177 parent
::__construct( 'Activeusers' );
181 * Show the special page
183 * @param $par Mixed: parameter passed to the page or null
185 public function execute( $par ) {
186 global $wgActiveUserDays;
189 $this->outputHeader();
191 $out = $this->getOutput();
192 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
193 array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
195 $up = new ActiveUsersPager( $this->getContext() );
197 # getBody() first to check, if empty
198 $usersbody = $up->getBody();
200 $out->addHTML( $up->getPageHeader() );
203 $up->getNavigationBar() .
204 Html
::rawElement( 'ul', array(), $usersbody ) .
205 $up->getNavigationBar()
208 $out->addWikiMsg( 'activeusers-noresult' );