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 * Implements Special:Activeusers
29 * @ingroup SpecialPage
31 class SpecialActiveUsers
extends SpecialPage
{
36 public function __construct() {
37 parent
::__construct( 'Activeusers' );
41 * Show the special page
43 * @param string $par Parameter passed to the page or null
45 public function execute( $par ) {
46 $out = $this->getOutput();
49 $this->outputHeader();
51 $opts = new FormOptions();
53 $opts->add( 'username', '' );
54 $opts->add( 'groups', [] );
55 $opts->add( 'excludegroups', [] );
56 // Backwards-compatibility with old URLs
57 $opts->add( 'hidebots', false, FormOptions
::BOOL );
58 $opts->add( 'hidesysops', false, FormOptions
::BOOL );
60 $opts->fetchValuesFromRequest( $this->getRequest() );
62 if ( $par !== null ) {
63 $opts->setValue( 'username', $par );
66 $pager = new ActiveUsersPager( $this->getContext(), $opts );
67 $usersBody = $pager->getBody();
73 $pager->getNavigationBar() .
74 Html
::rawElement( 'ul', [], $usersBody ) .
75 $pager->getNavigationBar()
78 $out->addWikiMsg( 'activeusers-noresult' );
83 * Generate and output the form
85 protected function buildForm() {
86 $groups = User
::getAllGroups();
88 foreach ( $groups as $group ) {
89 $msg = htmlspecialchars( UserGroupMembership
::getGroupName( $group ) );
90 $options[$msg] = $group;
93 // Backwards-compatibility with old URLs
94 $req = $this->getRequest();
96 if ( $req->getCheck( 'hidebots' ) ) {
97 $excludeDefault[] = 'bot';
99 if ( $req->getCheck( 'hidesysops' ) ) {
100 $excludeDefault[] = 'sysop';
106 'name' => 'username',
107 'label-message' => 'activeusers-from',
110 'type' => 'multiselect',
114 'label-message' => 'activeusers-groups',
115 'options' => $options,
118 'type' => 'multiselect',
121 'name' => 'excludegroups',
122 'label-message' => 'activeusers-excludegroups',
123 'options' => $options,
124 'default' => $excludeDefault,
128 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
129 // For the 'multiselect' field values to be preserved on submit
130 ->setFormIdentifier( 'specialactiveusers' )
131 ->setIntro( $this->getIntroText() )
132 ->setWrapperLegendMsg( 'activeusers' )
133 ->setSubmitTextMsg( 'activeusers-submit' )
134 // prevent setting subpage and 'username' parameter at the same time
135 ->setAction( $this->getPageTitle()->getLocalURL() )
138 ->displayForm( false );
142 * Return introductory message.
145 protected function getIntroText() {
146 $days = $this->getConfig()->get( 'ActiveUserDays' );
148 $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
150 // Mention the level of cache staleness...
151 $dbr = wfGetDB( DB_REPLICA
, 'recentchanges' );
152 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__
);
154 $cTime = $dbr->selectField( 'querycache_info',
156 [ 'qci_type' => 'activeusers' ],
160 $secondsOld = wfTimestamp( TS_UNIX
, $rcMax ) - wfTimestamp( TS_UNIX
, $cTime );
162 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
163 $secondsOld = time() - wfTimestamp( TS_UNIX
, $rcMin );
165 if ( $secondsOld > 0 ) {
166 $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
167 ->durationParams( $secondsOld )->parseAsBlock();
174 protected function getGroupName() {