mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-24 00:05:00 +00:00
Expose mw.log data on preview
People have been complaining that they can't find the log data anywhere. The new parser limit report seems a good place to show this information. Change-Id: If2abf27f7779d92ff7c7a1f32b2a54a5de521678
This commit is contained in:
parent
40b8bd2caa
commit
410229c312
|
@ -249,6 +249,46 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {
|
|||
$chunk );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data logged by modules
|
||||
* @return string Logged data
|
||||
*/
|
||||
protected function getLogBuffer() {
|
||||
if ( !$this->loaded ) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
$log = $this->getInterpreter()->callFunction( $this->mw['getLogBuffer'] );
|
||||
return $log[0];
|
||||
} catch ( ScribuntoException $ex ) {
|
||||
// Probably time expired, ignore it.
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the logged data for HTML output
|
||||
* @param string $logs Logged data
|
||||
* @param boolean $localize Whether to localize the message key
|
||||
* @return string HTML
|
||||
*/
|
||||
protected function formatHtmlLogs( $logs, $localize ) {
|
||||
$keyMsg = wfMessage( 'scribunto-limitreport-logs' );
|
||||
if ( !$localize ) {
|
||||
$keyMsg->inLanguage( 'en' )->useDatabase( false );
|
||||
}
|
||||
return Html::openElement( 'tr' ) .
|
||||
Html::rawElement( 'th', array( 'colspan' => 2 ), $keyMsg->parse() ) .
|
||||
Html::closeElement( 'tr' ) .
|
||||
Html::openElement( 'tr' ) .
|
||||
Html::openElement( 'td', array( 'colspan' => 2 ) ) .
|
||||
Html::openElement( 'div', array( 'class' => 'mw-collapsible mw-collapsed' ) ) .
|
||||
Html::element( 'pre', array( 'class' => 'scribunto-limitreport-logs' ), $logs ) .
|
||||
Html::closeElement( 'div' ) .
|
||||
Html::closeElement( 'td' ) .
|
||||
Html::closeElement( 'tr' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a library from the given file and execute it in the base environment.
|
||||
* @param string File name/path to load
|
||||
|
|
|
@ -41,6 +41,12 @@ class Scribunto_LuaSandboxEngine extends Scribunto_LuaEngine {
|
|||
$this->interpreter->getPeakMemoryUsage(),
|
||||
$this->options['memoryLimit'],
|
||||
);
|
||||
|
||||
$logs = $this->getLogBuffer();
|
||||
if ( $logs !== '' ) {
|
||||
$ret['scribunto-limitreport-logs'] = $logs;
|
||||
}
|
||||
|
||||
if ( $t < 1.0 ) {
|
||||
return $ret;
|
||||
}
|
||||
|
@ -105,12 +111,21 @@ class Scribunto_LuaSandboxEngine extends Scribunto_LuaEngine {
|
|||
foreach ( $data as $k => $v ) {
|
||||
$output->setLimitReportData( $k, $v );
|
||||
}
|
||||
if ( isset( $data['scribunto-limitreport-logs'] ) ) {
|
||||
$output->addModules( 'ext.scribunto' );
|
||||
}
|
||||
}
|
||||
|
||||
public function formatLimitData( $key, &$value, &$report, $isHTML, $localize ) {
|
||||
global $wgLang;
|
||||
$lang = $localize ? $wgLang : Language::factory( 'en' );
|
||||
switch ( $key ) {
|
||||
case 'scribunto-limitreport-logs':
|
||||
if ( $isHTML ) {
|
||||
$report .= $this->formatHtmlLogs( $value, $localize );
|
||||
}
|
||||
return false;
|
||||
|
||||
case 'scribunto-limitreport-memusage':
|
||||
$value = array_map( array( $lang, 'formatSize' ), $value );
|
||||
break;
|
||||
|
|
|
@ -67,12 +67,22 @@ class Scribunto_LuaStandaloneEngine extends Scribunto_LuaEngine {
|
|||
$output->setLimitReportData( 'scribunto-limitreport-estmemusage',
|
||||
$status['vsize'] - $this->initialStatus['vsize']
|
||||
);
|
||||
$logs = $this->getLogBuffer();
|
||||
if ( $logs !== '' ) {
|
||||
$output->addModules( 'ext.scribunto' );
|
||||
$output->setLimitReportData( 'scribunto-limitreport-logs', $logs );
|
||||
}
|
||||
}
|
||||
|
||||
function formatLimitData( $key, &$value, &$report, $isHTML, $localize ) {
|
||||
global $wgLang;
|
||||
$lang = $localize ? $wgLang : Language::factory( 'en' );
|
||||
switch ( $key ) {
|
||||
case 'scribunto-limitreport-logs':
|
||||
if ( $isHTML ) {
|
||||
$report .= $this->formatHtmlLogs( $value, $localize );
|
||||
}
|
||||
return false;
|
||||
case 'scribunto-limitreport-virtmemusage':
|
||||
$value = array_map( array( $lang, 'formatSize' ), $value );
|
||||
break;
|
||||
|
|
|
@ -61,5 +61,6 @@
|
|||
"scribunto-limitreport-memusage-value": "$1/$2",
|
||||
"scribunto-limitreport-profile": "Lua Profile",
|
||||
"scribunto-limitreport-profile-ms": "$1 ms",
|
||||
"scribunto-limitreport-profile-percent": "$1%"
|
||||
"scribunto-limitreport-profile-percent": "$1%",
|
||||
"scribunto-limitreport-logs": "Lua logs"
|
||||
}
|
||||
|
|
|
@ -69,5 +69,6 @@
|
|||
"scribunto-limitreport-memusage-value": "{{optional}}\nFormat for the \"Lua memory usage\" value in the limit report table. Parameters:\n* $1 - the usage\n* $2 - the maximum\nSee also:\n* {{msg-mw|Scribunto-limitreport-memusage}}",
|
||||
"scribunto-limitreport-profile": "Label for the \"Lua Profile\" row in the limit report table.\n\nFollowed by {{msg-mw|Scribunto-limitreport-profile-ms}} and {{msg-mw|Scribunto-limitreport-profile-percent}}.",
|
||||
"scribunto-limitreport-profile-ms": "Text to format the milliseconds in the \"Lua Profile\" table.\n\nPreceded by {{msg-mw|Scribunto-limitreport-profile}}.\n\nFollowed by {{msg-mw|Scribunto-limitreport-profile-percent}}.\n\nParameters:\n* $1 - the time in milliseconds",
|
||||
"scribunto-limitreport-profile-percent": "Text to format the time percentage in the \"Lua Profile\" table.\n\nPreceded by {{msg-mw|Scribunto-limitreport-profile}} and {{msg-mw|Scribunto-limitreport-profile-ms}}.\n\nParameters:\n* $1 - the percentage"
|
||||
"scribunto-limitreport-profile-percent": "Text to format the time percentage in the \"Lua Profile\" table.\n\nPreceded by {{msg-mw|Scribunto-limitreport-profile}} and {{msg-mw|Scribunto-limitreport-profile-ms}}.\n\nParameters:\n* $1 - the percentage",
|
||||
"scribunto-limitreport-logs": "Label for the \"Lua logs\" row in the limit report table"
|
||||
}
|
||||
|
|
|
@ -5,3 +5,8 @@
|
|||
.scribunto-error:hover, .scribunto-error:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.scribunto-limitreport-logs {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue