3 * Implements Special:Activeusers
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Implements Special:Activeusers
27 * @ingroup SpecialPage
29 class SpecialActiveUsers
extends SpecialPage
{
31 public function __construct() {
32 parent
::__construct( 'Activeusers' );
36 * @param string|null $par Parameter passed to the page or null
38 public function execute( $par ) {
39 $out = $this->getOutput();
42 $this->outputHeader();
44 $opts = new FormOptions();
46 $opts->add( 'username', '' );
47 $opts->add( 'groups', [] );
48 $opts->add( 'excludegroups', [] );
49 // Backwards-compatibility with old URLs
50 $opts->add( 'hidebots', false, FormOptions
::BOOL );
51 $opts->add( 'hidesysops', false, FormOptions
::BOOL );
53 $opts->fetchValuesFromRequest( $this->getRequest() );
55 if ( $par !== null ) {
56 $opts->setValue( 'username', $par );
59 $pager = new ActiveUsersPager( $this->getContext(), $opts );
60 $usersBody = $pager->getBody();
66 $pager->getNavigationBar() .
67 Html
::rawElement( 'ul', [], $usersBody ) .
68 $pager->getNavigationBar()
70 $out->addModuleStyles( 'mediawiki.interface.helpers.styles' );
72 $out->addWikiMsg( 'activeusers-noresult' );
77 * Generate and output the form
79 protected function buildForm() {
80 $groups = User
::getAllGroups();
83 foreach ( $groups as $group ) {
84 $msg = htmlspecialchars( UserGroupMembership
::getGroupName( $group ) );
85 $options[$msg] = $group;
89 // Backwards-compatibility with old URLs
90 $req = $this->getRequest();
92 if ( $req->getCheck( 'hidebots' ) ) {
93 $excludeDefault[] = 'bot';
95 if ( $req->getCheck( 'hidesysops' ) ) {
96 $excludeDefault[] = 'sysop';
102 'name' => 'username',
103 'label-message' => 'activeusers-from',
106 'type' => 'multiselect',
110 'label-message' => 'activeusers-groups',
111 'options' => $options,
114 'type' => 'multiselect',
117 'name' => 'excludegroups',
118 'label-message' => 'activeusers-excludegroups',
119 'options' => $options,
120 'default' => $excludeDefault,
124 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
125 // For the 'multiselect' field values to be preserved on submit
126 ->setFormIdentifier( 'specialactiveusers' )
127 ->setIntro( $this->getIntroText() )
128 ->setWrapperLegendMsg( 'activeusers' )
129 ->setSubmitTextMsg( 'activeusers-submit' )
130 // prevent setting subpage and 'username' parameter at the same time
131 ->setAction( $this->getPageTitle()->getLocalURL() )
134 ->displayForm( false );
138 * Return introductory message.
141 protected function getIntroText() {
142 $days = $this->getConfig()->get( 'ActiveUserDays' );
144 $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
146 // Mention the level of cache staleness...
147 $dbr = wfGetDB( DB_REPLICA
, 'recentchanges' );
148 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__
);
150 $cTime = $dbr->selectField( 'querycache_info',
152 [ 'qci_type' => 'activeusers' ],
156 $secondsOld = wfTimestamp( TS_UNIX
, $rcMax ) - wfTimestamp( TS_UNIX
, $cTime );
158 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
159 $secondsOld = time() - wfTimestamp( TS_UNIX
, $rcMin );
161 if ( $secondsOld > 0 ) {
162 $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
163 ->durationParams( $secondsOld )->parseAsBlock();
170 protected function getGroupName() {