mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-24 08:14:09 +00:00
c8f4d0a213
* Removed ScriptingEngineBase::load(), inappropriate interface specification, only used by child classes and more properly defined by them * Fixed inappropriate use of final * Fixed case of a class constant to conform with MediaWiki conventions * Use a factory function interface for module creation instead of a class name accessor * Don't pass unnecessary $engine parameter to ScriptingFunctionBase::__construct(). Pass parent object as the first parameter per convention. * Fixed unnecessary reference parameter in doRunHook() * Have LuaSandboxEngineFunction::call() return the first result or null, per the base class documentation, instead of imploding. * Use strval() to avoid a warning in case call() returns an array or object * Improved some comments
64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Generic scripting functions.
|
|
*/
|
|
class Scripting {
|
|
const LOCAL = 'local';
|
|
|
|
protected static function getEngineClass() {
|
|
global $wgScriptingEngine, $wgScriptingEngines;
|
|
|
|
if( !$wgScriptingEngine ) {
|
|
throw new MWException( 'Scripting extension is enabled but $wgScriptingEngine is not set' );
|
|
}
|
|
|
|
if( !isset( $wgScriptingEngines[$wgScriptingEngine] ) ) {
|
|
throw new MWException( 'Invalid scripting engine is specified in $wgScriptingEngine' );
|
|
}
|
|
|
|
return $wgScriptingEngines[$wgScriptingEngine];
|
|
}
|
|
|
|
public static function getEngine( $parser ) {
|
|
global $wgScriptingEngineConf;
|
|
|
|
if( !isset( $parser->scripting_engine ) || !$parser->scripting_engine ) {
|
|
$class = self::getEngineClass();
|
|
$parser->scripting_engine = new $class( $parser );
|
|
$parser->scripting_engine->setOptions( $wgScriptingEngineConf );
|
|
}
|
|
return $parser->scripting_engine;
|
|
}
|
|
|
|
public static function resetEngine( $parser ) {
|
|
$parser->scripting_engine = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Exceptions which represents user-originating error in the script.
|
|
* Please do not use it for internal errors like "oh god, this should have never happened".
|
|
* Use casual MWException for that.
|
|
*/
|
|
class ScriptingException extends MWException {
|
|
function __construct( $exceptionID, $engine, $module = null, $line = null, $params = array() ) {
|
|
if( $module ) {
|
|
$codelocation = wfMsg( 'scripting-codelocation', $module, $line );
|
|
$msg = wfMsgExt( "scripting-exception-{$engine}-{$exceptionID}", array(), array_merge( array( $codelocation ), $params ) );
|
|
} else {
|
|
$msg = wfMsgExt( "scripting-exception-{$engine}-{$exceptionID}", array(), $params );
|
|
}
|
|
parent::__construct( $msg );
|
|
|
|
$this->mExceptionID = $exceptionID;
|
|
$this->mLine = $line;
|
|
$this->mModule = $module;
|
|
$this->mParams = $params;
|
|
}
|
|
|
|
public function getExceptionID() {
|
|
return $this->mExceptionID;
|
|
}
|
|
}
|