Commit graph

100 commits

Author SHA1 Message Date
Brad Jorsch 821ba409d8 (bug 47268) lang:parseFormattedNumber should return a number, not a string
The documentation, and the expectation of users, is that
lang:parseFormattedNumber() should actually return a number, not a
string.

Bug: 47268
Change-Id: Ieabddd0d9192f1fd8ef7e890d5d6268be9636f38
2013-04-15 20:53:47 -04:00
Brad Jorsch 581b2306af Remove mw.getLogBuffer and others from public interface
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
2013-04-14 23:59:07 +00:00
Brad Jorsch ca3b0b55b2 Add timezone support to mw.lang:formatDate
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
2013-04-02 23:15:16 +00:00
Brad Jorsch 71d9f600dc (bug 46294) Fix for Windows text-mode file handles
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
2013-04-02 23:05:38 +00:00
Brad Jorsch adb7b5f939 Make pairs() work with various library objects
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
2013-04-02 17:23:42 +00:00
Brad Jorsch 4374903e83 (bug 46635) Recognize Windows path+drive letter
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
2013-03-29 09:26:13 -04: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 3d4a81653c (bug 46405) Fix errors in mw.title.new( pageid )
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
2013-03-21 09:39:25 -04: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 541e61a1c4 (bug 41769) Add frame:callParserFunction() and frame::extensionTag()
Requires change I339b882010dedd714e7965e25ad650ed8b8cd48f to
mediawiki/core.

Bug: 41769
Change-Id: I0138836654b0e34c5c23daaedcdf5d4f9d1c7ab2
2013-03-18 13:46:26 -04:00
Brad Jorsch 53c46561ab Don't record self-link from mw.title
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
2013-03-17 14:55:04 -04:00
jenkins-bot b59117fbdd Merge "Portable DIRECTORY_SEPARATOR :)" 2013-03-14 14:35:13 +00:00
Jens Ohlig 8fd450269c Portable DIRECTORY_SEPARATOR :)
Change-Id: I61d2ddc5367c2ffacd68c12bf9b6037cfc39d487
2013-03-14 15:09:45 +01:00
Brad Jorsch b6ea64f132 Make mw.getCurrentFrame() work in console, add frame:newChild()
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
2013-03-12 14:42:36 +11:00
Brad Jorsch 5faa00150c (bug 45684) Don't count argument parsing time towards Lua limit
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
2013-03-12 03:18:05 +00:00
Chad Horohoe 3ac6904790 Missing global
Change-Id: I78fc2acd31dd2969971e23239d5c820d867a204c
2013-03-11 14:55:23 -04:00
Brad Jorsch 466ba8668e (bug 45774) Add title.fileExists, improve title.exists
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
2013-03-08 10:33:35 -05:00
Brad Jorsch b926846a7a mw.title:getContent() should record in templatelinks
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
2013-03-07 13:02:41 -05:00
jenkins-bot efe2def71a Merge "Add language functions" 2013-03-07 00:05:54 +00:00
Brad Jorsch e004b415d6 (bug 45512) Add mw.title:getContent()
Bug: 45512
Change-Id: I630033d367a47f7f80809a0918d3e6feede3fe41
2013-03-05 19:05:00 +00:00
jenkins-bot 61a4dccabd Merge "Clean up argument lists" 2013-03-05 18:49:53 +00:00
jenkins-bot fc766f205a Merge "Fix mw.uri error with empty fragment or query string" 2013-03-05 18:49:06 +00:00
Brad Jorsch fcef54e9d9 Fix ustring errors
* 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
2013-03-05 12:22:15 -05:00
Brad Jorsch 328680ed96 Add language functions
RTL support, duration formatting.

Change-Id: I78db53976abfe04fd6529b36c9434e33a3bc90c7
2013-03-04 21:14:34 -05:00
Brad Jorsch 580cda00d0 Fix mw.uri error with empty fragment or query string
Off-by-one error.

Bug: 45655
Change-Id: Ic6e0dfe8dbf392b1fe9e225f7906b4dd84f4febf
2013-03-05 01:44:10 +00:00
Brad Jorsch 5e548e769a Add requirable bit32 library
Following the interface of the Lua 5.2 bit32 library.

Change-Id: I4bc9edc549dbc2d5fdca15ec3a326397a1212a8a
2013-03-05 01:36:17 +00:00
Brad Jorsch e995922bf4 Clean up argument lists
Remove unused parameters from the require() argument lists of two
modules, left over from an earlier phase of development.

Change-Id: Ib55d19fb9adffed2153a9cb3788533c4b70b5e26
2013-03-04 14:55:46 -05:00
Brad Jorsch 69a717c5ba Fix title library saving
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
2013-03-01 11:07:45 -08:00
Brad Jorsch 307a5b1be8 Clean up lualibs
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
2013-02-28 18:39:16 -08: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 00d4b711ed Add mw.loadData, for static data loading
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
2013-02-21 23:03:53 +00:00
Tim Starling 96615c97b0 Explicitly destroy the loadedLibraries array
Otherwise there is a circular reference and the engine is not destroyed
until the end of the request.

Change-Id: I9c98fe449c19d22e771e11d485e5516059c45329
2013-02-18 10:41:12 +11:00
Brad Jorsch 2d36fbc492 Scribunto language library
Added a language library. Introduced functions which are easy and safe,
most of them already have parser function interfaces.

Change-Id: I4465150f3e16493a15a056f7ddb7787bdf3b0373
2013-02-18 10:41:12 +11:00
Brad Jorsch 4ff1dbd6a7 Document Scribunto_LuaEngine
Some parts of this that really should be documented aren't. Fix that.

Change-Id: I058f47a08a7529a8d2a70e5b50e4532db7bdb720
2013-02-15 18:42:07 -05:00
jenkins-bot 2980cf4c11 Merge "Fix mw.ustring.gmatch and patterns with '^'" 2013-02-15 08:22:11 +00:00
Brad Jorsch 1efe182e40 Hide mw.makeProtectedEnvFuncs from modules
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
2013-02-14 16:49:15 -05:00
Brad Jorsch 4dcac2fcd9 Fix mw.ustring.gmatch and patterns with '^'
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
2013-02-14 14:25:55 -05:00
Chad Horohoe c98cc64545 Allow extensions to add libraries
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
2013-02-14 12:38:03 -05:00
Tim Starling ce062407ab Fix further non-local effects of library registration
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
2013-02-13 15:40:18 +11:00
Tim Starling f2f866cbdd Remove global side-effects from mw.ustring library registration
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
2013-02-13 15:05:22 +11:00
Tim Starling 2d9e3c74ba Merge "Lua ustring implementation" 2013-02-13 03:32:43 +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 d6116fa6ba Make pairs and ipairs work with frame.args
Using the 5.2 compatability added in I37efc59a, we can now make
pairs( frame.args ) work.

Change-Id: Iefdca8805b08ea222251f28514b2c92182a7feb3
2013-02-12 06:41:33 +00:00
Brad Jorsch fddf05c056 Make our loader work like Lua's built-in loaders
Our loader for lua files distributed with the extension doesn't work
like Lua's built-in loaders. Fix that.

Change-Id: I7576f0e173c10a589f7ebf2c121230ed66b538fe
2013-02-08 14:20:32 -05:00
Chad Horohoe 3055ac6aa3 Clean up title handling for defaultUrl
getParser() sometimes returns null (eg: on saving edits), so use
the engine's title instead.

Change-Id: I62259b76d6960a934b5e208fdaacbbfc7c2d057c
2013-02-07 15:45:49 -05:00
Brad Jorsch db9fd2b39b Add mw.uri library
Change-Id: I1d94a8c288537ada038f24f2ec26922d95f14785
2013-02-07 13:31:24 -05:00
Chad Horohoe 04b207829e $wgServerName doesn't exist anymore
This is a followup to I944938f9. I had kind of forgotten that
we removed $wgServerName.

Change-Id: I846cba6853f1a3a09f4e2d362960fea5f60bfcc3
2013-02-06 10:24:59 -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