diff --git a/EnhancedReportTime.php b/EnhancedReportTime.php index 51a68d5..350998b 100644 --- a/EnhancedReportTime.php +++ b/EnhancedReportTime.php @@ -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'; @@ -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'); /*****************************/ @@ -55,10 +58,11 @@ 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'])) { @@ -66,14 +70,18 @@ function wfEnhancedReportTimeReport() { $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(); } }