Skip to content

Commit

Permalink
Added ability to call function with extra tests
Browse files Browse the repository at this point in the history
Added ability to call function with extra tests
configurable via $wgERTTestFunction
  • Loading branch information
DavisNT committed Aug 19, 2013
1 parent 719b61c commit 1b0dd6b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions EnhancedReportTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'author' => 'Davis Mosenkovs',
'url' => 'https://www.mediawiki.org/wiki/Extension:EnhancedReportTime',
'description' => 'Displays enhanced information about generation time of wiki pages',
'version' => '1.0.0',
'version' => '1.0.1',
);

$wgExtensionMessagesFiles['EnhancedReportTime'] = dirname( __FILE__ ) . '/EnhancedReportTime.i18n.php';
Expand All @@ -40,6 +40,9 @@
// Maximum allowed generation time for which to report that SLA is met.
$wgERTSLATime = 10;

// Name of PHP function with additional tests. This function must return true on success or string with error message on failure.
$wgERTTestFunction = '';

// Array with page names (see magic word {{FULLPAGENAME}}) where to enable EnhancedReportTime (empty means everywhere).
$wgERTPages = array('Special:Version');
/*****************************/
Expand All @@ -55,25 +58,30 @@ function wfEnhancedReportTimeOutputPageBeforeExec($sk, &$tpl) {
}

function wfEnhancedReportTimeReport() {
global $wgERTUseServerStartTime, $wgERTSLATime, $wgRequestTime, $wgShowHostnames;
global $wgERTUseServerStartTime, $wgERTSLATime, $wgERTTestFunction, $wgRequestTime, $wgShowHostnames;

$starttime = $wgRequestTime;
$stserver = false;
$testresult = true;
$slamessage = '';

if($wgERTUseServerStartTime && isset($_SERVER['REQUEST_TIME_FLOAT'])) {
$starttime = $_SERVER['REQUEST_TIME_FLOAT'];
$stserver = true;
}

if($wgERTTestFunction != '') {
$testresult = $wgERTTestFunction();
}

$elapsed = microtime(true) - $starttime;
if($wgERTSLATime > 0) {
$slamessage = ' '.wfMessage($elapsed <= $wgERTSLATime ? 'enhancedreporttime-sla-met' : 'enhancedreporttime-sla-notmet', $wgERTSLATime)->text();
}

if($wgShowHostnames) {
return wfMessage('enhancedreporttime-text-host', round($elapsed, 3), $stserver ? 'REQUEST_TIME_FLOAT' : '$wgRequestTime', $slamessage, wfHostname())->text();
return wfMessage('enhancedreporttime-text-host', round($elapsed, 3), $stserver ? 'REQUEST_TIME_FLOAT' : '$wgRequestTime', $testresult===true ? $slamessage : ' '.$testresult, wfHostname())->text();
} else {
return wfMessage('enhancedreporttime-text-nohost', round($elapsed, 3), $stserver ? 'REQUEST_TIME_FLOAT' : '$wgRequestTime', $slamessage)->text();
return wfMessage('enhancedreporttime-text-nohost', round($elapsed, 3), $stserver ? 'REQUEST_TIME_FLOAT' : '$wgRequestTime', $testresult===true ? $slamessage : ' '.$testresult)->text();
}
}

0 comments on commit 1b0dd6b

Please sign in to comment.