Merge "Automatically detect if luasandbox is installed"

This commit is contained in:
jenkins-bot 2017-06-29 18:44:22 +00:00 committed by Gerrit Code Review
commit ae0c953f77
4 changed files with 38 additions and 4 deletions

View file

@ -24,7 +24,7 @@ if ( function_exists( 'wfLoadExtension' ) ) {
/**
* The name of the default script engine.
*/
$wgScribuntoDefaultEngine = 'luastandalone';
$wgScribuntoDefaultEngine = 'luaautodetect';
/**
* Configuration for each script engine
@ -67,6 +67,9 @@ $wgScribuntoEngineConf = [
'allowEnvFuncs' => false,
'maxLangCacheSize' => 30,
],
'luaautodetect' => [
'factory' => 'Scribunto_LuaEngine::newAutodetectEngine',
],
];
/**

View file

@ -13,8 +13,12 @@ class Scribunto {
* @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 );
}
}
/**

View file

@ -50,6 +50,30 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {
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

View file

@ -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,