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 ) {
33 $un = $wgRequest->getText( 'username' );
34 $this->requestedUser
= '';
36 $username = Title
::makeTitleSafe( NS_USER
, $un );
37 if( !is_null( $username ) ) {
38 $this->requestedUser
= $username->getText();
41 parent
::__construct();
44 function getIndexField() {
45 return 'rc_user_text';
48 function getQueryInfo() {
49 $dbr = wfGetDB( DB_SLAVE
);
50 $conds = array('rc_user > 0'); // Users - no anons
51 $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
52 $conds[] = 'rc_log_type IS NULL OR rc_log_type != "newusers"';
53 $useIndex = $dbr->useIndexClause( 'rc_user_text' );
54 if( $this->requestedUser
!= '' ) {
55 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
58 list( $recentchanges, $ipblocks, $user ) = $dbr->tableNamesN( 'recentchanges', 'ipblocks', 'user' );
61 'tables' => "$recentchanges $useIndex
62 INNER JOIN $user ON rc_user_text=user_name
63 LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1 ",
64 'fields' => array( 'rc_user_text AS user_name', // inheritance
65 'rc_user_text', // for Pager
67 'COUNT(*) AS recentedits',
68 'MAX(ipb_user) AS blocked' ),
69 'options' => array( 'GROUP BY' => 'rc_user_text' ),
75 function formatRow( $row ) {
76 $userName = $row->rc_user_text
;
77 $userPage = Title
::makeTitle( NS_USER
, $userName );
78 $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
81 foreach( self
::getGroups( $row->user_id
) as $group )
82 $list[] = self
::buildGroupLink( $group );
83 $groups = implode( ', ', $list );
85 $item = wfSpecialList( $name, $groups );
86 $count = wfMsgExt( 'activeusers-count', array( 'parsemag' ), $row->recentedits
, $userName );
87 $blocked = $row->blocked ?
' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
89 return "<li>{$item} [{$count}]{$blocked}</li>";
92 function getPageHeader() {
93 global $wgScript, $wgRequest;
94 $self = $this->getTitle();
97 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
99 Xml
::element( 'legend', array(), wfMsg( 'activeusers' ) );
100 $out .= Xml
::hidden( 'title', $self->getPrefixedDBkey() );
103 $out .= Xml
::label( wfMsg( 'activeusers-from' ), 'offset' ) . ' ' .
104 Xml
::input( 'username', 20, $this->requestedUser
, array( 'id' => 'offset' ) ) . ' ';
106 # Submit button and form bottom
108 $out .= Xml
::hidden( 'limit', $this->mLimit
);
109 $out .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) );
111 $out .= '</fieldset>' . Xml
::closeElement( 'form' );
118 * @ingroup SpecialPage
120 class SpecialActiveUsers
extends SpecialPage
{
125 public function __construct() {
126 parent
::__construct( 'ActiveUsers' );
130 * Show the special page
132 * @param $par Mixed: parameter passed to the page or null
134 public function execute( $par ) {
139 $up = new ActiveUsersPager();
141 # getBody() first to check, if empty
142 $usersbody = $up->getBody();
143 $s = $up->getPageHeader();
145 $s .= $up->getNavigationBar();
146 $s .= '<ul>' . $usersbody . '</ul>';
147 $s .= $up->getNavigationBar();
149 $s .= '<p>' . wfMsgHtml( 'activeusers-noresult' ) . '</p>';
152 $wgOut->addHTML( $s );