Commit graph

157 commits

Author SHA1 Message Date
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 ab722f3b08 Improve performance of PHP ustring
Cache patterns and the regexes they become, avoid revalidating the same
pattern multiple times, and don't bother checking if something is a string
when we just made it one.

Change-Id: I1a61dd0a36eb449c8acdc8c1be68aae793f172d3
2014-09-16 00:19:39 -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
jenkins-bot 96508a3215 Merge "Output   instead of &#nbsp;" 2014-09-08 20:37:05 +00:00
Jackmcbarn f5894a6a9f Output   instead of &#nbsp;
Bug: 70475
Change-Id: I19aeceaa1eed17be4a128acd7fb50a9c8b40cf12
2014-09-08 16:06:34 -04:00
Jackmcbarn 01c9ef5004 Set vary-revision appropriately with getContent()
When calling getContent() on the page currently being viewed, set
vary-revision on the parser output, as is done when a page transcludes
itself.

Change-Id: I908f095935067dc24dd561192b0699c602cb605f
2014-09-05 17:04:46 -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
addshore e29c8eda63 Use public instead of var in classes
Change-Id: I0c059515cbf0fa8ef3846526a989f1a322fcd8ae
2014-08-17 22:11:26 +01: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
Brad Jorsch 410229c312 Expose mw.log data on preview
People have been complaining that they can't find the log data anywhere.
The new parser limit report seems a good place to show this information.

Change-Id: If2abf27f7779d92ff7c7a1f32b2a54a5de521678
2014-07-07 16:14:30 -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 e65638777a Show blanknamespace in content language
This is cached with the page.

Change-Id: I62335dd37c411dc5dc77ac7564c6fa6361679ac3
2014-06-30 11:44:47 -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
Brad Jorsch ccab415701 Don't cache volatile wikitext
Certain wikitext, such as that containing Cite.php <ref> or <references>
or the #tag versions of the same, should not be cached. This uses the
isVolatile method added to PPFrame in I95b3cf87 to avoid caching the
preprocessed output of such wikitext from frame:preprocess and similar
methods.

Bug: 46815
Change-Id: I1084f87fd863eb22f2f3f3d3ff308b24e20a08ef
2014-06-26 22:03:35 -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
jenkins-bot 996a48e42c Merge "Remove dead code" 2014-06-19 18:45:14 +00:00
jenkins-bot 8d7d5f35ed Merge "Allow passing nils to mw.html" 2014-06-19 16:57:02 +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
Marius Hoch 9e6b67c723 Remove dead code
Just confusing...

Change-Id: I8b6e3d290c8ae75159e86835a0d359a4dcaa7a0e
2014-06-18 19:56:39 +02:00
Reedy 4d0665dbd8 Parameter type hints
Change-Id: I3d578ab6fb65917ef0fa65767089b01ca7c4e96d
2014-06-18 18:19:07 +01:00
Brad Jorsch ec7472a0e5 Sanity check $wgNamespaceAliases
If someone goes and adds aliases for namespaces that don't actually
exist (as was done in I94c34799, for example), Scribunto will run into
issues when trying to create its mw.site.namespace objects.

Let's ignore those bogus aliases so we don't go breaking everything just
because someone did something stupid.

Change-Id: I16acd97f587de320cf61becb829cc66794cbb119
2014-06-17 14:23:26 -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
jenkins-bot 1504b474e4 Merge "Accept mw.title object as the title argument of frame:expandTemplate()" 2014-04-15 16:11:26 +00:00
Jackmcbarn d74c81c233 Add name to nosuchfunction and nosuchmodule errors
When displaying a nosuchfunction or nosuchmodule error, include the name
of the nonexistent function or module.

Change-Id: I17fc2c68dc8267302a82eee3cb2c5df9b5a3c46c
2014-04-13 21:29:05 -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
jenkins-bot 40d3685a50 Merge "Prevent passing information between #invokes using math.random" 2014-04-02 19:28:23 +00: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 55fd5f7bdd Remove limits on mw.language:formatDate()
Remove the 6000 character per page limit of mw.language:formatDate(). It
only exists because ParserFunctions has something like it for performance
reasons. Since Lua has a maximum execution time, there's no reason that it
needs this as well.

Change-Id: I42ae4f51295135007c6e2edc66ec36b7d96e3be3
2014-03-21 19:04:17 -04:00
Jackmcbarn 50a1f556b7 Remove leftover code for titles in messages
Since the code related to titles in messages was removed from
mw.message.lua, remove it from here as well. Titles have no effect since
only the plain format is available.

Change-Id: I0c96a4e831abe61100b48cb6a898ad8dbffd8a72
2014-03-18 13:52:51 -04:00
Jackmcbarn 18f177a3a9 Improve invalid title error message
Include the text of the title being complained about when returning an
invalid title error from expandTemplate.

Change-Id: I2261f9574557c3ae514c39cea71f9777f8f9f431
2014-03-11 17:06:23 +00:00
Brad Jorsch 29452c9bef mw.language: Fix exceptions and add tests
Various methods are throwing exceptions when passed invalid language
codes. Those need to be caught.

And we should really add unit tests for the mw.language library, too.
Doing so exposed another bug (in lang:gender), which is also fixed here.

Bug: 62242
Change-Id: Ib7d257cbb1ce179c510273526910d6ac5f3cac5d
2014-03-09 02:56:06 +00:00
Brad Jorsch ed54cd7032 Fix PHP implementation of mw.ustring %W
Incorrect regex is making it match basically everything.

Bug: 60908
Change-Id: Ic1c5a740c6b825bb7dfacf684d0c7fa905b135ee
2014-02-10 00:45:46 +00: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
Brad Jorsch 5cf28c5a15 Use a child frame in frame:expandTemplate
If we don't do this, then the section edit links point to the wrong page
if we expand a template that contains section headings.

Bug: 55525
Change-Id: I00bda935be3e8b9c0f86fd0f131814207fbb34a7
2014-01-30 22:47:31 +00: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