2012-01-28 16:22:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wikitext scripting infrastructure for MediaWiki: base classes.
|
|
|
|
* Copyright (C) 2012 Victor Vasiliev <vasilvv@gmail.com> et al
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-04-06 05:04:30 +00:00
|
|
|
* Base class for all script engines. Includes all code
|
2012-01-28 16:22:18 +00:00
|
|
|
* not related to particular modules, like tracking links between
|
|
|
|
* modules or loading module texts.
|
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
abstract class ScribuntoEngineBase {
|
2014-10-10 09:02:03 +00:00
|
|
|
/**
|
|
|
|
* @var Title
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
protected $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $options;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ScribuntoModuleBase[]
|
|
|
|
*/
|
|
|
|
protected $modules = array();
|
2012-01-28 16:22:18 +00:00
|
|
|
|
2014-06-18 17:17:04 +00:00
|
|
|
/**
|
|
|
|
* @var Parser
|
|
|
|
*/
|
|
|
|
protected $parser;
|
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
/**
|
2012-04-04 06:10:32 +00:00
|
|
|
* Creates a new module object within this engine
|
2014-10-09 19:49:40 +00:00
|
|
|
*
|
|
|
|
* @param string $text
|
2014-10-10 09:02:03 +00:00
|
|
|
* @param string|bool $chunkName
|
2014-06-18 17:17:04 +00:00
|
|
|
* @return ScribuntoModuleBase
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-05 07:58:02 +00:00
|
|
|
abstract protected function newModule( $text, $chunkName );
|
2012-01-28 16:22:18 +00:00
|
|
|
|
2012-07-14 04:23:42 +00:00
|
|
|
/**
|
|
|
|
* Run an interactive console request
|
|
|
|
*
|
2014-06-18 17:17:04 +00:00
|
|
|
* @param array $params Associative array. Options are:
|
2012-07-14 04:23:42 +00:00
|
|
|
* - title: The title object for the module being debugged
|
|
|
|
* - content: The text content of the module
|
2013-01-25 17:53:18 +00:00
|
|
|
* - prevQuestions: An array of previous "questions" used to establish the state
|
2012-07-14 04:23:42 +00:00
|
|
|
* - question: The current "question", a string script
|
|
|
|
*
|
|
|
|
* @return array containing:
|
|
|
|
* - print: The resulting print buffer
|
|
|
|
* - return: The resulting return value
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
abstract function runConsole( array $params );
|
2012-07-14 04:23:42 +00:00
|
|
|
|
2013-03-20 16:30:26 +00:00
|
|
|
/**
|
|
|
|
* Get software information for Special:Version
|
|
|
|
* @param &$software array
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
abstract public function getSoftwareInfo( array &$software );
|
2013-03-20 16:30:26 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
/**
|
2012-06-15 23:34:35 +00:00
|
|
|
* @param $options array Associative array of options:
|
2012-04-05 07:58:02 +00:00
|
|
|
* - parser: A Parser object
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
public function __construct( array $options ) {
|
2012-04-05 07:58:02 +00:00
|
|
|
$this->options = $options;
|
|
|
|
if ( isset( $options['parser'] ) ) {
|
|
|
|
$this->parser = $options['parser'];
|
|
|
|
}
|
2012-04-23 11:36:13 +00:00
|
|
|
if ( isset( $options['title'] ) ) {
|
|
|
|
$this->title = $options['title'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 11:43:44 +00:00
|
|
|
public function __destruct() {
|
2012-09-05 09:39:58 +00:00
|
|
|
$this->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy() {
|
|
|
|
// Break reference cycles
|
|
|
|
$this->parser = null;
|
|
|
|
$this->title = null;
|
|
|
|
$this->modules = null;
|
|
|
|
}
|
|
|
|
|
2014-06-18 17:17:04 +00:00
|
|
|
/**
|
|
|
|
* @param Title $title
|
|
|
|
*/
|
2012-04-23 11:36:13 +00:00
|
|
|
public function setTitle( $title ) {
|
|
|
|
$this->title = $title;
|
|
|
|
}
|
|
|
|
|
2014-06-18 17:17:04 +00:00
|
|
|
/**
|
|
|
|
* @return Title
|
|
|
|
*/
|
2012-04-23 11:36:13 +00:00
|
|
|
public function getTitle() {
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
2012-06-15 23:34:35 +00:00
|
|
|
/**
|
2014-10-09 19:49:40 +00:00
|
|
|
* @param string $message
|
2012-06-15 23:34:35 +00:00
|
|
|
* @param $params array
|
|
|
|
* @return ScribuntoException
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
public function newException( $message, array $params = array() ) {
|
2012-04-23 11:36:13 +00:00
|
|
|
return new ScribuntoException( $message, $this->getDefaultExceptionParams() + $params );
|
|
|
|
}
|
|
|
|
|
2012-06-15 23:34:35 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-04-23 11:36:13 +00:00
|
|
|
public function getDefaultExceptionParams() {
|
|
|
|
$params = array();
|
|
|
|
if ( $this->title ) {
|
|
|
|
$params['title'] = $this->title;
|
|
|
|
}
|
|
|
|
return $params;
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-07 18:46:59 +00:00
|
|
|
* Load a module from some parser-defined template loading mechanism and
|
2012-04-05 07:58:02 +00:00
|
|
|
* register a parser output dependency.
|
|
|
|
*
|
2012-01-28 16:22:18 +00:00
|
|
|
* Does not initialize the module, i.e. do not expect it to complain if the module
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* text is garbage or has syntax error. Returns a module or null if it doesn't exist.
|
2012-04-05 07:58:02 +00:00
|
|
|
*
|
2014-06-18 17:17:04 +00:00
|
|
|
* @param Title $title The title of the module
|
|
|
|
* @return ScribuntoEngineBase|null
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-05 07:58:02 +00:00
|
|
|
function fetchModuleFromParser( Title $title ) {
|
2013-03-18 01:21:14 +00:00
|
|
|
$key = $title->getPrefixedDBkey();
|
|
|
|
if ( !array_key_exists( $key, $this->modules ) ) {
|
|
|
|
list( $text, $finalTitle ) = $this->parser->fetchTemplateAndTitle( $title );
|
|
|
|
if ( $text === false ) {
|
|
|
|
$this->modules[$key] = null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$finalKey = $finalTitle->getPrefixedDBkey();
|
|
|
|
if ( !isset( $this->modules[$finalKey] ) ) {
|
|
|
|
$this->modules[$finalKey] = $this->newModule( $text, $finalKey );
|
|
|
|
}
|
|
|
|
// Almost certainly $key === $finalKey, but just in case...
|
|
|
|
$this->modules[$key] = $this->modules[$finalKey];
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
2012-04-05 03:53:05 +00:00
|
|
|
return $this->modules[$key];
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-07 18:46:59 +00:00
|
|
|
* Validates the script and returns a Status object containing the syntax
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* errors for the given code.
|
2014-07-07 18:46:59 +00:00
|
|
|
*
|
2012-06-15 23:34:35 +00:00
|
|
|
* @param $text string
|
2014-10-10 09:02:03 +00:00
|
|
|
* @param string|bool $chunkName
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* @return Status
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-05 07:58:02 +00:00
|
|
|
function validate( $text, $chunkName = false ) {
|
|
|
|
$module = $this->newModule( $text, $chunkName );
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
return $module->validate();
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows the engine to append their information to the limits
|
|
|
|
* report.
|
|
|
|
*/
|
|
|
|
public function getLimitsReport() {
|
|
|
|
/* No-op by default */
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-06 22:14:47 +00:00
|
|
|
* Get the language for GeSHi syntax highlighter.
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-05 07:58:02 +00:00
|
|
|
function getGeSHiLanguage() {
|
2012-01-28 16:22:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-07 18:46:59 +00:00
|
|
|
|
2012-02-06 22:14:47 +00:00
|
|
|
/**
|
2012-04-05 07:58:02 +00:00
|
|
|
* Get the language for Ace code editor.
|
2012-02-06 22:14:47 +00:00
|
|
|
*/
|
|
|
|
function getCodeEditorLanguage() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-19 07:40:56 +00:00
|
|
|
|
2014-06-18 17:17:04 +00:00
|
|
|
/**
|
|
|
|
* @return Parser
|
|
|
|
*/
|
2012-04-19 07:40:56 +00:00
|
|
|
public function getParser() {
|
|
|
|
return $this->parser;
|
|
|
|
}
|
2013-02-14 17:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a list of all libraries supported by this engine
|
|
|
|
*
|
2014-09-26 18:11:21 +00:00
|
|
|
* The return value is an array with keys being the library name seen by
|
|
|
|
* the module and values being either a PHP class name or an array with the
|
|
|
|
* following elements:
|
|
|
|
* - class: (string) Class to load (required)
|
|
|
|
* - deferLoad: (bool) Library should not be loaded at startup; modules
|
|
|
|
* needing the library must request it (e.g. via 'require' in Lua)
|
|
|
|
*
|
2013-02-14 17:38:03 +00:00
|
|
|
* @param $engine String script engine we're using (eg: lua)
|
|
|
|
* @param $coreLibraries Array of core libraries we support
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
protected function getLibraries( $engine, array $coreLibraries = array() ) {
|
2013-02-14 17:38:03 +00:00
|
|
|
$extraLibraries = array();
|
|
|
|
wfRunHooks( 'ScribuntoExternalLibraries', array( $engine, &$extraLibraries ) );
|
|
|
|
return $coreLibraries + $extraLibraries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a list of all paths libraries can be in for this engine
|
|
|
|
*
|
|
|
|
* @param $engine String script engine we're using (eg: lua)
|
|
|
|
* @param $coreLibraryPaths Array of library paths to use by default
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
protected function getLibraryPaths( $engine, array $coreLibraryPaths = array() ) {
|
2013-02-14 17:38:03 +00:00
|
|
|
$extraLibraryPaths = array();
|
|
|
|
wfRunHooks( 'ScribuntoExternalLibraryPaths', array( $engine, &$extraLibraryPaths ) );
|
|
|
|
return array_merge( $coreLibraryPaths, $extraLibraryPaths );
|
|
|
|
}
|
2013-03-14 12:42:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get text for the limit report, old style
|
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLimitReport(){
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add limit report data to a ParserOutput object
|
|
|
|
*
|
|
|
|
* @param $output ParserOutput ParserOutput object in which to add limit data
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
public function reportLimitData( ParserOutput $output ){
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format limit report data
|
|
|
|
*
|
|
|
|
* @param $key string
|
|
|
|
* @param &$value string
|
|
|
|
* @param &$report string
|
|
|
|
* @param $isHTML bool
|
|
|
|
* @param $localize bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function formatLimitData( $key, &$value, &$report, $isHTML, $localize ){
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class that represents a module. Responsible for initial module parsing
|
|
|
|
* and maintaining the contents of the module.
|
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
abstract class ScribuntoModuleBase {
|
2014-06-18 17:17:04 +00:00
|
|
|
/**
|
|
|
|
* @var ScribuntoEngineBase
|
|
|
|
*/
|
2014-10-09 19:49:40 +00:00
|
|
|
protected $engine;
|
2014-06-18 17:17:04 +00:00
|
|
|
|
2014-10-09 19:49:40 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $code;
|
|
|
|
|
|
|
|
/**
|
2014-10-10 09:02:03 +00:00
|
|
|
* @var string|bool
|
2014-10-09 19:49:40 +00:00
|
|
|
*/
|
|
|
|
protected $chunkName;
|
2012-01-28 16:22:18 +00:00
|
|
|
|
2014-10-09 19:49:40 +00:00
|
|
|
/**
|
|
|
|
* @param ScribuntoEngineBase $engine
|
|
|
|
* @param string $code
|
2014-10-10 09:02:03 +00:00
|
|
|
* @param string|bool $chunkName
|
2014-10-09 19:49:40 +00:00
|
|
|
*/
|
|
|
|
public function __construct( ScribuntoEngineBase $engine, $code, $chunkName ) {
|
2012-04-05 03:53:05 +00:00
|
|
|
$this->engine = $engine;
|
|
|
|
$this->code = $code;
|
2012-04-05 07:58:02 +00:00
|
|
|
$this->chunkName = $chunkName;
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 09:02:03 +00:00
|
|
|
/**
|
|
|
|
* @return ScribuntoEngineBase
|
|
|
|
*/
|
|
|
|
public function getEngine() {
|
|
|
|
return $this->engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCode() {
|
|
|
|
return $this->code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|bool
|
|
|
|
*/
|
|
|
|
public function getChunkName() {
|
|
|
|
return $this->chunkName;
|
|
|
|
}
|
2012-04-05 07:58:02 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
/**
|
2014-07-07 18:46:59 +00:00
|
|
|
* Validates the script and returns a Status object containing the syntax
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* errors for the given code.
|
2012-06-15 23:34:35 +00:00
|
|
|
*
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* @return Status
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
abstract public function validate();
|
2014-07-07 18:46:59 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
/**
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* Invoke the function with the specified name.
|
2014-07-07 18:46:59 +00:00
|
|
|
*
|
2014-10-09 19:49:40 +00:00
|
|
|
* @param string $name
|
|
|
|
* @param PPFrame $frame
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
* @return string
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-05-22 03:56:07 +00:00
|
|
|
abstract public function invoke( $name, $frame );
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|