From 410229c312a70c6311e7427a9c45a9465fc5eb1f Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 25 Mar 2013 11:56:38 -0400 Subject: [PATCH] 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 --- engines/LuaCommon/LuaCommon.php | 40 +++++++++++++++++++ engines/LuaSandbox/Engine.php | 15 +++++++ engines/LuaStandalone/LuaStandaloneEngine.php | 10 +++++ i18n/en.json | 3 +- i18n/qqq.json | 3 +- modules/ext.scribunto.css | 5 +++ 6 files changed, 74 insertions(+), 2 deletions(-) diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php index 9be1ef04..80a18369 100644 --- a/engines/LuaCommon/LuaCommon.php +++ b/engines/LuaCommon/LuaCommon.php @@ -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 diff --git a/engines/LuaSandbox/Engine.php b/engines/LuaSandbox/Engine.php index 1d6cda00..85ecdb71 100644 --- a/engines/LuaSandbox/Engine.php +++ b/engines/LuaSandbox/Engine.php @@ -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; diff --git a/engines/LuaStandalone/LuaStandaloneEngine.php b/engines/LuaStandalone/LuaStandaloneEngine.php index 30509bb2..f0423abd 100644 --- a/engines/LuaStandalone/LuaStandaloneEngine.php +++ b/engines/LuaStandalone/LuaStandaloneEngine.php @@ -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; diff --git a/i18n/en.json b/i18n/en.json index c4a8ffeb..ccd2ee6f 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -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" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 68b4dcbc..916ffcbc 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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" } diff --git a/modules/ext.scribunto.css b/modules/ext.scribunto.css index 184691a9..ee3dada5 100644 --- a/modules/ext.scribunto.css +++ b/modules/ext.scribunto.css @@ -5,3 +5,8 @@ .scribunto-error:hover, .scribunto-error:focus { text-decoration: underline; } + +.scribunto-limitreport-logs { + margin: 0; + white-space: pre-wrap; +}