2012-01-28 16:22:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic scripting functions.
|
|
|
|
*/
|
|
|
|
class Scripting {
|
2012-04-04 06:10:32 +00:00
|
|
|
const LOCAL = 'local';
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
protected static function getEngineClass() {
|
|
|
|
global $wgScriptingEngine, $wgScriptingEngines;
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
if( !$wgScriptingEngine ) {
|
|
|
|
throw new MWException( 'Scripting extension is enabled but $wgScriptingEngine is not set' );
|
|
|
|
}
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
if( !isset( $wgScriptingEngines[$wgScriptingEngine] ) ) {
|
|
|
|
throw new MWException( 'Invalid scripting engine is specified in $wgScriptingEngine' );
|
|
|
|
}
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
return $wgScriptingEngines[$wgScriptingEngine];
|
|
|
|
}
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
public static function getEngine( $parser ) {
|
|
|
|
global $wgScriptingEngineConf;
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|