This is getting close to the point of "don't do that, just wrap the
built-in". But since it's a regression in a recent patch, let's restore
the old behavior here.
Bug: T236092
Change-Id: Ieddc23d942bc91fd0246ae14d8a4af7719e3834f
When an #invoke is passed as an argument to another #invoke,
mw.getCurrentFrame() at module scope will return the wrong frame.
On the PHP side, we need to always reset the frame when processing
an #invoke, not just when there's no frame already. I don't remember why
I82dde43e wasn't done that way, but changing it doesn't make any tests
fail and Scribunto tends to have good tests.
On the Lua side, we need to do the same. The logic wih mw.getCurrentFrame()
using a global that gets stored, modified, and reset in several places
was getting confusing, so this patch reworks the logic to inject a
globalless mw.getCurrentFrame() into each #invoke's cloned environment
instead.
Bug: T234368
Change-Id: I8cb5bc4dc14c9b448c9f267e0539daa75e72af4c
And use the unit test base on most of the tests, except the ones that need
database. This makes tests considerably faster.
Bug: T230701
Change-Id: Ifbede1e2610c672b4d8a83ce41f74200e0c97be9
MediaWikiIntegrationTestCase (formerlly know as MediaWikiTestCase)
is a very heavy class that resets the database, caches and services between
every test.
Bug: T229180
Change-Id: I3d328d6ba7009e87c0f432a4f8d84d774ea57e5f
The test currently runs a busy loop that does string operations 1
billion times, when really it just needs something that takes more than
2 seconds of CPU time. On the other hand, there's another test that uses
the same method to run only 100 string operations for a different test.
Add a second parameter to have it exit early if enough CPU time has been
used, and use it in the first test.
Bug: T220685
Change-Id: I32309f049bcfb2e1310651818ff8674f0a311f40
RFC 3986 allows IPv6 literals (and future IP versions) by having the
"host" enclosed in brackets, like `http://[2001:db8::]`. mw.uri should
handle these appropriately.
Bug: T223267
Change-Id: I6f712b87bc376cf606c6c2ebbe80176037d6dddb
If TemplateStyles installed, then enable it in the Module namespace
by default. This change is analogous to I96d9601ff80c2d3eb052c01.
Since both extensions use the ContentHandlerDefaultModelFor hook, Scribunto
will check if the sanitized-css model has already been set, and if so, not
override it. If the page is in NS_MODULE, it will set the content model to
Scribunto, but allow further hooks to override it, in which case it is
expected that TemplateStyles would set it to sanitized-css.
Bug: T200914
Depends-On: I2fa9b822ee39bcc5f95a293c8c4aad4d53ede30a
Change-Id: I7a9b445accde35e4a5e7d13100c646f211d21afe
It's easily possible for Lua to raise errors where the string is not
valid UTF-8. When we turn that into a Scribunto_LuaError, we should
normalize it so other things don't break.
Bug: T208689
Change-Id: Idc5514261e99d64222b86877dd0500d425a26988
This test causes spurious CI failures in other projects; to unblock them
for now, remove the test again until we can figure out how to make it
work better.
This reverts commit 7a7f522676.
Bug: T209232
Change-Id: Id2eeeb781b7a8a6298ba06d78bab238b37dac9ca
As documented, string.gub( 'foo', '%a', '%1' ) should raise an invalid
capture index error because there is no capture with index 1 in the
pattern. But in fact it treats %1 as %0 in this situation. The ustring
library should match this behavior.
This patch also adds some tests for the behavior of gsub with table and
function replacements when the pattern does have captures.
Bug: T207623
Change-Id: Ie3e6c2eafa4a05989815c62c7037167642581751
If the replacement table or function results in a value that isn't a
string or number (or nil), string.gsub raises an error. Have ustring
raise the same error.
Bug: T195326
Change-Id: Ic36f9f5d7adc0c14e7a4a94d3747335107acd8b6
Manually import LuaSandbox's git repository as a composer dependency to
provide the PHP stubs for phan.
Change-Id: I6226b9211f31d829da5a2775c6f5cf3599dd8ebc
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.MissingCovers.MissingCovers
Change-Id: I07b2cf945f44fd5532812a712f7dd40d2f208be2
When passing an array from PHP to Lua, stringify integer array keys
beyond the range a lua_Number can represent.
When passing a table from Lua to PHP,
* Avoid exponential encoding for integer keys beyond 1e14, so Zend PHP
will interpret them as integers.
* Always encode integer keys as integers, so HHVM will interpret them as
integers.
* Detect collisions, e.g. { [0] = 'foo', ["0"] = 'bar' }
Bug: T186240
Change-Id: I078068ed57df078248a307608381614bdfc70801
The extraneous whitespace in the return value from wfShellExec() causes
multiplying $size to trigger the newly introduced "A non well formed
numeric value encountered" warning in PHP 7.1+.
Work around that by using trim() to get rid of the whitespace.
Bug: T186299
Change-Id: I3d47ef6cc7fb99b4d4840dc847d150c3939ee535
The two lualib/ustring generation scripts run independently of MediaWiki, so
the new wfIsCLI() isn't usable there.
Bug: T184043
Change-Id: I217657d12e16a7b76dc814be5fed03540c461e7c
This should make sure the tests still work, even if the running
node is heavily overloaded.
Bug: T143389
Change-Id: Ic40c8d76c8799c2e9d11f53945276747c199fd02
Iaa880531 added extra frames in the call stack, so the frame being
tested by the "setfenv invalid level" and "getfenv invalid level" tests
was no longer invalid.
Bug: T175065
Change-Id: Id1028e7c8bbb92fb9d7d01ebeabd94e8ba284b1c
The core {{urlencode:}} parser function doesn't encode various
characters in WIKI mode that it does in other modes. mw.uri.encode
should match that.
Bug: T174239
Change-Id: I2be0811cf39c02c5c0ad3433e4b0ef9030350e24
Make the language cache size configurable, and increase the default from
20 to 30. It needs to be fairly small on default installations, but can
be essentially unlimited if $wgLocalisationCacheConf['manualRecache'] is
true.
Bug: T85461
Change-Id: Idb17691b30b0d2565a1624e5159df7d9b795764d
I252ec046 noticeably broke things by adding a dependency on the pcntl
functions, which tend not to be present under Apache.
It also subtly broke exit handling by using proc_close()'s return value,
which PHP mangles in such a way that we can't tell the difference
between an actual XCPU kill and exit( SIGXCPU ). This one wasn't noticed
because the pcntl functions interpret everything proc_close() is going
to return as a signal kill and we didn't test the 'exited' code path.
I'm not sure what was going on in I57cdf8aa since it provides no details
about what it was trying to fix, but that would have broken signal
handling in the other way: Ibf5f4656 worked because proc_open() on Linux
executes the command by passing it to /bin/sh -c, and that shell is
going to turn any signal that kills Lua (e.g. the SIGXCPU) into an exit
status of 128+signum.
To avoid proc_close()'s broken return value while also avoiding the
race, we can loop on proc_get_status() until $status['running'] is
false.
To have signals that kill Lua actually be interpreted as signals, we
have two options: add an "exec" in front of the command so proc_open()'s
/bin/sh -c is execed away, or detect shell-style signal reporting and
convert it. We may as well do both.
Bug: T128048
Change-Id: I8a62e1660fe1694e9ba5de77d01960c1ab4580aa
When investigating a test failure on T155600 I found the title
'scribuntotitletest:Module:TestFramework' to be rather obscure. Had to
browse the code to findout 'scribuntotitletest' is an interwiki prefix.
Update TitleLibraryTest php/lua and change the interwiki prefix to the
more meaningful 'interwikiprefix'.
Bug: T155600
Change-Id: Iec63734c82b0835a7f2444ea9af35617876831d5