AuthManager: Break AuthPlugin::addUser more explicitly
[mediawiki.git] / includes / specials / SpecialActiveusers.php
blobc697ca70379e7dc7dd801bdf46696b585a0fe63d
1 <?php
2 /**
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
22 * @file
23 * @ingroup SpecialPage
26 /**
27 * Implements Special:Activeusers
29 * @ingroup SpecialPage
31 class SpecialActiveUsers extends SpecialPage {
33 /**
34 * Constructor
36 public function __construct() {
37 parent::__construct( 'Activeusers' );
40 /**
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();
48 $this->setHeaders();
49 $this->outputHeader();
51 $opts = new FormOptions();
53 $opts->add( 'username', '' );
54 $opts->add( 'hidebots', false, FormOptions::BOOL );
55 $opts->add( 'hidesysops', false, FormOptions::BOOL );
57 $opts->fetchValuesFromRequest( $this->getRequest() );
59 if ( $par !== null ) {
60 $opts->setValue( 'username', $par );
63 // Mention the level of cache staleness...
64 $cacheText = '';
65 $dbr = wfGetDB( DB_SLAVE, 'recentchanges' );
66 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
67 if ( $rcMax ) {
68 $cTime = $dbr->selectField( 'querycache_info',
69 'qci_timestamp',
70 [ 'qci_type' => 'activeusers' ],
71 __METHOD__
73 if ( $cTime ) {
74 $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
75 } else {
76 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
77 $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
79 if ( $secondsOld > 0 ) {
80 $cacheTxt = '<br>' . $this->msg( 'cachedspecial-viewing-cached-ttl' )
81 ->durationParams( $secondsOld );
85 $pager = new ActiveUsersPager( $this->getContext(), $opts );
86 $usersBody = $pager->getBody();
88 $days = $this->getConfig()->get( 'ActiveUserDays' );
90 $formDescriptor = [
91 'username' => [
92 'type' => 'user',
93 'name' => 'username',
94 'label-message' => 'activeusers-from',
97 'hidebots' => [
98 'type' => 'check',
99 'name' => 'hidebots',
100 'label-message' => 'activeusers-hidebots',
101 'default' => false,
104 'hidesysops' => [
105 'type' => 'check',
106 'name' => 'hidesysops',
107 'label-message' => 'activeusers-hidesysops',
108 'default' => false,
112 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
113 ->setIntro( $this->msg( 'activeusers-intro' )->numParams( $days ) . $cacheText )
114 ->setWrapperLegendMsg( 'activeusers' )
115 ->setSubmitTextMsg( 'activeusers-submit' )
116 ->setMethod( 'get' )
117 ->prepareForm()
118 ->displayForm( false );
120 if ( $usersBody ) {
121 $out->addHTML(
122 $pager->getNavigationBar() .
123 Html::rawElement( 'ul', [], $usersBody ) .
124 $pager->getNavigationBar()
126 } else {
127 $out->addWikiMsg( 'activeusers-noresult' );
131 protected function getGroupName() {
132 return 'users';