Anomie has uploaded a new change for review. https://gerrit.wikimedia.org/r/58897
Change subject: Remove mw.getLogBuffer and others from public interface ...................................................................... Remove mw.getLogBuffer and others from public interface One of the design goals of Scribunto is that each #invoke should be independent. Creative use of mw.log and mw.getLogBuffer can get around this, passing information from one #invoke to the next. This patch takes the simple solution of removing mw.getLogBuffer from modules' environments. For good measure, it also removes mw.clearLogBuffer and mw.executeModule. Some minor cleanup of the console code is also included. Change-Id: I30d73928bade4a6bdd7c00ffcd58a3858ff55698 --- M engines/LuaCommon/LuaCommon.php M engines/LuaCommon/lualib/mw.lua 2 files changed, 16 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/97/58897/1 diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php index fc38213..bd2bd6b 100644 --- a/engines/LuaCommon/LuaCommon.php +++ b/engines/LuaCommon/LuaCommon.php @@ -27,7 +27,7 @@ ); protected $loaded = false; - protected $executeModuleFunc, $interpreter; + protected $interpreter; protected $mw; protected $currentFrames = array(); protected $expandCache = array(); @@ -52,7 +52,6 @@ public function destroy() { // Break reference cycles $this->interpreter = null; - $this->executeModuleFunc = null; $this->mw = null; $this->expandCache = null; $this->loadedLibraries = null; @@ -232,8 +231,9 @@ * Maybe each console line could be evaluated as a different chunk, * apparently that's what lua.c does. */ - $code = "return function (__init)\n" . - "local p = mw.executeModule(__init)\n" . + $code = "return function (__init, exe)\n" . + "local p = exe(__init)\n" . + "__init, exe = nil, nil\n" . "local print = mw.log\n"; foreach ( $params['prevQuestions'] as $q ) { if ( substr( $q, 0, 1 ) === '=' ) { @@ -246,7 +246,8 @@ $code .= "mw.clearLogBuffer()\n"; if ( substr( $params['question'], 0, 1 ) === '=' ) { // Treat a statement starting with "=" as a return statement, like in lua.c - $code .= "return mw.allToString(" . substr( $params['question'], 1 ) . "), mw.getLogBuffer()\n"; + $code .= "local ret = mw.allToString(" . substr( $params['question'], 1 ) . ")\n" . + "return ret, mw.getLogBuffer()\n"; } else { $code .= $params['question'] . "\n" . "return nil, mw.getLogBuffer()\n"; @@ -262,9 +263,9 @@ wfMessage( 'scribunto-console-current-src' )->text() ); $consoleInit = $consoleModule->getInitChunk(); - $ret = $this->executeModule( $consoleInit ); + $ret = $this->getInterpreter()->callFunction( $this->mw['executeModule'], $consoleInit, true ); $func = $ret[0]; - $ret = $this->getInterpreter()->callFunction( $func, $contentInit ); + $ret = $this->getInterpreter()->callFunction( $func, $contentInit, $this->mw['executeModule'] ); } catch ( Exception $ex ) { $this->currentFrames = $oldFrames; throw $ex; diff --git a/engines/LuaCommon/lualib/mw.lua b/engines/LuaCommon/lualib/mw.lua index 7cc0c21..c83051c 100644 --- a/engines/LuaCommon/lualib/mw.lua +++ b/engines/LuaCommon/lualib/mw.lua @@ -133,12 +133,18 @@ -- {{#invoke}}. -- -- @param chunk The module chunk -function mw.executeModule( chunk ) +-- @param isConsole Whether this is the debug console +function mw.executeModule( chunk, isConsole ) local env = mw.clone( _G ) makePackageModule( env ) - -- This is unsafe + -- These are unsafe env.mw.makeProtectedEnvFuncs = nil + env.mw.executeModule = nil + if not isConsole then + env.mw.getLogBuffer = nil + env.mw.clearLogBuffer = nil + end if allowEnvFuncs then env.setfenv, env.getfenv = mw.makeProtectedEnvFuncs( {[_G] = true}, {} ) -- To view, visit https://gerrit.wikimedia.org/r/58897 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I30d73928bade4a6bdd7c00ffcd58a3858ff55698 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Anomie <bjor...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits