This bug is a request for comments and an invitation to a discussion regarding Scribunto.
Introducing client-written server-side scripting in a proper programming language was a great step forward for MediaWiki. Now, complicated behaviour can be relatively easily programmed without monstrous chains of {{#if:}}'s, {{#ifeq:}}'s and {{#switch:}}'es. This is instrumental to converting low-quality input made by an inexperienced user to high-quality wiki content.
Yet the idea of allowing server-side scripting in MediaWiki was not immediately accepted. Several years before Scribunto, a proposal to install Winter extension on Wikimedia sites was rejected. Among the objections were the security considerations and outright "MediaWiki is not a bloody programming language". This proves that what once seemed impracticable can become desirable.
I welcomed Scribunto and installed it on the wiki I run as soon as it became technically possible. It added many new opportunitiers. However, as time passed, I started to notice limitations. Here are some of them:
- Lua version is 5.1 and this is really an old one. I miss the features introduced in later versions (5.4.0 is now available) like a metamethod for ipairs and pairs (missed also by lusandbox developers, so they backported it), yielding across C calls, etc.
- I am dissatisfied about the fact that I have to patch and re-compile luasandbox to enable some standard Lua libraries, like coroutine. I would prefer to switch in on in php.ini.
- I would also like to have a way to connect Lua libraries in C like lrexlib for PERL-compatible regular expressions, better then patching and rebuilding luasandbox.
- (UPD) Metatables for userdata will be needed if new libraries will be enabled.
- Some day, perhaps, I would like to have server-side scripts in languages other than Lua--not because they are better, but to avoid rewriting existing libraries in Lua.
I know that there are objections to any change that would aim to fulfil these wishes:
- Enabling new features is a security risk. To this I answer that it ought to remain wiki site admin's responsibility.
- There is already a significant code base in Lua 5.1 in Wikimedia projects, and 5.2 is not fully backward-compatible. My opinion is that obsolete code base is a problem and it will only get worse with time. Something should be done about it as early as possible.
To address these issues, perhaps, a revision of both Scribunto's and luasandbox's architectures is needed. My proposals below can be based on insufficient information, be too brave or vague but I think they should be considered:
- The information on page content model in Module: namespace should include the language (first, only Lua, later, perhas, others) and its version.
- The same page can be in multiple versions of Lua, like 5.1,5.2,5.3, which means that the code is expected to work under any listed version of Lua.
- The language and version compability checks can be automatic,
- It can be based not only on successful interpretation but also on automated unit test: an assertion defined by the module author.
- Scribunto settings should define separate engines for different languages and their versions.
- There can be several luasandboxes or one with several lua environments (if the conflict between lua libraries can be avoided).
- Perhaps an initialisation script written in Lua, set in php.ini and invoked on PHP startup without the limitations of sandboxed Module: scripts, will be useful; e.g.: luasandbox.ini = "rex = require 'rex_pcre2.so'".