More changes for extension rename

This commit is contained in:
Tim Starling 2012-04-06 05:04:30 +00:00
parent 925045a669
commit 30622e86fe
Notes: Tim Starling 2012-04-06 05:04:30 +00:00
6 changed files with 96 additions and 96 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* Internationalisation file for extension Scripting.
* Internationalisation file for extension Scribunto.
*
* @file
* @ingroup Extensions
@ -12,14 +12,14 @@ $messages = array();
* @author Victor Vasiliev
*/
$messages['en'] = array(
'scripting-desc' => 'Framework for embedding scripting languages into MediaWiki pages',
'scripting-codelocation' => 'in $1 at line $2',
'scripting-luasandbox-error' => 'Lua error: $2',
'scripting-common-toofewargs' => 'Lua error: Too few arguments to function $2',
'scripting-common-nosuchmodule' => 'Script error: No such module',
'scripting-luasandbox-noreturn' => 'Script error: The module did not return a value, it should return an export table.',
'scripting-luasandbox-toomanyreturns' => 'Script error: The module returned multiple values, it should return an export table.',
'scripting-luasandbox-notarrayreturn' => 'Script error: The module returned something other than a table, it should return an export table.',
'scripting-common-nofunction' => 'Script error: You must specify a function to call.',
'scripting-common-nosuchfunction' => 'Script error: The function you specified did not exist.',
'scribunto-desc' => 'Framework for embedding scripting languages into MediaWiki pages',
'scribunto-codelocation' => 'in $1 at line $2',
'scribunto-luasandbox-error' => 'Lua error: $2',
'scribunto-common-toofewargs' => 'Lua error: Too few arguments to function $2',
'scribunto-common-nosuchmodule' => 'Script error: No such module',
'scribunto-luasandbox-noreturn' => 'Script error: The module did not return a value, it should return an export table.',
'scribunto-luasandbox-toomanyreturns' => 'Script error: The module returned multiple values, it should return an export table.',
'scribunto-luasandbox-notarrayreturn' => 'Script error: The module returned something other than a table, it should return an export table.',
'scribunto-common-nofunction' => 'Script error: You must specify a function to call.',
'scribunto-common-nosuchfunction' => 'Script error: The function you specified did not exist.',
);

View file

@ -23,35 +23,35 @@
if( !defined( 'MEDIAWIKI' ) )
die();
$wgExtensionCredits['parserhook']['Scripting'] = array(
$wgExtensionCredits['parserhook']['Scribunto'] = array(
'path' => __FILE__,
'name' => 'Scripting',
'name' => 'Scribunto',
'author' => 'Victor Vasiliev',
'descriptionmsg' => 'scripting-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:Scripting',
'descriptionmsg' => 'scribunto-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:Scribunto',
);
$dir = dirname(__FILE__) . '/';
$wgExtensionMessagesFiles['Scripting'] = $dir . 'Scripting.i18n.php';
$wgExtensionMessagesFiles['ScriptingMagic'] = $dir . 'Scripting.magic.php';
$wgExtensionMessagesFiles['ScriptingNamespaces'] = $dir . 'Scripting.namespaces.php';
$wgExtensionMessagesFiles['Scribunto'] = $dir . 'Scribunto.i18n.php';
$wgExtensionMessagesFiles['ScribuntoMagic'] = $dir . 'Scribunto.magic.php';
$wgExtensionMessagesFiles['ScribuntoNamespaces'] = $dir . 'Scribunto.namespaces.php';
$wgAutoloadClasses['ScriptingEngineBase'] = $dir.'common/Base.php';
$wgAutoloadClasses['ScriptingModuleBase'] = $dir.'common/Base.php';
$wgAutoloadClasses['ScriptingFunctionBase'] = $dir.'common/Base.php';
$wgAutoloadClasses['ScriptingHooks'] = $dir.'common/Hooks.php';
$wgAutoloadClasses['ScriptingException'] = $dir.'common/Common.php';
$wgAutoloadClasses['Scripting'] = $dir.'common/Common.php';
$wgAutoloadClasses['ScribuntoEngineBase'] = $dir.'common/Base.php';
$wgAutoloadClasses['ScribuntoModuleBase'] = $dir.'common/Base.php';
$wgAutoloadClasses['ScribuntoFunctionBase'] = $dir.'common/Base.php';
$wgAutoloadClasses['ScribuntoHooks'] = $dir.'common/Hooks.php';
$wgAutoloadClasses['ScribuntoException'] = $dir.'common/Common.php';
$wgAutoloadClasses['Scribunto'] = $dir.'common/Common.php';
$wgHooks['ParserFirstCallInit'][] = 'ScriptingHooks::setupParserHook';
$wgHooks['ParserLimitReport'][] = 'ScriptingHooks::reportLimits';
$wgHooks['ParserClearState'][] = 'ScriptingHooks::clearState';
$wgHooks['ParserFirstCallInit'][] = 'ScribuntoHooks::setupParserHook';
$wgHooks['ParserLimitReport'][] = 'ScribuntoHooks::reportLimits';
$wgHooks['ParserClearState'][] = 'ScribuntoHooks::clearState';
$wgHooks['CanonicalNamespaces'][] = 'ScriptingHooks::addCanonicalNamespaces';
$wgHooks['ArticleViewCustom'][] = 'ScriptingHooks::handleScriptView';
$wgHooks['TitleIsWikitextPage'][] = 'ScriptingHooks::isWikitextPage';
$wgHooks['CodeEditorGetPageLanguage'][] = 'ScriptingHooks::getCodeLanguage';
$wgHooks['EditFilter'][] = 'ScriptingHooks::validateScript';
$wgHooks['CanonicalNamespaces'][] = 'ScribuntoHooks::addCanonicalNamespaces';
$wgHooks['ArticleViewCustom'][] = 'ScribuntoHooks::handleScriptView';
$wgHooks['TitleIsWikitextPage'][] = 'ScribuntoHooks::isWikitextPage';
$wgHooks['CodeEditorGetPageLanguage'][] = 'ScribuntoHooks::getCodeLanguage';
$wgHooks['EditFilter'][] = 'ScribuntoHooks::validateScript';
/***** Individual engines and their configurations *****/
@ -60,14 +60,14 @@ $wgAutoloadClasses['LuaSandboxEngine'] = $dir.'engines/LuaSandbox/Engine.php';
/***** Configuration *****/
/**
* The name of the default scripting engine.
* The name of the default script engine.
*/
$wgScriptingDefaultEngine = 'luasandbox';
$wgScribuntoDefaultEngine = 'luasandbox';
/**
* Configuration for each scripting engine
* Configuration for each script engine
*/
$wgScriptingEngineConf = array(
$wgScribuntoEngineConf = array(
'luasandbox' => array(
'class' => 'LuaSandboxEngine',
'memoryLimit' => 50 * 1024 * 1024,
@ -78,7 +78,7 @@ $wgScriptingEngineConf = array(
/**
* Script namespace numbers.
*/
$wgScriptingNamespaceNumbers = array(
$wgScribuntoNamespaceNumbers = array(
'Module' => 20,
'Module_talk' => 21,
);
@ -86,17 +86,17 @@ $wgScriptingNamespaceNumbers = array(
/**
* Turn on to true if SyntaxHighlight_GeSHi extension is enabled.
*/
$wgScriptingUseGeSHi = false;
$wgScribuntoUseGeSHi = false;
/**
* Turn on to true if CodeEditor extension is enabled.
*/
$wgScriptingUseCodeEditor = false;
$wgScribuntoUseCodeEditor = false;
function efDefineScriptingNamespace() {
global $wgScriptingNamespaceNumbers;
define( 'NS_MODULE', $wgScriptingNamespaceNumbers['Module'] );
define( 'NS_MODULE_TALK', $wgScriptingNamespaceNumbers['Module_talk'] );
function efDefineScribuntoNamespace() {
global $wgScribuntoNamespaceNumbers;
define( 'NS_MODULE', $wgScribuntoNamespaceNumbers['Module'] );
define( 'NS_MODULE_TALK', $wgScribuntoNamespaceNumbers['Module_talk'] );
}
$wgExtensionFunctions[] = 'efDefineScriptingNamespace';
$wgExtensionFunctions[] = 'efDefineScribuntoNamespace';

View file

@ -22,11 +22,11 @@
*/
/**
* Base class for all scripting engines. Includes all code
* Base class for all script engines. Includes all code
* not related to particular modules, like tracking links between
* modules or loading module texts.
*/
abstract class ScriptingEngineBase {
abstract class ScribuntoEngineBase {
protected
$parser,
$options,
@ -58,12 +58,12 @@ abstract class ScriptingEngineBase {
* text is garbage or has syntax error. Returns a module or throws an exception.
*
* @param $title The title of the module
* @return ScriptingEngineModule
* @return ScribuntoEngineModule
*/
function fetchModuleFromParser( Title $title ) {
list( $text, $finalTitle ) = $this->parser->fetchTemplateAndTitle( $title );
if ( $text === false ) {
throw new ScriptingException( 'scripting-common-nosuchmodule' );
throw new ScribuntoException( 'scribunto-common-nosuchmodule' );
}
$key = $finalTitle->getPrefixedDBkey();
@ -86,7 +86,7 @@ abstract class ScriptingEngineBase {
try {
$module->initialize();
} catch( ScriptingException $e ) {
} catch( ScribuntoException $e ) {
return array( $e->getMessage() );
}
@ -121,7 +121,7 @@ abstract class ScriptingEngineBase {
* Class that represents a module. Responsible for initial module parsing
* and maintaining the contents of the module.
*/
abstract class ScriptingModuleBase {
abstract class ScribuntoModuleBase {
var $engine, $code, $chunkName;
public function __construct( $engine, $code, $chunkName ) {
@ -146,7 +146,7 @@ abstract class ScriptingModuleBase {
/**
* Returns the object for a given function. Should return null if it does not exist.
*
* @return ScriptingFunctionBase or null
* @return ScribuntoFunctionBase or null
*/
abstract function getFunction( $name );
@ -158,7 +158,7 @@ abstract class ScriptingModuleBase {
abstract function getFunctions();
}
abstract class ScriptingFunctionBase {
abstract class ScribuntoFunctionBase {
protected $mName, $mContents, $mModule, $mEngine;
public function __construct( $module, $name, $contents ) {

View file

@ -1,9 +1,9 @@
<?php
/**
* Generic scripting functions.
* Static function collection for general extension support.
*/
class Scripting {
class Scribunto {
const LOCAL = 'local';
/**
@ -19,15 +19,15 @@ class Scripting {
* @param $extraOptions Extra options to pass to the constructor, in addition to the configured options
*/
public static function newDefaultEngine( $extraOptions = array() ) {
global $wgScriptingDefaultEngine, $wgScriptingEngineConf;
if( !$wgScriptingDefaultEngine ) {
throw new MWException( 'Scripting extension is enabled but $wgScriptingDefaultEngine is not set' );
global $wgScribuntoDefaultEngine, $wgScribuntoEngineConf;
if( !$wgScribuntoDefaultEngine ) {
throw new MWException( 'Scribunto extension is enabled but $wgScribuntoDefaultEngine is not set' );
}
if( !isset( $wgScriptingEngineConf[$wgScriptingDefaultEngine] ) ) {
throw new MWException( 'Invalid scripting engine is specified in $wgScriptingDefaultEngine' );
if( !isset( $wgScribuntoEngineConf[$wgScribuntoDefaultEngine] ) ) {
throw new MWException( 'Invalid scripting engine is specified in $wgScribuntoDefaultEngine' );
}
$options = $extraOptions + $wgScriptingEngineConf[$wgScriptingDefaultEngine];
$options = $extraOptions + $wgScribuntoEngineConf[$wgScribuntoDefaultEngine];
return self::newEngine( $options );
}
@ -39,17 +39,17 @@ class Scripting {
* @param Parser $parser
*/
public static function getParserEngine( $parser ) {
if( !isset( $parser->scripting_engine ) || !$parser->scripting_engine ) {
$parser->scripting_engine = self::newDefaultEngine( array( 'parser' => $parser ) );
if( !isset( $parser->scribunto_engine ) || !$parser->scribunto_engine ) {
$parser->scribunto_engine = self::newDefaultEngine( array( 'parser' => $parser ) );
}
return $parser->scripting_engine;
return $parser->scribunto_engine;
}
/**
* Remove the current engine instance from the parser
*/
public static function resetParserEngine( $parser ) {
$parser->scripting_engine = null;
$parser->scribunto_engine = null;
}
}
@ -57,7 +57,7 @@ class Scripting {
* An exception class which represents an error in the script. This does not
* normally abort the request, instead it is caught and shown to the user.
*/
class ScriptingException extends MWException {
class ScribuntoException extends MWException {
var $messageName, $params;
function __construct( $messageName, $params = array() ) {
@ -67,7 +67,7 @@ class ScriptingException extends MWException {
$args = array();
}
if ( isset( $params['module'] ) && isset( $params['line'] ) ) {
$codelocation = wfMsg( 'scripting-codelocation', $params['module'], $params['line'] );
$codelocation = wfMsg( 'scribunto-codelocation', $params['module'], $params['line'] );
} else {
$codelocation = '[UNKNOWN]'; // should never happen
}

View file

@ -21,16 +21,16 @@
*/
/**
* Hooks for the Scripting extension.
* Hooks for the Scribunto extension.
*/
class ScriptingHooks {
class ScribuntoHooks {
/**
* Register parser hooks.
* @param $parser Parser
*/
public static function setupParserHook( &$parser ) {
$parser->setFunctionHook( 'invoke', 'ScriptingHooks::callHook', SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'script', 'ScriptingHooks::transcludeHook', SFH_NO_HASH | SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'invoke', 'ScribuntoHooks::callHook', SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'script', 'ScribuntoHooks::transcludeHook', SFH_NO_HASH | SFH_OBJECT_ARGS );
return true;
}
@ -42,7 +42,7 @@ class ScriptingHooks {
* @return bool
*/
public static function clearState( &$parser ) {
Scripting::resetParserEngine( $parser );
Scribunto::resetParserEngine( $parser );
return true;
}
@ -56,7 +56,7 @@ class ScriptingHooks {
*/
public static function callHook( &$parser, $frame, $args ) {
if( count( $args ) < 2 ) {
throw new ScriptingException( 'scripting-common-nofunction' );
throw new ScribuntoException( 'scribunto-common-nofunction' );
}
$module = $parser->mStripState->unstripBoth( array_shift( $args ) );
@ -84,22 +84,22 @@ class ScriptingHooks {
* @param $functionName
* @param $args
* @return string
* @throws ScriptingException
* @throws ScribuntoException
*/
private static function doRunHook( $parser, $frame, $moduleName, $functionName, $args ) {
wfProfileIn( __METHOD__ );
try {
$engine = Scripting::getParserEngine( $parser );
$engine = Scribunto::getParserEngine( $parser );
$title = Title::makeTitleSafe( NS_MODULE, $moduleName );
if ( !$title ) {
throw new ScriptingException( 'scripting-common-nosuchmodule' );
throw new ScribuntoException( 'scribunto-common-nosuchmodule' );
}
$module = $engine->fetchModuleFromParser( $title );
$functionObj = $module->getFunction( $functionName );
if( !$functionObj ) {
throw new ScriptingException( 'scripting-common-nosuchfunction' );
throw new ScribuntoException( 'scribunto-common-nosuchfunction' );
}
foreach( $args as &$arg ) {
@ -110,7 +110,7 @@ class ScriptingHooks {
wfProfileOut( __METHOD__ );
return trim( strval( $result ) );
} catch( ScriptingException $e ) {
} catch( ScribuntoException $e ) {
$msg = $e->getMessage();
wfProfileOut( __METHOD__ );
return "<strong class=\"error\">{$msg}</strong>";
@ -127,13 +127,13 @@ class ScriptingHooks {
* @return bool
*/
public static function handleScriptView( $text, $title, $output ) {
global $wgScriptingUseGeSHi;
global $wgScribuntoUseGeSHi;
if( $title->getNamespace() == NS_MODULE ) {
$engine = Scripting::newDefaultEngine();
$engine = Scribunto::newDefaultEngine();
$language = $engine->getGeSHiLanguage();
if( $wgScriptingUseGeSHi && $language ) {
if( $wgScribuntoUseGeSHi && $language ) {
$geshi = SyntaxHighlight_GeSHi::prepare( $text, $language );
$geshi->set_language( $language );
if( $geshi instanceof GeSHi && !$geshi->error() ) {
@ -157,9 +157,9 @@ class ScriptingHooks {
}
public static function getCodeLanguage( $title, &$lang ) {
global $wgScriptingUseCodeEditor;
if( $wgScriptingUseCodeEditor && $title->getNamespace() == NS_MODULE ) {
$engine = Scripting::newDefaultEngine();
global $wgScribuntoUseCodeEditor;
if( $wgScribuntoUseCodeEditor && $title->getNamespace() == NS_MODULE ) {
$engine = Scribunto::newDefaultEngine();
if( $engine->getCodeEditorLanguage() ) {
$lang = $engine->getCodeEditorLanguage();
return false;
@ -193,7 +193,7 @@ class ScriptingHooks {
public static function reportLimits( $parser, &$report ) {
# FIXME
global $wgScriptsLimits;
$engine = Scripting::getParserEngine( $parser );
$engine = Scribunto::getParserEngine( $parser );
$report .= $engine->getLimitReport();
return true;
}
@ -212,13 +212,13 @@ class ScriptingHooks {
$title = $editor->mTitle;
if( $title->getNamespace() == NS_MODULE ) {
$engine = Scripting::newDefaultEngine();
$engine = Scribunto::newDefaultEngine();
$errors = $engine->validate( $text, $title->getPrefixedDBkey() );
if( !$errors ) {
return true;
}
$errmsg = wfMsgExt( 'scripting-error', array( 'parsemag' ), array( count( $errors ) ) );
$errmsg = wfMsgExt( 'scribunto-error', array( 'parsemag' ), array( count( $errors ) ) );
if( count( $errors ) == 1 ) {
$errlines = ': ' . wfEscapeWikiText( $errors[0] );
} else {

View file

@ -1,6 +1,6 @@
<?php
class LuaSandboxEngine extends ScriptingEngineBase {
class LuaSandboxEngine extends ScribuntoEngineBase {
public $sandbox, $options, $loaded = false;
public function newModule( $text, $chunkName ) {
@ -55,20 +55,20 @@ class LuaSandboxEngine extends ScriptingEngineBase {
$args = func_get_args();
if( count( $args ) < 1 ) {
// FIXME: LuaSandbox PHP extension should provide proper context
throw new ScriptingException( 'scripting-common-toofewargs',
throw new ScribuntoException( 'scribunto-common-toofewargs',
array( 'args' => array( 'mw.import' ) ) );
}
$title = Title::makeTitleSafe( NS_MODULE, $args[0] );
if ( !$title ) {
throw new ScriptingException( 'scripting-common-nosuchmodule' );
throw new ScribuntoException( 'scribunto-common-nosuchmodule' );
}
$module = $this->fetchModuleFromParser( $title );
return $module->getContents();
}
}
class LuaSandboxEngineModule extends ScriptingModuleBase {
class LuaSandboxEngineModule extends ScribuntoModuleBase {
protected $initialized;
function initialize() {
@ -86,18 +86,18 @@ class LuaSandboxEngineModule extends ScriptingModuleBase {
'@' . $this->chunkName );
$output = $this->body->call();
} catch( LuaSandboxError $e ) {
throw new ScriptingException( 'scripting-luasandbox-error',
throw new ScribuntoException( 'scribunto-luasandbox-error',
array( 'args' => array( $e->getMessage() ) ) );
}
if( !$output ) {
throw new ScriptingException( 'scripting-luasandbox-noreturn' );
throw new ScribuntoException( 'scribunto-luasandbox-noreturn' );
}
if( count( $output ) > 2 ) {
throw new ScriptingException( 'scripting-luasandbox-toomanyreturns' );
throw new ScribuntoException( 'scribunto-luasandbox-toomanyreturns' );
}
if( !is_array( $output[0] ) ) {
throw new ScriptingException( 'scripting-luasandbox-notarrayreturn' );
throw new ScribuntoException( 'scribunto-luasandbox-notarrayreturn' );
}
$this->contents = $output[0];
@ -131,12 +131,12 @@ class LuaSandboxEngineModule extends ScriptingModuleBase {
}
}
class LuaSandboxEngineFunction extends ScriptingFunctionBase {
class LuaSandboxEngineFunction extends ScribuntoFunctionBase {
public function call( $args, $frame ) {
try {
$result = call_user_func_array( array( $this->contents, 'call' ), $args );
} catch( LuaSandboxError $e ) {
throw new ScriptingException( 'scripting-luasandbox-error',
throw new ScribuntoException( 'scribunto-luasandbox-error',
array( 'args' => array( $e->getMessage() ) ) );
}