Merge "Migration of browsertests* Jenkins jobs to selenium* jobs"
[lhc/web/wiklou.git] / includes / specials / SpecialActiveusers.php
1 <?php
2 /**
3 * Implements Special:Activeusers
4 *
5 * Copyright © 2008 Aaron Schulz
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 * @ingroup SpecialPage
24 */
25
26 /**
27 * @ingroup SpecialPage
28 */
29 class SpecialActiveUsers extends SpecialPage {
30
31 /**
32 * Constructor
33 */
34 public function __construct() {
35 parent::__construct( 'Activeusers' );
36 }
37
38 /**
39 * Show the special page
40 *
41 * @param string $par Parameter passed to the page or null
42 */
43 public function execute( $par ) {
44 $days = $this->getConfig()->get( 'ActiveUserDays' );
45
46 $this->setHeaders();
47 $this->outputHeader();
48
49 $out = $this->getOutput();
50 $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
51 [ 'activeusers-intro', $this->getLanguage()->formatNum( $days ) ] );
52
53 // Mention the level of cache staleness...
54 $dbr = wfGetDB( DB_SLAVE, 'recentchanges' );
55 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
56 if ( $rcMax ) {
57 $cTime = $dbr->selectField( 'querycache_info',
58 'qci_timestamp',
59 [ 'qci_type' => 'activeusers' ],
60 __METHOD__
61 );
62 if ( $cTime ) {
63 $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
64 } else {
65 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
66 $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
67 }
68 if ( $secondsOld > 0 ) {
69 $out->addWikiMsg( 'cachedspecial-viewing-cached-ttl',
70 $this->getLanguage()->formatDuration( $secondsOld ) );
71 }
72 }
73
74 $up = new ActiveUsersPager( $this->getContext(), null, $par );
75
76 # getBody() first to check, if empty
77 $usersbody = $up->getBody();
78
79 $out->addHTML( $up->getPageHeader() );
80 if ( $usersbody ) {
81 $out->addHTML(
82 $up->getNavigationBar() .
83 Html::rawElement( 'ul', [], $usersbody ) .
84 $up->getNavigationBar()
85 );
86 } else {
87 $out->addWikiMsg( 'activeusers-noresult' );
88 }
89 }
90
91 protected function getGroupName() {
92 return 'users';
93 }
94 }