jenkins-bot has submitted this change and it was merged. (
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.
Bug: T128144
Change-Id: I585019be4dfeb0e2614d91dc3fb7eac0a3bd4bab
---
M Scribunto.php
M common/Common.php
M engines/LuaCommon/LuaCommon.php
M extension.json
4 files changed, 38 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Anomie: Looks good to me, approved
diff --git a/Scribunto.php b/Scribunto.php
index b08629e..79e7e6c 100644
--- a/Scribunto.php
+++ b/Scribunto.php
@@ -24,7 +24,7 @@
/**
* The name of the default script engine.
*/
-$wgScribuntoDefaultEngine = 'luastandalone';
+$wgScribuntoDefaultEngine = 'luaautodetect';
/**
* Configuration for each script engine
@@ -67,6 +67,9 @@
'allowEnvFuncs' => false,
'maxLangCacheSize' => 30,
],
+ 'luaautodetect' => [
+ 'factory' => 'Scribunto_LuaEngine::newAutodetectEngine',
+ ],
];
/**
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 102bf4a..c261b39 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: merged
Gerrit-Change-Id: I585019be4dfeb0e2614d91dc3fb7eac0a3bd4bab
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Legoktm
Gerrit-Reviewer: Anomie
Gerrit-Reviewer: Jackmcbarn
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits