Commit graph

93 commits

Author SHA1 Message Date
jenkins-bot 1fa52ef583 Merge "Allow for dynamically-loaded PHP libraries" 2014-10-03 14:01:46 +00:00
Brad Jorsch df38a296bf Allow for dynamically-loaded PHP libraries
Scribunto currently supports libraries with PHP callbacks that are
loaded on startup, and pure-Lua libraries that may be loaded from the
module with require().

This change allows for libraries with PHP callbacks to also be loaded
with require().

Change-Id: Ibdc1f4ef51b1c8644c3d4c98d57755b5c06447a5
2014-10-03 09:27:23 -04:00
Jackmcbarn ccba1c78f5 Allow numbers in tag names
HTML tags can contain numbers, like <h2>.

Bug: 71594
Change-Id: I3b7bbfa3aa8f41a28f8ce64086e4066ffda948b2
2014-10-03 07:52:17 -04:00
Jackmcbarn 634f75f53e Don't escape the delete character
Escaping the delete character breaks strip markers, so don't do it.

Bug: 68011
Change-Id: Ica97c898209c59c0084bf700d891b28603f79dd1
2014-09-21 22:59:52 -04:00
Jackmcbarn b970046f2e Don't output a semicolon at the end of CSS
It's not necessary, it makes the output bigger, and some pages have enough
elements with CSS that it does make an actual difference.

Change-Id: I80d471899c7e04a8a4876c205198a8c0d0b1f281
2014-09-10 19:08:34 -04:00
Jackmcbarn f5894a6a9f Output &nbsp; instead of &#nbsp;
Bug: 70475
Change-Id: I19aeceaa1eed17be4a128acd7fb50a9c8b40cf12
2014-09-08 16:06:34 -04:00
Jackmcbarn ef6e2fa410 Fix __pairs not working in LuaStandalone serialization
In Ia4d58f44, the code enabling __pairs to work no longer ran inside
MWServer.lua, so it hasn't worked right for serialization since then. This
restores the correct behavior.

Change-Id: Iea31ab363957f5f69838d6715527cf822c15fa94
2014-08-27 21:09:05 -04:00
Jackmcbarn fd9ecb9cbe Expose cascading protection directly to Lua
Add a way to fetch cascading protection information from Lua without
needing to call the CASCADINGSOURCES parser function.

Change-Id: I1b3ac18af11d3066f78d27b31da8d6709a6a2631
2014-08-13 12:34:47 -04:00
Brad Jorsch 0367e9bddd Fix deceptively-simple pattern in pure-Lua ustring
The pure-Lua ustring pattern matching functions short-circuit to the
much faster string library when the pattern would match the same against
the raw bytes.

A pattern like "[^a-z]" can match a partial UTF-8 character when applied
bytewise, and so must be detected as unsafe.

Let's also directly test the pure-Lua module, instead of me having to
comment out lines in Scribunto_LuaUstringLibrary::register() whenever I
want to test them.

Change-Id: I91ed3374aadfea379b9db2e13b4248ab20df509e
2014-08-10 01:18:18 +00:00
Mr. Stradivarius 1d13fd503a Simplify mw.text.listToText
Simplify the logic in mw.text.listToText so that we don't need to add or
remove anything from the original table we were passed.

Change-Id: I3efcbba1b9adc9a9e32e366e355cb742376cd91b
2014-07-14 19:32:33 +09:00
jenkins-bot ef40ccc8b1 Merge "Fix wrong variable in ustring.lua" 2014-07-11 17:50:03 +00:00
Jackmcbarn ee289c8045 Make the cssEncode pattern simpler
The pattern used by cssEncode is unnecessarily complicated. Simplify it by
using a negating pattern.

Change-Id: I5dc7169efea63473e9e23a1450d2941e434a00d8
2014-07-11 11:40:57 -04:00
Brad Jorsch cb2a331565 Fix wrong variable in ustring.lua
Change-Id: Ibc8056b36d615b57d357987c59219a22e63fdfe8
2014-07-11 11:25:35 -04:00
Jackmcbarn 7c51f69901 Create mw.dumpObject split from mw.logObject
Add an mw.dumpObject() method, which converts an object in the same manner
as mw.logObject(), but returns it instead of adding it to the log buffer.

Change-Id: Ie9fbd24d9d8d13ee2ddf8052679010892f61e1e0
2014-07-09 10:30:53 -04:00
Jackmcbarn 40b8bd2caa Add comments and remove trailing whitespace
Clean up trailing whitespace from all of our code, and add comments
indicating that apparently unused variables are ScopedCallbacks.

Change-Id: I8e5997797cc7b1c64c5351ec112a18f30edc8fef
2014-07-07 14:46:59 -04:00
Brad Jorsch 85aca87e94 Improve mw.getCurrentFrame handling
Two similar bugs are handled here:
* mw.getCurrentFrame() doesn't work when the module is loaded (only when
  a function is called), which breaks os.date and os.time at module
  scope since I59ad364d.
* mw.getCurrentFrame() gives access to frame args from inside
  mw.loadData, which allows for data leakage between #invokes.

Bug: 67498
Bug: 65687
Change-Id: I82dde43e2601b59c03c6ed4b9365829c40a953a5
2014-07-07 13:11:20 -04:00
Jackmcbarn 8d1d5ac84c Fix strange mw.html errors with numeric arguments
Some functions in mw.html accept numbers as arguments, but later fail when
constructing the string. This disallows numbers in attribute names, since
they aren't valid anyway, and fixes the remainder of the cases to properly
build the string.

Bug: 67201
Change-Id: Ie7bcbb9d8df580dd8793681f78a8b0719d8a287a
2014-06-27 14:41:42 -04:00
Brad Jorsch bf39827980 mw.ustring functions should accept numbers where string functions do
Lua's string functions tend to auto-convert numbers to strings. We
should do the same in mw.ustring.

Bug: 67201
Change-Id: Icd3c5e93bac19dafd78d737ec9b315daba9f1729
2014-06-27 12:31:04 -04:00
Jackmcbarn 780d8e1ec7 Set TTLs on outputs containing times
When os.date, os.time, or mw.language:formatDate are called, set the
appropriate TTL on the output. This needs I412febf3 in core to function at
all, and I3f5a80aa in core to function with formatDate.

Change-Id: I59ad364d502fc247500d94c5606516ad9f98a24d
2014-06-23 15:52:17 +00:00
Jackmcbarn d1030989bc Allow passing nils to mw.html
Rather than calling error() when nils get passed to mw.html methods,
either remove whatever it was that the nil would go to (if that makes
sense), or just do nothing. The seemingly inconsistent use of "not x" and
"x ~= nil" is to allow any falsey value where it wouldn't be ambiguous
(such as class names), but not where it could be (such as attribute values).

Bug: 62982
Change-Id: I76773abbb4394aa9bb8c8a08445e019cade3b2bf
2014-06-19 11:40:39 -04:00
Jackmcbarn 1201618b7d Keep modules' export tables inside Lua
When tables are passed from Lua to PHP, their metatables are lost. Because
of this, they need to be kept inside of Lua to allow the __index
metamethod to return a method to be called by #invoke.

Bug: 64141
Change-Id: I0840bc12b25dee72828ec97d2b205812e4929f2b
2014-05-26 20:01:18 -04:00
Jackmcbarn 1492ac3d68 Avoid running all of mw.lua twice
LuaStandalone only uses 2 functions from mw.lua, so move them to their own
file to avoid running the whole thing twice.

Change-Id: Ia4d58f44be17f7a71666dbe750e66d9d90cb5c2f
2014-05-15 14:15:08 -04:00
Jackmcbarn e19a1404f4 Use do...end to restrict scope
Creating and calling an anonymous function to create a scope is prone to
breakage, and only works because the last token before it is a numeric
literal. Do...end is designed for this purpose, so use it instead.

Change-Id: Ic33321086d5469bf97301b434c5a660f04120662
2014-05-14 13:43:13 -04:00
Brad Jorsch 35ee461a0b Improve frame:callParserFunction argument validation
From wikitext, $parser->callParserFunction() will always get an array of
strings with at least an element [0]. Let's match this from Scribunto:
stringify numbers, and require that [0] (although in Lua it'll be [1]).

Also fix an old broken unit test.

Bug: 63597
Change-Id: Ie7ac34ae4bce70cec455d90c3f02a658644f6866
2014-05-13 05:14:07 +00:00
Jackmcbarn b0de034ffe Use correct variable in require()
Use modname instead of the nonexistent name in the error message if
require() is passed the wrong type of parameter.

Change-Id: I2e96d283e34a16e4675141ce8ccddbcc045ef2a1
2014-04-20 18:57:03 -04:00
Alexander Jones 1ec95a7bba Accept mw.title object as the title argument of frame:expandTemplate()
This commit fixes an error with using a mw.title object referring to a
mainspace page as the title argument to frame:expandTemplate(), by
adding a leading colon to prevent the function from searching in the
Template namespace.

Bug: 47601
Change-Id: I4cdc05571598bf7998f4cf0f2691bf86188c3c5d
2014-04-10 10:32:40 -05:00
Brad Jorsch 708d87c181 Prevent passing information between #invokes using math.random
It's possible to pass information between multiple #invokes on a page by
having the first call math.randomseed with one of a set of known seeds
and then having the second examine the output from math.random to
determine which of those known seeds was used.

Prevent that by calling math.randomseed( 1 ) when invoking (see the bug
for details on why that seed). But avoid doing so if e.g. a
frame:expandTemplate() call results in a recursive invoke.

Bug: 62291
Change-Id: Id01cb63eca52ced29bf4efebc38beb9f159b7b0e
2014-04-01 13:46:09 -04:00
Jackmcbarn 2b06e83816 Remove message formats other than plain
Message formats other than plain should have never been exposed in this
way, as they allow link tables, etc. to be bypassed and serve no useful
purpose. This removes them, and also removes title, as it serves no
purpose without them.

Bug: 60758
Change-Id: I96284ffbe986a9cd92d2bde1ffdb746029bad989
2014-02-03 15:29:39 -05:00
Marius Hoch aa943d5795 Validate the type of the tagName given to mw.html.create
Change-Id: I35f70701ba6156325dfd268903452e6279aca528
2014-01-31 02:08:11 +01:00
Jackmcbarn 9902ec1284 Add protectionLevels variable to mw.title output
Include a protectionLevels variable in the output of the mw.title.*
functions, containing the contents of the title's mRestrictions
array (i.e., its protection levels)

Change-Id: I79c9fed64bacfc90aee1d411a3e1b47e44c99755
2014-01-15 14:53:18 -05:00
jenkins-bot b34e466b18 Merge "Add mw.html to Scribunto" 2014-01-07 14:09:46 +00:00
Marius Hoch ac62e34952 Add mw.html to Scribunto
A module for building complex HTML from Lua using a
fluent interface. The module is originally from enwiki,
but the authors allowed us to reuse it under GPLv2+
(as stated in the file).
The module will be loaded per default and comes with
unit tests.

As discussed on wikitech-l:
http://lists.wikimedia.org/pipermail/wikitech-l/2013-December/073320.html

Change-Id: I7c8d4378091c13d5ace0dd1fcbb4e27163e8c896
2014-01-03 00:04:34 +01:00
Brad Jorsch 3ced70adb8 Provide access to Language::getFallbacksFor()
The other fallback-related functions in PHP all seem to be based on
this.

Bug: 48328
Change-Id: I4b54ab0c1e1535529f47443f6d0e72a59d3d120c
2013-12-16 14:12:47 -05:00
Brad Jorsch fcb6d9ff92 Add access to Language::fetchLanguageNames
Apparently this is useful on Commons, where they would like to iterate
over all language names in some of their templates.

Bug: 47833
Change-Id: I6e3291bedc72da6630c485ea9bf381d8d2f5453a
2013-12-10 12:22:09 -05:00
Brad Jorsch 0763e22292 Expose PPFrame::getTitle to Lua
This field already exists in PHP with exactly the content requested in
bug 47089, so we may as well expose it on the frame object.

Bug: 47089
Change-Id: I672820589f6ebc7c4daad29b5eb156733a5bc5cc
2013-12-10 04:26:03 +00:00
jenkins-bot a18a762fd7 Merge "Add mw.isSubsting()" 2013-11-06 18:26:56 +00:00
Brad Jorsch d4331f0c96 Add mw.isSubsting()
It's already possible to detect whether the current template is being
substituted via ParserFunctions (see [[en:Template:Ifsubst]]), and a
similar trick works with frame:preprocess. So we may as well provide the
flag directly.

Bug: 47828
Change-Id: Id06d27c6283ee589a8830b78c04e56978e0ac6da
2013-10-31 22:05:00 -04:00
Brad Jorsch ec2f67c7ea Regularize whitespace handling in mw.title
Specifically:
* String conversion in non-URL contexts (e.g. .prefixedText) uses spaces
  instead of underscores.
* Setting .fragment now applies the same transformations that are done
  (in PHP) by mw.title.new.

Bug: 56217
Change-Id: I12e354636bcde3327864088175fb4de61aecc81a
2013-10-31 11:54:26 -04:00
Brad Jorsch 18f858314a Fix frame:extensionTag when not passed args
Bug: 55436
Change-Id: I82b638e89be1d57c941cc4534dc44944a7389740
2013-10-07 14:43:05 -04:00
Brad Jorsch a0a1b05b74 Improve mw.text.nowiki, part 2
The following are now correctly escaped:
* Blank lines (including those with only tabs)
* ---- at the start of a line

Bug: 53658
Change-Id: Ib000ff4f21f76c310741de89de0e0b66f6450344
2013-09-20 13:17:38 -04:00
Brad Jorsch 29eb0f4ea6 Improve mw.text.nowiki
The following are now correctly escaped:
* Space at the start of a line
* Start-of-line characters after \r
* Magic links such as "RFC 123" with non-space whitespace
* URIs that don't use "://", such as "urn:foo"
* Double-underscore magic words

Bug: 53658
Change-Id: I824417e2937dd27cd1e69bd4e74ab7d21a978c75
2013-09-03 17:36:36 -04:00
jenkins-bot 99b96d8b14 Merge "Add frontier pattern (%f[set]) to ustring" 2013-08-30 06:22:40 +00:00
Brad Jorsch d9ba200571 Add mw.logObject
People have requested a method to log a table as something more detailed
than just "table", to be able to inspect values while debugging.

Bug: 48173
Change-Id: Ia58cab834e87842927a2a13d153ee32473f74086
2013-07-26 05:15:20 +00:00
Brad Jorsch d8314539da Fix mw.ustring edge cases
A few edge cases were being incorrectly handled:
* mw.ustring.sub( 'abc', 1, 0 ) returned 'a', not ''.
* mw.ustring.codepoint( 'abc', 1, 0 ) returned 97, not no results.
* mw.ustring.codepoint( 'abc', 4, 4 ) returned 99, not no results.
* mw.ustring.gcodepoint had the same issues as mw.ustring.codepoint.

Change-Id: Ib8c0ef5a8073106eb7d90d0aa0513be4525dca08
2013-07-03 11:49:52 -04:00
Brad Jorsch 82820aafc8 Add frontier pattern (%f[set]) to ustring
The "%f[set]" frontier pattern has been in Lua 5.1 since the beginning,
but was undocumented until Lua 5.2. And the code is even unchanged from
5.1.0 to 5.2.1. So there's no reason not to implement it in ustring too.

Note the changes to UstringLibrary.php are somewhat large, because it
splits the "convert a Lua bracketed charset to PCRE" code into a
separate function and it changes the handling of mw.ustring.find's and
mw.ustring.match's 'init' parameter from "substring, match from 0, then
add back on $init" to "use preg_match's $offset and use \G instead of ^
where this matters". Both of these are necessary to properly support
%f.

This also fixes a bug in the pure-Lua code (not used in Scribunto)
exposed by the unit tests for %f where %z was matching '\1' rather than
'\0' and %Z everything except '\1' instead of everything except '\0'.

Bug: 48331
Change-Id: Ie0b95ef5b734db53d6adc9de5dae4874f8944c08
2013-05-12 10:27:36 -04:00
Brad Jorsch d6f3633428 (bug 47365) Fix edge cases in mw.ustring.find, mw.ustring.match
The following errors are fixed:
* PHP warning and wrong return value with empty pattern and plain
* Incorrect offsets returned when init is larger than the string length
* Incorrect captured offsets returned when init is excessively negative

Bug: 47365
Change-Id: I9741418287dc727747326d6a19678370ce155a2b
2013-05-10 06:00:02 +00:00
Brad Jorsch 3622f82bd1 (bug 47300) Fix sandboxing with require
Two related issues:
* The package module was inheriting the loaders from the outer sandbox,
  so loaded modules were being loaded into the outer sandbox's
  environment.
* mw.loadData was using the outer sandbox's require(), so again loaded
  modules were being loaded into the outer sandbox's environment.

Bug: 47300
Change-Id: I48d8dd4784c9a890e3abb6389f96f38e1420dbbb
2013-04-24 06:19:44 +00:00
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 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