The documentation, and the expectation of users, is that
lang:parseFormattedNumber() should actually return a number, not a
string.
Bug: 47268
Change-Id: Ieabddd0d9192f1fd8ef7e890d5d6268be9636f38
One of the design goals of Scribunto is that each #invoke should be
independent. Creative use of mw.log and mw.getLogBuffer can get around
this, passing information from one #invoke to the next.
This patch takes the simple solution of removing mw.getLogBuffer from
modules' environments. For good measure, it also removes
mw.clearLogBuffer and mw.executeModule.
Some minor cleanup of the console code is also included.
Change-Id: I30d73928bade4a6bdd7c00ffcd58a3858ff55698
This uses the timezone support added to core Language::sprintfDate in
Iea1f7842 to add support for various timezone-related formatting
characters, and to correct the output for 'c', 'r', and 'U' in local
mode.
This is related to bug 33454, which requests the same for
ParserFunctions' {{#timel:}}.
Bug: 33454
Change-Id: I1b92dc671051a6cc53e35ebd74d383448e16696c
On Windows for LuaStandalone, the lua executable's standard output is a
text-mode file handle, even if the pipe is opened from PHP with the
binary flag. Which means that when Lua returns a "\n", it gets silently
rewritten to "\r\n" and the unserialization fails.
So, change the protocol for Lua→PHP messages to encode \r and \n (and \
itself, as the escape character) to avoid this issue.
Bug: 46294
Change-Id: I73b5f44e8aa0334f5fd03013dc027d1a57318349
Users are reporting disappointment that using pairs on title objects
doesn't let them see the fields available. It's easy enough to add a
__pairs metamethod to allow pairs to work on title objects, so let's do
that.
The same can be done for mw.uri objects.
For mw.message objects, we can easily enough change the implementation
to be like mw.language objects, which doesn't have this problem.
For mw.site.stats, we may as well just remove the load-on-demand feature
since it will be demanded as soon as the environment is cloned for the
first module.
Change-Id: Ie5a3b5684b2bb6c090f9994baa03977687688929
The logic for recognizing absolute versus relative paths needs to take
into account the possibility of a Windows drive letter.
Bug: 46635
Change-Id: I3a43acac2f6e8b481807e1babe5a261b9eb1fe23
Use the SoftwareInfo hook to add the versions of LuaSandbox and Lua to
Special:Version.
Bug: 39655
Change-Id: I912197efee0211066677c4d46e638fb546a410c6
mw.title.new( pageid ) should not throw an error for an nonexisting
pageid, just return nil. Similarly, it should always return nil for 0,
rather than returning the last non-existent title created.
Change-Id: I3cdbb24fc785aef0f8e75fba1feccd26ac5b7370
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
Every Lua-using page loads the "self" title for mw.title. But we don't
want to record this self-link in the links table, because that confuses
people.
Change-Id: I1ef57daa615c176b7789f5f09bd15ee5b292ad0c
It would be helpful for debugging if a frame object could be gotten in
the console. To that end, add an empty frame when running in the console
and allow it to be returned by mw.getCurrentFrame().
It would also be helpful to be able to create frames with arbitrary
arguments, again for testing. Fortunately support for creating child
frames with arbitrary arguments already exists in core, so we can just
use it.
And for good measure, be sure to restore the $engine->currentFrames
array even if the Lua code throws an exception.
Change-Id: I1dc8602d63af75424f267c42a3743fabbc1827f7
Currently, the time taken to parse the arguments passed to a Lua
function from #invoke will be counted against Lua's 10-second limit.
This is counterintuitive, and can remove incentive for users to convert
templates to Lua since they may have to convert a whole stack at once.
Note this requires change I11881232 to mediawiki/php/luasandbox to
actually have any effect.
Bug: 45684
Change-Id: I773950e4c399b8a1cfa6d1cde781a069d286b3bd
People sometimes want to know if the actual file exists, not just the
file description page. Support that.
Also alias .exists to .fileExists for the Media namespace, since that's
what the Media namespace is for.
And while we're at it, fix .exists for special pages too.
Bug: 45774
Change-Id: I019adc89858a1d32995a38d5e8eef32577fd32d6
Since the content of a page is being loaded, this should be recorded in
templatelinks so things can be updated properly when that page is
edited.
Change-Id: I3e720fee2705f6c08ac0456c3cab0ed4ede84536
* mw.ustring.sub( '', 1 ) errors in LuaStandalone
* Default value for ustring.maxStringLength and ustring.maxPatternLength
should be infinity, not nil
* mw.ustring.find() returns one value instead of two in "plain" mode.
Change-Id: I5e65c4ec3a05f0e6930ce7ab7fd4ac72bea95e7f
Remove unused parameters from the require() argument lists of two
modules, left over from an earlier phase of development.
Change-Id: Ib55d19fb9adffed2153a9cb3788533c4b70b5e26
getParser() sometimes returns null (eg: on saving edits). In that case,
don't try injecting link information into the (non-existent)
ParserOutput object.
Change-Id: Ief544922228615fbf674305bff95f874d56b7866
Clean up the modules in engines/LuaCommon/lualib:
* Fix luabit/bit.lua to return its table instead of trying to set the
global directly.
* Fix luabit/hex.lua to return its table instead of trying to set the
global directly.
* luabit/noki.lua is useless for our purposes
* luabit/utf8.lua is redundant to mw.ustring
* stringtools uses coroutines, which we don't support
Also fix a parser test that has apparently been broken for a long time.
Change-Id: I1284cddb6e9b94327964cb1077d8dbdf7def6d06
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
People sometimes want to load large tables of constant data from a
module. Using require(), this has to be reparsed every time, which can
be slow.
mw.loadData() will load the just data once, and return a table with a
metatable cleverly designed to give read-only access to the loaded data.
Change-Id: Icec192bdbe6cfca7902fd5cb5d0e217bd8399637
Otherwise there is a circular reference and the engine is not destroyed
until the end of the request.
Change-Id: I9c98fe449c19d22e771e11d485e5516059c45329
Added a language library. Introduced functions which are easy and safe,
most of them already have parser function interfaces.
Change-Id: I4465150f3e16493a15a056f7ddb7787bdf3b0373
Allowing a module to call mw.makeProtectedEnvFuncs() lets it bypass the
allowEnvFuncs setting. It can also be used to manipulate the global
tables that other modules' sandboxes will be copied from.
And for paranoia's sake, let's tighten up what setfenv is allowed to
set. This requires changing a unit test, because it is no longer
sane to do something like
env.setfenv, env.getfenv = mw.makeProtectedEnvFuncs( { [env] = true }, {} )
Nothing real does this, it was only in the unit test.
Change-Id: I8e0d83bb0980ee869af3ac4413afd211717ca92f
The Lua manual says this:
For this function, a '^' at the start of a pattern does not work as an
anchor, as this would prevent the iteration.
I had interpreted that to mean that a pattern starting with '^' would
never match in gmatch. But further testing reveals that the '^' is just
treated as a literal character: string.gmatch( "foo ^bar baz", "^%a+" )
will match "^bar".
Change-Id: Id91d6ee2db753ce1d6a4f6ae27764691d9e9fdc4
Wikidata has already requested the ability to add libraries into Lua. We
do this in a simple way: add a $wgScribuntoExtraLibraries global, and
load whatever modules someone puts there.
Change-Id: I460b4e7b968eb02dd86620f1e4b50daf1be9e901
Fixed several accidental leaks to the global namespace due to missing
"local" declaration. Removed extension of the string table by mw.uri,
same justification as I5d0ddb70.
Change-Id: Iba1bf8e651d4ce05812e4a9a7a074cb6679297a0
The point of putting the unicode library in mw.ustring instead of
ustring was to avoid conflicts with future upstream work, and with other
libraries. It rather defeats the purpose if you then modify the global
string table during module startup.
Users can always set up local aliases if they feel "mw.ustring" is too
much to type.
Change-Id: I5d0ddb70d999aeb6e36e6ddbcdb19922d0274a39
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
Our loader for lua files distributed with the extension doesn't work
like Lua's built-in loaders. Fix that.
Change-Id: I7576f0e173c10a589f7ebf2c121230ed66b538fe