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
{
34 public function __construct() {
35 parent
::__construct( 'Activeusers' );
39 * Show the special page
41 * @param string $par Parameter passed to the page or null
43 public function execute( $par ) {
44 $out = $this->getOutput();
47 $this->outputHeader();
49 $opts = new FormOptions();
51 $opts->add( 'username', '' );
52 $opts->add( 'groups', [] );
53 $opts->add( 'excludegroups', [] );
54 // Backwards-compatibility with old URLs
55 $opts->add( 'hidebots', false, FormOptions
::BOOL );
56 $opts->add( 'hidesysops', false, FormOptions
::BOOL );
58 $opts->fetchValuesFromRequest( $this->getRequest() );
60 if ( $par !== null ) {
61 $opts->setValue( 'username', $par );
64 $pager = new ActiveUsersPager( $this->getContext(), $opts );
65 $usersBody = $pager->getBody();
71 $pager->getNavigationBar() .
72 Html
::rawElement( 'ul', [], $usersBody ) .
73 $pager->getNavigationBar()
76 $out->addWikiMsg( 'activeusers-noresult' );
81 * Generate and output the form
83 protected function buildForm() {
84 $groups = User
::getAllGroups();
86 foreach ( $groups as $group ) {
87 $msg = htmlspecialchars( UserGroupMembership
::getGroupName( $group ) );
88 $options[$msg] = $group;
91 // Backwards-compatibility with old URLs
92 $req = $this->getRequest();
94 if ( $req->getCheck( 'hidebots' ) ) {
95 $excludeDefault[] = 'bot';
97 if ( $req->getCheck( 'hidesysops' ) ) {
98 $excludeDefault[] = 'sysop';
104 'name' => 'username',
105 'label-message' => 'activeusers-from',
108 'type' => 'multiselect',
112 'label-message' => 'activeusers-groups',
113 'options' => $options,
116 'type' => 'multiselect',
119 'name' => 'excludegroups',
120 'label-message' => 'activeusers-excludegroups',
121 'options' => $options,
122 'default' => $excludeDefault,
126 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
127 // For the 'multiselect' field values to be preserved on submit
128 ->setFormIdentifier( 'specialactiveusers' )
129 ->setIntro( $this->getIntroText() )
130 ->setWrapperLegendMsg( 'activeusers' )
131 ->setSubmitTextMsg( 'activeusers-submit' )
132 // prevent setting subpage and 'username' parameter at the same time
133 ->setAction( $this->getPageTitle()->getLocalURL() )
136 ->displayForm( false );
140 * Return introductory message.
143 protected function getIntroText() {
144 $days = $this->getConfig()->get( 'ActiveUserDays' );
146 $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
148 // Mention the level of cache staleness...
149 $dbr = wfGetDB( DB_REPLICA
, 'recentchanges' );
150 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__
);
152 $cTime = $dbr->selectField( 'querycache_info',
154 [ 'qci_type' => 'activeusers' ],
158 $secondsOld = wfTimestamp( TS_UNIX
, $rcMax ) - wfTimestamp( TS_UNIX
, $cTime );
160 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
161 $secondsOld = time() - wfTimestamp( TS_UNIX
, $rcMin );
163 if ( $secondsOld > 0 ) {
164 $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
165 ->durationParams( $secondsOld )->parseAsBlock();
172 protected function getGroupName() {