Extension talk:Scribunto
Add topicWriting unit tests crashes PHPUnit: Premature access to service container in MediaWikiServices.php
[edit]Currently making writing tests for a Lua extension, when running the following command:
composer phpunit:entrypoint -- extensions/BigInteger/tests/phpunit/unit/BigIntegerTest.php
Yields the error listed above.
Running on a Docker container in Ubuntu 20.04 LTS (WSL2):
MediaWiki 1.44.0 (55746f6) 15:17, 22 August 2025 PHP 8.3.14 (fpm-fcgi) ICU 72.1 SQLite 3.40.1 Lua 5.1.5 Pygments 2.19.2
Trace stack:
PHP Fatal error: Uncaught LogicException: Premature access to service container in /var/www/html/w/includes/MediaWikiServices.php:342
Stack trace:
#0 /var/www/html/w/extensions/Scribunto/tests/phpunit/Engines/LuaCommon/LuaEngineTestHelper.php(65): MediaWiki\MediaWikiServices::getInstance()
#1 /var/www/html/w/extensions/Scribunto/tests/phpunit/Engines/LuaCommon/LuaEngineTestBase.php(75): MediaWiki\Extension\Scribunto\Tests\Engines\LuaCommon\LuaEngineTestBase::makeSuite()
#2 [internal function]: MediaWiki\Extension\Scribunto\Tests\Engines\LuaCommon\LuaEngineTestBase::suite()
#3 /var/www/html/w/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(131): ReflectionMethod->invoke()
#4 /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/Command.php(121): PHPUnit\Runner\BaseTestRunner->getTest()
#5 /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/Command.php(99): PHPUnit\TextUI\Command->run()
#6 /var/www/html/w/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#7 /var/www/html/w/vendor/bin/phpunit(122): include('...')
#8 {main}
Next PHPUnit\TextUI\RuntimeException: Premature access to service container in /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/Command.php:101
Stack trace:
#0 /var/www/html/w/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#1 /var/www/html/w/vendor/bin/phpunit(122): include('...')
#2 {main}
thrown in /var/www/html/w/vendor/phpunit/phpunit/src/TextUI/Command.php on line 101
I believe this may be an issue with Scribunto. Is there a way to get the PHPUnit run properly?
--Yonicstudios (talk) 21:30, 1 September 2025 (UTC)
Modules in other namespaces?
[edit]Would that be possible?
This can be notably useful for userspace code that ought not to be in Module:.
As it stands, the module contentmodel can not be given to userspace pages.
It would also require invoke to permit using other namespaces, sort of like template invocations do (here it would be assume module, or use what's given.) — Alien 3
3 3 18:13, 23 January 2025 (UTC)
Lua error: Internal error: The interpreter has terminated with signal "11".
[edit]I am getting this error while trying to use Semantic MediaWiki.
MediaWiki 1.41.4
PHP 8.2.27 (litespeed)
ICU 76.1
MySQL 8.0.33-cll-lve
Lua 5.1.5
Semantic MediaWiki 4.2.0
Semantic Scribunto 2.3.2
I have followed the instructions here that say 'Scribunto should work for you out of the box if'.
- Linux x86-64
- PHP's proc_open function is not restricted.
- proc_terminate and shell_exec are not disabled in PHP.
- lua5_1_5_linux_64_generic/lua is set to 755
- SELinux is not running on my server.
LocalSettings.php includes
$wgScribuntoDefaultEngine = 'luastandalone';
$wgScribuntoEngineConf['luastandalone']['errorFile'] = "$IP/images/temp/lua-error.log";
I attempted to verify that lua is running.
[home@az1-ss108 lua5_1_5_linux_64_generic]$ file lua
lua: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped
So it appears to be running fine.
But the extension is not working out of the box.
lua-error.log contains:
/mediawiki-1.41.4/extensions/Scribunto/includes/Engines/LuaStandalone/lua_ulimit.sh: line 6: /mediawiki-1.41.4/extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic: Is a directory /mediawiki-1.41.4/extensions/Scribunto/includes/Engines/LuaStandalone/lua_ulimit.sh: line 6: exec: /mediawiki-1.41.4/extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic: cannot execute: Is a directory
I tried using $wgScribuntoEngineConf['luastandalone']['luaPath'] = '/usr/bin/lua, but the version running on my server is 5.2.
Redheadkelly (talk) 21:50, 16 March 2025 (UTC)
- Just in case there are any other novices out there attempting to make this work on shared hosting without sufficient server-side experience, this is what I learned.
- The PHP luasandbox extension can be turned on in cPanel, or at least the version I have with my host, by clicking 'Select PHP version' then just checking the box next to luasandbox in the version of PHP marked 'current'.
- It is not as complicated as LuaSandbox makes it seem.
- I also needed to verify that the version of PHP marked 'current' matched the version being used by MediaWiki as displayed on the Special:Version page. Mine wasn't at first, so I had to contact tech support to remedy that.
- The only settings required in LocalSettings.php was the line:
$wgScribuntoDefaultEngine = 'luasandbox';- I also added
error_log( "luasandbox loaded? " . (extension_loaded('luasandbox') ? 'yes' : 'no') );until I got it working. - Once this line is added, load a page of the wiki and then check the error_log in the wiki root directory. It should return 'luasandbox loaded? yes'. If it does not, then keep troubleshooting. I actually asked ChatGPT and it gave me better answers than my hosting tech support. Redheadkelly (talk) 19:42, 10 August 2025 (UTC)
Lua 5.3.4?
[edit]In an attempt to verify that Lua was not crashing, I tried this:
[/extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic]$ lua
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
This appears to be saying that Lua 5.3.4 is installed in this directory and not Lua 5.1.5? Redheadkelly (talk) 21:46, 26 March 2025 (UTC)
- Perhaps if you run
./lua? Justluawould use the system lua, not necessarily the one in the folder. Lwangaman (talk) 14:21, 28 January 2026 (UTC)
LuaStandaloneInterpreter.php bug for windows 10
[edit]At lines 138 -- 144 the if instruction adds extra double quotes that prevent lua standalone executable to be found . 2A01:E0A:44F:F9E0:F83A:39AC:A12:8770 10:35, 26 May 2025 (UTC)
- Похоже существующий метод в LuaStandaloneInterpreter.php сбоит на неанглийских системах очень часто:
- if ( php_uname( 's' ) == 'Windows NT' ) {
- // Like the passthru() in older versions of PHP,
- // PHP's invokation of cmd.exe in proc_open() is broken:
- // http://news.php.net/php.internals/21796
- // Unlike passthru(), it is not fixed in any PHP version,
- // so we use the fix similar to one in wfShellExec()
- $cmd = '"' . $cmd . '"';
- }
- Вроде бы в reddit'е его предлагали просто удалить, но тогда не работает передача крупных параметров.
- Есть предложение заменить его на фильтрующий код:
- if ( php_uname( 's' ) == 'Windows NT' ) {
- // Avoid invoking cmd.exe if possible to prevent command-line length limits
- // and quoting issues. Instead, pass the command directly to proc_open(),
- // but ensure the executable path and arguments are properly escaped.
- // This works if $cmd is already a full command with properly quoted arguments.
- // Do NOT wrap the whole command in quotes, as that forces cmd.exe usage.
- // Instead, rely on proc_open() to call the binary directly.
- // Only use cmd.exe if the command contains shell operators like |, >, ||, etc.
- $hasShellOperators = preg_match( '/[|<>;&\n\r]/', $cmd );
- if ( $hasShellOperators ) {
- // Must use cmd.exe; wrap properly
- $cmd = 'cmd.exe /c "' . str_replace( '"', '""', $cmd ) . '"';
- }
- // Otherwise: leave $cmd as-is and let proc_open() call the binary directly
- }
- тогда сбои при передаче параметров вроде бы исчезают, и даже передаются параметры размером более 64кБ (проверял на [1]). Масштабных проверок не делал - очень долго для домашних компьютеров.
- Halfcookie (talk) 20:33, 6 January 2026 (UTC)
Why Lua?
[edit]Why did the authors of this extension choose Lua as the designated scripting language? I have a feeling that Python with Jinja would work a lot better, especially given the fact that Lua is a very weird language with things such as 1-based indexing. 208.114.63.4 13:00, 30 May 2025 (UTC)
- User:Sumanah/Lua vs Javascript has some background. Nardog (talk) 06:19, 25 June 2025 (UTC)
Lua error: Internal error: The interpreter exited with status 126.
[edit]I have a MediaWiki install on shared hosting. I have yet to be able to get it working. I think I've ruled out several common problems.
I'm running:
MediaWiki 1.43.1
Semantic MediaWiki 5.0.0
PHP 8.2.28 (litespeed)
MySQL 8.0.33-cll-lve
I have in LocalSettings.php:
$wgScribuntoDefaultEngine = 'luastandalone';
$wgScribuntoEngineConf['luastandalone']['luaPath'] = 'extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic';
I have verified the following things outlined in the documentation:
- My web server is run on Linux 64.
- PHP's
proc_openfunction is not restricted. proc_terminateandshell_execare not disabled in PHP.- The permissions on this luaPath and executable are set to 755.
The error being output is:
rosssurnameproject.net/wiki/extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic: cannot execute: Is a directory
But if I change to:
$wgScribuntoEngineConf['luastandalone']['luaPath'] = 'extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic/lua';
I get:
Lua error: Internal error: The interpreter has terminated with signal "11".
rosssurnameproject.net/wiki/extensions/Scribunto/includes/Engines/LuaStandalone/binaries/lua5_1_5_linux_64_generic: cannot execute: Is a directory
I found a comment on a similar post written 6 years ago that says 'Scribunto does not ship with a compatible binary.' Can that be true?
If I run 'file lua', I get:
lua: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped
My hosting company provides Lua, but it's not the right version, so I need this one to work. Redheadkelly (talk) 22:36, 7 July 2025 (UTC)
How to use extension tags proper? (resolved)
[edit]Hi, I'm trying to use an extension's tags in Lua and thought it was a good idea to use extensionTag, but got into trouble. Unfortunately, the developer recommends against using the #tag 'equivalents' because they don't always work quite the same way - I don't know if nested tags are especially problematic here. Since extensionTag is closer to the #tag version, what should I use instead? Is mw.html a viable alternative or is it suitable for HTML5 only? What about mw.text.tag? Rand(1,2022) (talk) 10:49, 11 July 2025 (UTC)
- The level of nesting does seem to matter. For tags nested in extensionTags, I had better luck using mw.text.tag. But top-level extension tags cannot use mw.text.tag and should use extensionTags. Is that how it works though? Rand(1,2022) (talk) 12:24, 11 July 2025 (UTC)
- I'm now using 'mw.text.tag' as the default and apply frame:preprocess in the final step where every tag and nested tags have been gathered in the output string. The 'feature (not a bug)' of 'frame:extensionTag' is that immediately parses the tag, which is probably great for most use cases but potentially problematic for groups of extension tags that have a more complicated, interdependent relationship to one another. Rand(1,2022) (talk) 13:08, 11 July 2025 (UTC)
bad argument #1 to 'mw.loadJsonData' ('....' is not a valid JSON page)
[edit]This appears to happen with wiki pages that contain perfectly valid JSON. The problem may be that Scribunto strictly accepts CONTENT_MODEL_JSON as the content model for JSON; if an extension adds a custom, JSON-based content model, Scribunto fails to recognise it. Rand(1,2022) (talk) 18:02, 13 July 2025 (UTC)
Includes Lua 5.3.4?
[edit]When I run the 'lua' command in the lua5_1_5_linux_64_generic directory, I get:
'Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio'
Is Scribunto being shipped with Lua 5.3.4, not Lua 5.1.5 for Linux 64 systems???
Where can I get the 5.1.5 executable? Redheadkelly (talk) 00:51, 15 July 2025 (UTC)
- I think you're probably running "lua" instead of "./lua", thus calling your OS binary instead of the one from the extension, hence your confusion. Tactica (talk) 04:20, 15 July 2025 (UTC)
Lua 5.2 compat being added to Debian LuaJIT package
[edit]For those using the (unsupported but in some cases still useful) LuaJIT - a change has been merged to make the Debian package use DLUAJIT_ENABLE_LUA52COMPAT (currently pending for the next build in the experimental repo), which as described here includes checks for __pairs and __ipairs, as in LuaSandbox. Of course, if the latter works for you, that is likely to remain a better choice (and Debian has it, though not yet this fix). GreenReaper (talk) 19:40, 27 December 2025 (UTC)
The interpreter exited with status 1 behind IIS
[edit]The note regarding this error in the troubleshooting section when running under IIS, [2] is indeed still correct, however just a note that the line number has changed from 132 to 145 (at least as of MediaWiki 1.45.1's Scribunto version)
What is the proper way to return/format multiple values?
[edit]If only a single string is returned, how does one retrieve multiple values for e.g. formatting as a list? Should we just return a string containing markup? Is it considered proper to couple the output with its presentation? Ham Pastrami (talk) 07:16, 24 April 2026 (UTC)