2012-01-28 16:22:18 +00:00
|
|
|
<?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();
|
|
|
|
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgExtensionCredits['parserhook']['Scribunto'] = array(
|
2012-01-28 16:22:18 +00:00
|
|
|
'path' => __FILE__,
|
2012-04-06 05:04:30 +00:00
|
|
|
'name' => 'Scribunto',
|
2012-01-28 16:22:18 +00:00
|
|
|
'author' => 'Victor Vasiliev',
|
2012-04-06 05:04:30 +00:00
|
|
|
'descriptionmsg' => 'scribunto-desc',
|
|
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:Scribunto',
|
2012-01-28 16:22:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$dir = dirname(__FILE__) . '/';
|
2012-04-06 05:04:30 +00:00
|
|
|
$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';
|
2012-01-28 16:22:18 +00:00
|
|
|
|
Added tests and fixed bugs
* Added unit tests for the two Lua interpreter classes
* Fixed a bug in checkType()
* Have Scribunto_LuaSandboxInterpreter throw an exception on construct
when the extension doesn't exist, to match the standalone behaviour.
* In Scribunto_LuaSandboxInterpreter, removed debugging statements
accidentally left in.
* Convert LuaSandboxTimeoutError to the appropriate common error
message.
* Moved the option munging from the sandbox engine to the interpreter,
so that the interpreter can be unit tested separately.
* Use /bin/sh instead of bash for lua_ulimit.sh, since dash is smaller
and still supports ulimit.
* Use exec to run the lua binary, so that the vsize of the shell doesn't
add to the memory limit.
* Added a quit function to the standalone interpreter. Unused at present.
* Don't add a comma after the last element of a table in a Lua
expression.
* Make the SIGXCPU detection work: proc_open() runs the command via a
shell, which reports signals in the child via the exit status, so
proc_get_status() will never return a valid termsig element.
* In MWServer:call(), fixed a bug causing the return values to be
wrapped in an array.
* Fixed a misunderstanding of what select() does.
* In MWServer:getStatus(), fixed indexes so that vsize will be correct.
Removed RSS, since it wasn't used anyway and turns out to be measured
in multiples of the page size, and I couldn't be bothered trying to
fetch that from getconf. Return the PID and vsize as numbers rather
than strings.
* Added a simple table dump feature to MWServer:debug().
* Fixed brackets in MWServer:tostring().
* Added missing Linux 32-bit binary.
Change-Id: Ibf5f4656b1c0a9f81287d363184c3fe9d2abdafd
2012-04-16 04:41:08 +00:00
|
|
|
$wgHooks['UnitTestsList'][] = 'ScribuntoHooks::unitTestsList';
|
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
/***** Individual engines and their configurations *****/
|
|
|
|
|
2012-04-13 10:38:12 +00:00
|
|
|
$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';
|
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
/***** Configuration *****/
|
|
|
|
|
|
|
|
/**
|
2012-04-06 05:04:30 +00:00
|
|
|
* The name of the default script engine.
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgScribuntoDefaultEngine = 'luasandbox';
|
2012-01-28 16:22:18 +00:00
|
|
|
|
2012-04-05 07:58:02 +00:00
|
|
|
/**
|
2012-04-06 05:04:30 +00:00
|
|
|
* Configuration for each script engine
|
2012-04-05 07:58:02 +00:00
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgScribuntoEngineConf = array(
|
2012-04-05 07:58:02 +00:00
|
|
|
'luasandbox' => array(
|
2012-04-13 10:38:12 +00:00
|
|
|
'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,
|
2012-04-05 07:58:02 +00:00
|
|
|
'memoryLimit' => 50 * 1024 * 1024,
|
|
|
|
'cpuLimit' => 7,
|
|
|
|
),
|
|
|
|
);
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-29 19:50:34 +00:00
|
|
|
* Script namespace numbers.
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgScribuntoNamespaceNumbers = array(
|
2012-01-29 19:50:34 +00:00
|
|
|
'Module' => 20,
|
|
|
|
'Module_talk' => 21,
|
|
|
|
);
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-06 22:14:47 +00:00
|
|
|
* Turn on to true if SyntaxHighlight_GeSHi extension is enabled.
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgScribuntoUseGeSHi = false;
|
2012-01-28 16:22:18 +00:00
|
|
|
|
2012-02-06 22:14:47 +00:00
|
|
|
/**
|
|
|
|
* Turn on to true if CodeEditor extension is enabled.
|
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgScribuntoUseCodeEditor = false;
|
2012-02-06 22:14:47 +00:00
|
|
|
|
2012-04-06 05:04:30 +00:00
|
|
|
function efDefineScribuntoNamespace() {
|
|
|
|
global $wgScribuntoNamespaceNumbers;
|
|
|
|
define( 'NS_MODULE', $wgScribuntoNamespaceNumbers['Module'] );
|
|
|
|
define( 'NS_MODULE_TALK', $wgScribuntoNamespaceNumbers['Module_talk'] );
|
2012-01-29 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-06 05:04:30 +00:00
|
|
|
$wgExtensionFunctions[] = 'efDefineScribuntoNamespace';
|