Commit graph

37 commits

Author SHA1 Message Date
Jackmcbarn d74c81c233 Add name to nosuchfunction and nosuchmodule errors
When displaying a nosuchfunction or nosuchmodule error, include the name
of the nonexistent function or module.

Change-Id: I17fc2c68dc8267302a82eee3cb2c5df9b5a3c46c
2014-04-13 21:29:05 -04:00
Marius Hoch 08de37719d Don't try to inline load ext.scribunto on mobile
This module doesn't exist on mobile, so don't try to load it there
(which will produce an exception).

Bug: 59808
Change-Id: Ifad7edb508c1f740a109e8f5c1656e4c7841ab13
2014-03-21 03:00:42 +01:00
Brad Jorsch b58ee1da94 Use the new limit report hooks
Change Ie065c7b5 added an option to show profiling data at the bottom of
preview pages, and with it new hooks to gather and format this data in a
more structured way than is possible with ParserLimitReport. This change
adds support for the new hooks.

Depends-On: I7799616a602d90e1b8d3f0ece35811ca387bade7
Change-Id: Idffd2d78f9a0217c99c07cbbfc844d6daf0172f7
2014-02-10 04:11:35 +00:00
Marius Hoch ac62e34952 Add mw.html to Scribunto
A module for building complex HTML from Lua using a
fluent interface. The module is originally from enwiki,
but the authors allowed us to reuse it under GPLv2+
(as stated in the file).
The module will be loaded per default and comes with
unit tests.

As discussed on wikitech-l:
http://lists.wikimedia.org/pipermail/wikitech-l/2013-December/073320.html

Change-Id: I7c8d4378091c13d5ace0dd1fcbb4e27163e8c896
2014-01-03 00:04:34 +01:00
jenkins-bot a85275592c Merge "Add text module" 2013-03-27 16:55:07 +00:00
Brad Jorsch 5989d28678 (bug 39655) Add Lua version info to Special:Version
Use the SoftwareInfo hook to add the versions of LuaSandbox and Lua to
Special:Version.

Bug: 39655
Change-Id: I912197efee0211066677c4d46e638fb546a410c6
2013-03-25 04:07:30 +00:00
Brad Jorsch 0db3d7c6d2 Add text module
This exists for some common text-processing functions that aren't
included in string (and therefore also aren't in mw.ustring), as well as
a logical place for the "unstrip" function requested in bug 45085.

Bug: 45085
Change-Id: I47356215fcc8ddeed5f901cd933a30021394bd78
2013-03-20 10:10:15 -04:00
Brad Jorsch ded331ddc9 (bug 45845) Allow for docs at non-subpages
It has been claimed that some wiki might want to place module
documentation at a location other than as a subpage of the module, for
example under "Project:Module documentation/$1". It's possible to
support this, so we may as well.

This also involves renaming the "scribunto-doc-subpage-*" messages to
"scribunto-doc-page-*", since the interpretation of
scribunto-doc-subpage-name would be drastically changed.

Note that any wiki that has customized scribunto-doc-subpage-name will
need to re-customize scribunto-doc-page-name, the old value will not be
transferred.

Bug: 45845
Change-Id: Ic453561691e04b5250d219cc7d871c17e60b9912
2013-03-12 14:33:40 -04:00
Brad Jorsch 7617f25a8b (bug 46031) scribunto-doc-subpage-name needs to be in the content language
Bug: 46031
Change-Id: I6e3c2c244f85258838774491d3bcc6ebd6a2c8c3
2013-03-12 14:18:28 -04:00
Brad Jorsch 04a0a580e3 Add mw.title library
Note that fetching any title besides the one for the current page is
considered "expensive". It also records the title fetched in the
ParserOutput so it will be listed in pagelinks, just like #ifexists.

This also moves the ToString test formatter into TestFramework.lua, so
TitleLibraryTests.lua can use it too.

Change-Id: I799f3289a37fe1349b6bca5758829acf82cb718f
2013-02-28 11:57:11 -08:00
Brad Jorsch ba09ba3fde Add mw.message library
Change-Id: I12ca84f848c34f1227ee8acdc8bc04bdfd0b2d97
2013-02-26 22:20:04 -08:00
Brad Jorsch 30a75fb0f1 Add module documentation support
Add the ability for modules to be documented using a /doc subpage, which
is automatically transcluded onto the module page.

To get the transcluding to work right, I wound up having to change from
the deprecated-in-1.21 ArticleViewCustom hook to ContentHandler, as
there didn't seem to be any other way to get the ParserOutput into the
links tables. Which means Scribunto now needs MediaWiki 1.21 rather
than 1.20.

Change-Id: Id487097c2a505c11f92a3404f5d3ee98beb2570c
2013-02-22 05:01:29 +00:00
Brad Jorsch 0a8757baba Lua ustring implementation
This is a reimplementation of Lua's string library with support for
UTF-8.

The entire ustring library is implemented in pure Lua. PHP callbacks are
also available for overrides: in LuaSandbox these are used for almost
all functions, while in LuaStandalone they are used only for the pattern
matching. Also, ustring.upper and ustring.lower are overridden using
mw.language's .uc and .lc if available.

It also includes a bunch of unit tests.

Note that if you download the normalization tests, they may fail under
LuaSandbox if you have PHP's intl extension installed and libicu on your
system is too old.

Change-Id: Ie76fdf8d3a85d0a3d2a41b0d3b7afe433f247af0
2013-02-12 14:26:29 -05:00
Brad Jorsch db9fd2b39b Add mw.uri library
Change-Id: I1d94a8c288537ada038f24f2ec26922d95f14785
2013-02-07 13:31:24 -05:00
Brad Jorsch bd03237246 Add mw.site library
Contains various constants and functions to access site info.

Change-Id: I944938f9af0203c16d1a3fb2046f332045dec4d9
2013-02-06 09:20:59 -05:00
Brad Jorsch 337abb295f Make Lua engine tests modular
Rework the LuaEngine tests to be entirely modular, so that every library
need not add itself to one monolithic file. This also allows other
extensions that add Lua modules to make unit tests without having to
somehow inject them into a test class owned by Scribunto.

The approach taken is similar to that used for Selenium for running
tests against multiple browsers.

Change-Id: I294b2a8195759c0e4fa211f879305a8eb66d9c9a
2013-02-06 09:10:57 -05:00
Brad Jorsch 50cde6fe8d Handle cloned parsers correctly
If the parser is cloned, we need to give the new instance a new
ScribuntoEngine. Otherwise when one of the clones has ParserClearState
called, the engine for the other will also be unexpectedly destroyed.

Change-Id: Ia6ded082e5adddfbd91387bca825a305ccbf831d
Depends-On: Ieec65c908d71e89b9a66f83b9a626f842aadacbb
2012-11-16 11:27:55 -05:00
Siebrand Mazeland 42c0c55225 Replace deprecated methods.
Change-Id: Ifab19bbc6f75148c8dcee758e09149280e2b229b
2012-10-07 02:59:30 +02:00
Tim Starling 776cc1f93d (bug 39606) Add a tracking category for script errors
Change-Id: I5a925ccd41e494a7b06d98b1e1656250b80c143a
2012-09-06 14:56:42 +10:00
Tim Starling b5c36bad59 Debug console module
* Added a debug console to the edit page, allowing unsaved modules to be
  tested.
* Removed the "preview" button from the edit page.
* Only show the "ignore code errors" checkbox on module edit pages, not
  all edit pages.
* Added Lua function mw.log() for sending messages to the debug log.

Change-Id: Ia51f439e573a1deb5b83f94ddd1a86792d5569c1
2012-07-14 14:35:55 +10:00
Tim Starling 54af4fc79e (bug 37315) Run UTF-8 normalization on script results
Change-Id: I9b9fdb0391145560d85e64f6afdc5bfbd5093cf2
2012-07-09 13:12:54 +10:00
Tim Starling be8f6ca34d Allow users to ignore parse errors
Allow users to save a module with a parse error in it, by checking an
"ignore error" box. This was a requested feature in Berlin, there was a
desire to be able to save incomplete drafts of modules. I tested the
effect of #invoking a module with a parse error in it, it shows a normal
script error.

Change-Id: If2978a226ac50150ebeb7837e8dd370a669db771
2012-07-03 13:02:03 +10:00
Reedy 5afbf6a7c7 Some bits of documentation
Left a FIXME

Remove some unused variables

Change-Id: If733608416e68de6afe1e8f6edd4ed78a119979e
2012-06-20 23:54:21 +01:00
Victor Vasiliev 8fcaa128ac Merge "New parser interface" 2012-05-26 11:42:40 +00:00
Tim Starling 6964cb1ded Don't throw an exception when you save a module page
Fix for 14e8d5d: EditFilter has a $section parameter, EditFilterMerged
doesn't. So if you try to just change the hook without changing the hook
function definition, you get "expected reference, value given" for
parameter 4, which is escalated to an exception.

Change-Id: Ibedff799472285802c43feff6f3cb078e9bfb73c
2012-05-24 04:50:35 -07:00
Tim Starling 6bc11ff615 New parser interface
* Implemented the new parser interface based on a frame object, as
  described in the design document and wikitech-l.
* Added parser tests for the new interface.
* Removed {{script:}} parser function
* Allow named parameters to {{#invoke:}}
* Don't trim the return value
* If a function invoked by #invoke returns multiple values, concatenate
  them into a single string.
* If there is an error during parse, show the error message as an HTML
  comment as well as via JavaScript. This makes parser test construction
  easier, and probably makes debugging easier also.
* Rename mw_internal to mw_php to clarify its role. It is now strictly a
  private Lua -> PHP interface function table.
* Protect mw.setup() against multiple invocation.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::receiveMessage():
  large packets caused fread() to return with less than the requested
  amount of data, which previously caused an exception. It's necessary
  to check for EOF and to repeat the read to get all data. The receive
  function on the Lua side does not suffer from this problem.
* In the standalone engine, fixed a bug in the interpretation of null
  return values from PHP callbacks. This should return no values to Lua.
* Updated the Lua unit tests to account for the fact that functions are
  now forced to return strings.
* Updated the getfenv and setfenv tests to account for the extra stack
  level introduced by mw.executeFunction().

Change-Id: If8fdecdfc91ebe7bd4b1dae8489ccbdeb6bbf5ce
2012-05-22 14:18:49 +10:00
Tim Starling da06273ede Nicer errors with backtraces etc.
* Added error backtrace collection to MWServer:handleCall()
* When there is an error on parse, show a short and simple inline error
  message to the user, which when clicked, expands to a full error with
  HTML-formatted backtrace.
* When an error is encountered during module validation, have the code
  editor jump directly to the line. Requires r115011.
* Expose the code location of most errors to Scribunto, by parsing the
  standard error message format.
* During module validation, abbreviate the error location if the error
  is in the same module.
* Do not execute the module during validation, just parse it. Execution
  does not really work without an active parse operation in progress.
  It already caused a fatal error if you called require() from the main
  chunk, and problems would have become more visible as more
  parser-related APIs were added.
* LuaSandbox does not yet provide backtraces, but this is planned.

Change-Id: Id9f6564a41b310792b3fe3ebb527cbf8f8771bd1
2012-04-23 21:58:30 +10:00
tstarling b68cae904a More tests and some related bug fixes
* Added tests for the engine classes.
* Added some tests that run under Lua.
* In the chunk names, fixed truncation of module names at 60 bytes
  by using an "=" prefix instead of @.
* Fixed a bug in mw.clone() which was causing the metatable to be set on
  the source table instead of the destination.
* Put restricted setfenv/getfenv in the cloned environment rather than
  the base environment, they work better that way.
* In setfenv(), check for getfenv() == nil, since that's what our own
  restricted getfenv returns.
* Fixed getfenv() handling of numeric arguments: add one where
  appropriate.

Change-Id: I2b356fd65a3fcb348c4e99a3a4267408fb995739
2012-04-19 17:48:20 +10:00
tstarling cebe775ee8 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 13:46:18 +10:00
tstarling b0f00103e2 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 14:41:08 +10:00
tstarling 54cedd69b8 Introduced standalone interpreter, implemented module isolation
* 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
2012-04-13 20:45:26 +10:00
Tim Starling 30622e86fe More changes for extension rename 2012-04-06 05:04:30 +00:00
Tim Starling 925045a669 * Removed scriptlinks table. It just seemed the same as templatelinks to me, and tl_namespace can be used if you want to separate out modules.
* Used Parser::fetchTemplateAndTitle() to get modules and register them in templatelinks. Most of the logic was previously duplicated.
* Changed the configuration and factory functions to allow for the possibility of multiple engines coexisting on the one wiki.
* Made the $parser parameter optional, to improve debugging in the case where a parser is needed but parsing has not started. Removed all $wgParser references.
* Renamed Scripting::getEngine() to getParserEngine() and resetEngine() to resetParserEngine()
* Removed setOptions() and updateOptions(). If you want to change the options, you can always make a new instance.
* Renamed getModule() to fetchModuleFromParser()
* Simplified module constructor parameters and member variable list
* Fixed spelling error langauge -> language
* Renamed a few variables for clarity: $module -> $moduleName, $function -> $functionName
* Renamed getLimitsReport() to getLimitReport() as it is in Parser
* Use an accessor for getting LuaSandboxEngineModule::$contents
* Renamed configuration variable maxCPU to cpuLimit
* Include the full message name as a parameter to ScriptingException. This makes it easier to find messages in the i18n file, and it makes it easier to find invocation points when a translator wants to know how a message is used. Adding the message name as a comment on the same line seems like a waste of space when you can just make it an actual parameter.
* Reduce the number of formal parameters to ScriptingException::__construct(), since there is already too many and we may want to add more things later, such as backtraces with hyperlinks and other such stuff.
* Include the code location as $2 unconditionally so that there is less chance of getting the parameters wrong
* Shortened some message names. Wrote English text for messages without it.
2012-04-05 07:58:02 +00:00
Tim Starling c8f4d0a213 First-pass cleanup:
* Removed ScriptingEngineBase::load(), inappropriate interface specification, only used by child classes and more properly defined by them
* Fixed inappropriate use of final
* Fixed case of a class constant to conform with MediaWiki conventions
* Use a factory function interface for module creation instead of a class name accessor
* Don't pass unnecessary $engine parameter to ScriptingFunctionBase::__construct(). Pass parent object as the first parameter per convention.
* Fixed unnecessary reference parameter in doRunHook()
* Have LuaSandboxEngineFunction::call() return the first result or null, per the base class documentation, instead of imploding. 
* Use strval() to avoid a warning in case call() returns an array or object
* Improved some comments
2012-04-04 06:10:32 +00:00
vvv 03bf6ce779 Add integration with CodeEditor extension. 2012-02-06 22:14:47 +00:00
Sam Reed fa2dd80ead Use get accessors
Add/Improve documentation

Remove trailing whitespace
2012-01-28 16:46:15 +00:00
vvv b960075a55 Commiting the initial revision of the Scripting extension, a framework that allows programming languages to be embedded regardless of what are those languages actually are and how they are interpreted.
This is a very raw version, and it misses most messages (even in English!) and probably needs some more work.
2012-01-28 16:22:18 +00:00