mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-24 00:05:00 +00:00
Merge "Automatically detect if luasandbox is installed"
This commit is contained in:
commit
ae0c953f77
|
@ -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',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue