Legoktm has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/361273 )
Change subject: Automatically detect if luasandbox is installed ...................................................................... Automatically detect if luasandbox is installed This makes it easier for people to use luasandbox and brings it in line with how we currently take advantage of other PHP extensions if they're available (e.g. wikidiff2). People can still explicitly use luastandalone if they want to. Change-Id: I585019be4dfeb0e2614d91dc3fb7eac0a3bd4bab --- M common/Common.php M engines/LuaCommon/LuaCommon.php M extension.json 3 files changed, 34 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/73/361273/1 diff --git a/common/Common.php b/common/Common.php index 5511cb6..c6f089e 100644 --- a/common/Common.php +++ b/common/Common.php @@ -13,8 +13,12 @@ * @return ScribuntoEngineBase */ public static function newEngine( $options ) { - $class = $options['class']; - return new $class( $options ); + if ( isset( $options['factory'] ) ) { + return call_user_func( $options['factory'], $options ); + } else { + $class = $options['class']; + return new $class( $options ); + } } /** diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php index 345e9c4..b544def 100644 --- a/engines/LuaCommon/LuaCommon.php +++ b/engines/LuaCommon/LuaCommon.php @@ -51,6 +51,30 @@ const MAX_EXPAND_CACHE_SIZE = 100; /** + * If luasandbox is installed and usable then use it, + * otherwise + * + * @param array $options + * @return Scribunto_LuaEngine + */ + public static function newAutodetectEngine( array $options ) { + global $wgScribuntoEngineConf; + $engine = 'luastandalone'; + try { + Scribunto_LuaSandboxInterpreter::checkLuaSandboxVersion(); + $engine = 'luasandbox'; + } catch ( Scribunto_LuaInterpreterNotFoundError $e ) { + // pass + } catch ( Scribunto_LuaInterpreterBadVersionError $e ) { + // pass + } + + unset( $options['factory'] ); + + return Scribunto::newEngine( $options + $wgScribuntoEngineConf[$engine] ); + } + + /** * Create a new interpreter object * @return Scribunto_LuaInterpreter */ diff --git a/extension.json b/extension.json index f807954..edac38d 100644 --- a/extension.json +++ b/extension.json @@ -136,7 +136,7 @@ ], "callback": "ScribuntoHooks::onRegistration", "config": { - "ScribuntoDefaultEngine": "luastandalone", + "ScribuntoDefaultEngine": "luaautodetect", "ScribuntoEngineConf": { "luasandbox": { "class": "Scribunto_LuaSandboxEngine", @@ -155,6 +155,9 @@ "allowEnvFuncs": false, "maxLangCacheSize": 30 }, + "luaautodetect": { + "factory": "Scribunto_LuaEngine::newAutodetectEngine" + }, "_merge_strategy": "array_plus_2d" }, "ScribuntoUseGeSHi": false, -- To view, visit https://gerrit.wikimedia.org/r/361273 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I585019be4dfeb0e2614d91dc3fb7eac0a3bd4bab Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Legoktm <lego...@member.fsf.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits