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', [] );
56 $opts->fetchValuesFromRequest( $this->getRequest() );
58 if ( $par !== null ) {
59 $opts->setValue( 'username', $par );
62 $pager = new ActiveUsersPager( $this->getContext(), $opts );
63 $usersBody = $pager->getBody();
69 $pager->getNavigationBar() .
70 Html
::rawElement( 'ul', [], $usersBody ) .
71 $pager->getNavigationBar()
74 $out->addWikiMsg( 'activeusers-noresult' );
79 * Generate and output the form
81 protected function buildForm() {
82 $groups = User
::getAllGroups();
84 foreach ( $groups as $group ) {
85 $msg = User
::getGroupName( $group );
86 $options[$msg] = $group;
93 'label-message' => 'activeusers-from',
97 'type' => 'multiselect',
101 'label-message' => 'activeusers-groups',
102 'options' => $options,
106 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
107 // For the 'multiselect' field values to be preserved on submit
108 ->setFormIdentifier( 'specialactiveusers' )
109 ->setIntro( $this->getIntroText() )
110 ->setWrapperLegendMsg( 'activeusers' )
111 ->setSubmitTextMsg( 'activeusers-submit' )
112 // prevent setting subpage and 'username' parameter at the same time
113 ->setAction( $this->getPageTitle()->getLocalURL() )
116 ->displayForm( false );
120 * Return introductory message.
123 protected function getIntroText() {
124 $days = $this->getConfig()->get( 'ActiveUserDays' );
126 $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
128 // Mention the level of cache staleness...
129 $dbr = wfGetDB( DB_REPLICA
, 'recentchanges' );
130 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__
);
132 $cTime = $dbr->selectField( 'querycache_info',
134 [ 'qci_type' => 'activeusers' ],
138 $secondsOld = wfTimestamp( TS_UNIX
, $rcMax ) - wfTimestamp( TS_UNIX
, $cTime );
140 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
141 $secondsOld = time() - wfTimestamp( TS_UNIX
, $rcMin );
143 if ( $secondsOld > 0 ) {
144 $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
145 ->durationParams( $secondsOld )->parseAsBlock();
152 protected function getGroupName() {