Skip to content

Commit 7a2f52b

Browse files
committed
Initial version
0 parents  commit 7a2f52b

File tree

4 files changed

+440
-0
lines changed

4 files changed

+440
-0
lines changed

EnhancedReportTime.i18n.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/* EnhancedReportTime - MediaWiki extension to display enhanced information
3+
* about generation time of wiki pages.
4+
* Copyright (C) 2013 Davis Mosenkovs
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
* http://www.gnu.org/copyleft/gpl.html
20+
*/
21+
22+
$messages = array();
23+
$messages['en'] = array(
24+
'enhancedreporttime-text-host' => '<!-- Served by $4 in $1 secs. Start from $2.$3 -->',
25+
'enhancedreporttime-text-nohost' => '<!-- Served in $1 secs. Start from $2.$3 -->',
26+
'enhancedreporttime-sla-met' => 'SLA of $1 secs met.',
27+
'enhancedreporttime-sla-notmet' => 'SLA of $1 secs NOT met.',
28+
);

EnhancedReportTime.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/* EnhancedReportTime - MediaWiki extension to display enhanced information
3+
* about generation time of wiki pages.
4+
* Copyright (C) 2013 Davis Mosenkovs
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
* http://www.gnu.org/copyleft/gpl.html
20+
*/
21+
22+
if(!defined('MEDIAWIKI'))
23+
die();
24+
25+
$wgExtensionCredits[ 'other' ][] = array(
26+
'path' => __FILE__,
27+
'name' => 'EnhancedReportTime',
28+
'author' => 'Davis Mosenkovs',
29+
'url' => 'https://www.mediawiki.org/wiki/Extension:EnhancedReportTime',
30+
'description' => 'Displays enhanced information about generation time of wiki pages',
31+
'version' => '1.0.0',
32+
);
33+
34+
$wgExtensionMessagesFiles['EnhancedReportTime'] = dirname( __FILE__ ) . '/EnhancedReportTime.i18n.php';
35+
36+
$wgERTUseServerStartTime = true;
37+
$wgERTSLATime = 10;
38+
$wgERTPages = array('Special:Version');
39+
40+
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'wfEnhancedReportTimeOutputPageBeforeExec';
41+
function wfEnhancedReportTimeOutputPageBeforeExec($sk, &$tpl) {
42+
global $wgERTPages;
43+
if(count($wgERTPages)==0 || in_array($sk->getTitle()->getPrefixedText(), $wgERTPages, true)) {
44+
$tpl->set('reporttime', wfEnhancedReportTimeReport());
45+
}
46+
return true;
47+
}
48+
49+
function wfEnhancedReportTimeReport() {
50+
global $wgERTUseServerStartTime, $wgERTSLATime, $wgRequestTime, $wgShowHostnames;
51+
52+
$starttime = $wgRequestTime;
53+
$stserver = false;
54+
$slamessage = '';
55+
56+
if($wgERTUseServerStartTime && isset($_SERVER['REQUEST_TIME_FLOAT'])) {
57+
$starttime = $_SERVER['REQUEST_TIME_FLOAT'];
58+
$stserver = true;
59+
}
60+
61+
$elapsed = microtime(true) - $starttime;
62+
if($wgERTSLATime > 0) {
63+
$slamessage = ' '.wfMessage($elapsed <= $wgERTSLATime ? 'enhancedreporttime-sla-met' : 'enhancedreporttime-sla-notmet', $wgERTSLATime)->text();
64+
}
65+
66+
if($wgShowHostnames) {
67+
return wfMessage('enhancedreporttime-text-host', round($elapsed, 3), $stserver ? 'REQUEST_TIME_FLOAT' : '$wgRequestTime', $slamessage, wfHostname())->text();
68+
} else {
69+
return wfMessage('enhancedreporttime-text-nohost', round($elapsed, 3), $stserver ? 'REQUEST_TIME_FLOAT' : '$wgRequestTime', $slamessage)->text();
70+
}
71+
}

0 commit comments

Comments
 (0)