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
{
43 protected $hideGroups = array();
48 protected $hideRights = array();
51 * @param $context IContextSource
52 * @param $group null Unused
53 * @param string $par Parameter passed to the page
55 function __construct( IContextSource
$context = null, $group = null, $par = null ) {
56 global $wgActiveUserDays;
58 parent
::__construct( $context );
60 $this->RCMaxAge
= $wgActiveUserDays;
61 $un = $this->getRequest()->getText( 'username', $par );
62 $this->requestedUser
= '';
64 $username = Title
::makeTitleSafe( NS_USER
, $un );
65 if ( !is_null( $username ) ) {
66 $this->requestedUser
= $username->getText();
70 $this->setupOptions();
73 public function setupOptions() {
74 $this->opts
= new FormOptions();
76 $this->opts
->add( 'hidebots', false, FormOptions
::BOOL );
77 $this->opts
->add( 'hidesysops', false, FormOptions
::BOOL );
79 $this->opts
->fetchValuesFromRequest( $this->getRequest() );
81 if ( $this->opts
->getValue( 'hidebots' ) == 1 ) {
82 $this->hideRights
[] = 'bot';
84 if ( $this->opts
->getValue( 'hidesysops' ) == 1 ) {
85 $this->hideGroups
[] = 'sysop';
89 function getIndexField() {
90 return 'rc_user_text';
93 function getQueryInfo() {
94 $dbr = $this->getDatabase();
96 $conds = array( 'rc_user > 0' ); // Users - no anons
97 $conds[] = 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' );
98 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes(
99 $dbr->timestamp( wfTimestamp( TS_UNIX
) - $this->RCMaxAge
* 24 * 3600 ) );
101 if ( $this->requestedUser
!= '' ) {
102 $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser
);
105 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
106 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
107 'ipblocks', '1', array( 'rc_user=ipb_user', 'ipb_deleted' => 1 )
112 'tables' => array( 'recentchanges' ),
114 'user_name' => 'rc_user_text', // for Pager inheritance
115 'rc_user_text', // for Pager
116 'user_id' => 'MAX(rc_user)', // Postgres
117 'recentedits' => 'COUNT(*)'
120 'GROUP BY' => array( 'rc_user_text' ),
121 'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
127 function doBatchLookups() {
129 foreach ( $this->mResult
as $row ) {
130 $uids[] = $row->user_id
;
132 // Fetch the block status of the user for showing "(blocked)" text and for
133 // striking out names of suppressed users when privileged user views the list.
134 // Although the first query already hits the block table for un-privileged, this
135 // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
136 $dbr = $this->getDatabase();
137 $res = $dbr->select( 'ipblocks',
138 array( 'ipb_user', 'MAX(ipb_deleted) AS block_status' ),
139 array( 'ipb_user' => $uids ),
141 array( 'GROUP BY' => array( 'ipb_user' ) )
143 $this->blockStatusByUid
= array();
144 foreach ( $res as $row ) {
145 $this->blockStatusByUid
[$row->ipb_user
] = $row->block_status
; // 0 or 1
147 $this->mResult
->seek( 0 );
150 function formatRow( $row ) {
151 $userName = $row->user_name
;
153 $ulinks = Linker
::userLink( $row->user_id
, $userName );
154 $ulinks .= Linker
::userToolLinks( $row->user_id
, $userName );
156 $lang = $this->getLanguage();
159 $user = User
::newFromId( $row->user_id
);
162 foreach ( $this->hideRights
as $right ) {
163 // Calling User::getRights() within the loop so that
164 // if the hideRights() filter is empty, we don't have to
165 // trigger the lazy-init of the big userrights array in the
167 if ( in_array( $right, $user->getRights() ) ) {
173 // Note: This is a different loop than for user rights,
174 // because we're reusing it to build the group links
176 foreach ( $user->getGroups() as $group ) {
177 if ( in_array( $group, $this->hideGroups
) ) {
180 $list[] = self
::buildGroupLink( $group, $userName );
183 $groups = $lang->commaList( $list );
185 $item = $lang->specialList( $ulinks, $groups );
187 $isBlocked = isset( $this->blockStatusByUid
[$row->user_id
] );
188 if ( $isBlocked && $this->blockStatusByUid
[$row->user_id
] == 1 ) {
189 $item = "<span class=\"deleted\">$item</span>";
191 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits
)
192 ->params( $userName )->numParams( $this->RCMaxAge
)->escaped();
193 $blocked = $isBlocked ?
' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
195 return Html
::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
198 function getPageHeader() {
201 $self = $this->getTitle();
202 $limit = $this->mLimit ? Html
::hidden( 'limit', $this->mLimit
) : '';
204 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
205 $out .= Xml
::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
206 $out .= Html
::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
208 $out .= Xml
::inputLabel( $this->msg( 'activeusers-from' )->text(),
209 'username', 'offset', 20, $this->requestedUser
) . '<br />';# Username field
211 $out .= Xml
::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
212 'hidebots', 'hidebots', $this->opts
->getValue( 'hidebots' ) );
214 $out .= Xml
::checkLabel( $this->msg( 'activeusers-hidesysops' )->text(),
215 'hidesysops', 'hidesysops', $this->opts
->getValue( 'hidesysops' ) ) . '<br />';
217 $out .= Xml
::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n";# Submit button and form bottom
218 $out .= Xml
::closeElement( 'fieldset' );
219 $out .= Xml
::closeElement( 'form' );
226 * @ingroup SpecialPage
228 class SpecialActiveUsers
extends SpecialPage
{
233 public function __construct() {
234 parent
::__construct( 'Activeusers' );
238 * Show the special page
240 * @param $par Mixed: parameter passed to the page or null
242 public function execute( $par ) {
243 global $wgActiveUserDays;
246 $this->outputHeader();
248 $out = $this->getOutput();
249 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
250 array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
252 $up = new ActiveUsersPager( $this->getContext(), null, $par );
254 # getBody() first to check, if empty
255 $usersbody = $up->getBody();
257 $out->addHTML( $up->getPageHeader() );
260 $up->getNavigationBar() .
261 Html
::rawElement( 'ul', array(), $usersbody ) .
262 $up->getNavigationBar()
265 $out->addWikiMsg( 'activeusers-noresult' );
269 protected function getGroupName() {