mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-09-24 02:39:48 +00:00
54cedd69b8
* Introduced a Lua implementation based on shelling out to a standard Lua binary. * Bundled several Lua binaries for common platforms. I haven't added a 32-bit Linux binary yet, but that will come. * Refactored the existing Lua class, bringing out functionality common to all Lua implementations into a set of common base classes. * Moved the bulk of the implementation-specific functionality into a set of "interpreter" classes. * Renamed LuaSandboxEngine to Scribunto_LuaSandboxEngine * Don't create an engine object unconditionally when the ParserLimitReport hook is called. * Implemented isolation of module global variable namespaces. This means that separate {{#invoke}} calls can't pass data to each other -- this was a desired feature in planning since it allows more flexibility in wikitext parser design. Isolation for mw.import() means that modules cannot accidentally create global variables which affect other modules -- exports are solely via the return value. Change-Id: I3fa35651fe5b1fbfd85adeadc220b1ea31cd6f0b
124 lines
4.6 KiB
PHP
124 lines
4.6 KiB
PHP
<?php
|
|
/**
|
|
* Wikitext scripting infrastructure for MediaWiki.
|
|
* Copyright (C) 2009-2012 Victor Vasiliev <vasilvv@gmail.com>
|
|
* http://www.mediawiki.org/
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*/
|
|
|
|
if( !defined( 'MEDIAWIKI' ) )
|
|
die();
|
|
|
|
$wgExtensionCredits['parserhook']['Scribunto'] = array(
|
|
'path' => __FILE__,
|
|
'name' => 'Scribunto',
|
|
'author' => 'Victor Vasiliev',
|
|
'descriptionmsg' => 'scribunto-desc',
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:Scribunto',
|
|
);
|
|
|
|
$dir = dirname(__FILE__) . '/';
|
|
$wgExtensionMessagesFiles['Scribunto'] = $dir . 'Scribunto.i18n.php';
|
|
$wgExtensionMessagesFiles['ScribuntoMagic'] = $dir . 'Scribunto.magic.php';
|
|
$wgExtensionMessagesFiles['ScribuntoNamespaces'] = $dir . 'Scribunto.namespaces.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'][] = 'ScribuntoHooks::setupParserHook';
|
|
$wgHooks['ParserLimitReport'][] = 'ScribuntoHooks::reportLimits';
|
|
$wgHooks['ParserClearState'][] = 'ScribuntoHooks::clearState';
|
|
|
|
$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 *****/
|
|
|
|
$wgAutoloadClasses['Scribunto_LuaEngine'] = $dir.'engines/LuaCommon/LuaCommon.php';
|
|
$wgAutoloadClasses['Scribunto_LuaModule'] = $dir.'engines/LuaCommon/LuaCommon.php';
|
|
$wgAutoloadClasses['Scribunto_LuaFunction'] = $dir.'engines/LuaCommon/LuaCommon.php';
|
|
$wgAutoloadClasses['Scribunto_LuaInterpreter'] = $dir.'engines/LuaCommon/LuaInterpreter.php';
|
|
$wgAutoloadClasses['Scribunto_LuaSandboxEngine'] = $dir.'engines/LuaSandbox/Engine.php';
|
|
$wgAutoloadClasses['Scribunto_LuaStandaloneEngine'] = $dir.'engines/LuaStandalone/LuaStandaloneEngine.php';
|
|
$wgAutoloadClasses['Scribunto_LuaStandaloneInterpreter'] = $dir.'engines/LuaStandalone/LuaStandaloneEngine.php';
|
|
$wgAutoloadClasses['Scribunto_LuaStandaloneInterpreterFunction'] = $dir.'engines/LuaStandalone/LuaStandaloneEngine.php';
|
|
|
|
|
|
/***** Configuration *****/
|
|
|
|
/**
|
|
* The name of the default script engine.
|
|
*/
|
|
$wgScribuntoDefaultEngine = 'luasandbox';
|
|
|
|
/**
|
|
* Configuration for each script engine
|
|
*/
|
|
$wgScribuntoEngineConf = array(
|
|
'luasandbox' => array(
|
|
'class' => 'Scribunto_LuaSandboxEngine',
|
|
'memoryLimit' => 50 * 1024 * 1024,
|
|
'cpuLimit' => 7,
|
|
),
|
|
'luastandalone' => array(
|
|
'class' => 'Scribunto_LuaStandaloneEngine',
|
|
|
|
// A filename to act as the destination for stderr from the Lua
|
|
// binary. This may provide useful error information if Lua fails to
|
|
// run. Set this to null to discard stderr output.
|
|
'errorFile' => null,
|
|
|
|
// The location of the Lua binary, or null to use the bundled binary.
|
|
'luaPath' => null,
|
|
'memoryLimit' => 50 * 1024 * 1024,
|
|
'cpuLimit' => 7,
|
|
),
|
|
);
|
|
|
|
/**
|
|
* Script namespace numbers.
|
|
*/
|
|
$wgScribuntoNamespaceNumbers = array(
|
|
'Module' => 20,
|
|
'Module_talk' => 21,
|
|
);
|
|
|
|
/**
|
|
* Turn on to true if SyntaxHighlight_GeSHi extension is enabled.
|
|
*/
|
|
$wgScribuntoUseGeSHi = false;
|
|
|
|
/**
|
|
* Turn on to true if CodeEditor extension is enabled.
|
|
*/
|
|
$wgScribuntoUseCodeEditor = false;
|
|
|
|
function efDefineScribuntoNamespace() {
|
|
global $wgScribuntoNamespaceNumbers;
|
|
define( 'NS_MODULE', $wgScribuntoNamespaceNumbers['Module'] );
|
|
define( 'NS_MODULE_TALK', $wgScribuntoNamespaceNumbers['Module_talk'] );
|
|
}
|
|
|
|
$wgExtensionFunctions[] = 'efDefineScribuntoNamespace';
|