Wikipedia talk:Lua
| WP:Lua Project |
WT:Lua Project talk |
Help |
To do |
Resources en: m: mw: external |
| To help centralise discussions and keep related topics together, all Wikipedia:Lua subpages' talk pages and Help talk:Lua redirect here. |
| The content of Wikipedia:Lua/Requests was merged into Wikipedia talk:Lua on 5 February 2016. For the contribution history and old versions of the redirected page, please see its history. |
| Wikipedia:Lua/To do was nominated for deletion on 21 May 2015. The result of the discussion was keep. |
Archives |
|---|
|
|
| This page is archived by ClueBot III. |
Contents
- 1 Module:String
- 2 Saving modules
- 3 Is frame:getParent() efficient?
- 4 Passing wikitables as arguments
- 5 Lua table for airports destinations
- 6 ColPollTable
- 7 Different options
- 8 Module:Coordinates
- 9 trouble with Expansion depth
- 10 Module:Coordinates (used in other modules)
- 11 Sensitive IP modules and libLua
- 12 How mw.html.tag() works?
Module:String[edit]
Hey.
I was hoping for someone to create a new function to the Module:String.
The function will give the first line of a string
for example:
hello
world
what's
up
will give you hello Thanks in advance--Mikey641 (talk) 15:51, 22 July 2016 (UTC)
- This is not necessary:
{{#invoke:String|match|hello world what's up |^%s*.- |||}}→hello
Paweł Ziemian (talk) 18:46, 22 July 2016 (UTC)
- Paweł Ziemian Thanks alot!!!--Mikey641 (talk) 00:25, 24 July 2016 (UTC)
Saving modules[edit]
I am having difficulty saving a module and its documentation page. Is there anyone I can ask for help? --פוילישער (talk) 18:29, 26 July 2016 (UTC)
- @פוילישער: What happens when you try to save it? Could you give us a link to the pages you are trying to save, or maybe paste the content here if that's easier? — Mr. Stradivarius ♪ talk ♪ 22:46, 26 July 2016 (UTC)
- Thank you. The problem manifests itself on yiwiki. I was trying to save the code for Module:Infobox. You can find it in my sandbox (as part1). When I try to save it nothing happens.
Is frame:getParent() efficient?[edit]
There seem to be two ways for a module to get the parameters from the template that invoked it: one is to have the template explicitly pass all of its parameters, and the other is to have the module get all the parameters via frame:getParent().args. Does anyone know if one way is computationally cheaper that the other? Uanfala (talk) 13:13, 5 August 2016 (UTC)
- I do not know the implementation details, however I suspect that
frame:getParent().argsis better. The parameters passed to template are already parsed but using them while invoking the template need additional cost. But forget the details and try Module:Arguments, which make all the dirty things transparent and allows to mix various method including calling functions even from other modules. Paweł Ziemian (talk) 15:35, 5 August 2016 (UTC) - The two ways to get parameters into a module are:
frame.argsparameters from the template invoking the moduleframe:getParent().argsparameters from the page using the template
- You probably mean that wikitext in the template could attempt to pass the expected parameters so #2 would be a duplicate of #1. There is no reason to do that and modules are sufficiently fast to know that the overhead of getParent is trivial. Like Paweł Ziemian, I would expect that duplicating the parameters in the template would be a tiny bit slower because it would require MediaWiki to parse the parameters twice, whereas the getParent code is probably much more efficient. Module:Arguments combines the parameters from the above two methods. Johnuniq (talk) 01:16, 6 August 2016 (UTC)
- When Scribunto was first being developed, the ability to get arguments directly from
frame:getParent().argswas actually one of the big reasons that Lua modules were anticipated to be faster than wikitext templates. This is apparent from the design documents, which talk about a "substantial cost" for "every triple brace and every pipe". The speed of parsing wikitext improved greatly with the introduction of HHVM in 2014 (a year after the Scribunto rollout), but I am guessing that you could still get a considerable performance boost by switching fromframe.argstoframe:getParent().argsfor modules that accept a lot of parameters. To say anything for certain someone would need to run some benchmarks, though. — Mr. Stradivarius ♪ talk ♪ 05:30, 6 August 2016 (UTC)- More importantly, I can't imagine there being any downside to using
frame:getParent().argsoverframe.args, so you may as well use it. These days I mostly use Module:Arguments with the wrappers option, though, which has the same benefits as usingframe:getParent().argsand also allows you to use the same arguments with #invoke directly if you want. Module:Arguments also allows you to automatically trim whitespace and to remove blank arguments, which I find is almost always needed. — Mr. Stradivarius ♪ talk ♪ 05:38, 6 August 2016 (UTC)- Thank you everyone for the responses. I'll have a look at Module:Arguments (hopefully this isn't going to slow things down compared to frame.getParent().args?). Speaking of performance, I notice that for a few days now I haven't been able to see much in the Parser profiling data area at the bottom of the page when previewing an edit. This used to be a table containing information about Lua memory usage or template argument size, but now it only lists the number of Wikibase entities. Does anyone know anything about that? Uanfala (talk) 15:44, 10 August 2016 (UTC)
- More importantly, I can't imagine there being any downside to using
- When Scribunto was first being developed, the ability to get arguments directly from
Passing wikitables as arguments[edit]
Hello, it seems that passing Wikitables as arguments does not always work as expected. The internal "|" are apparently interpreted as parameter separators: see Commons:Module talk:Artwork. Does anyone have a solution, other than rewriting all templates to avoid Wikitables ? --Zolo (talk) 06:17, 12 August 2016 (UTC)
if you must pass a whole wikitable, have you triedframe:preprocess?- —Trappist the monk (talk) 09:16, 12 August 2016 (UTC)
- nevermind; wrong end of the process. It's not clear to me what it is that you are trying to accomplish with the module that isn't already accomplished by the template. You can, of course replace the content of the template with a module that writes the html of a table (HTML library). But why do that if the template does what it is supposed to do?
- —Trappist the monk (talk) 09:29, 12 August 2016 (UTC)
- this issue is not specific to lua - it is a general thing with passing tables as parameters to templates. basically, there are 2 ways to handle this: (1) replace the | and || with {{!}} and {{!!}}, or (2) use html tags for the tables instead of wikicode (i.e., <table>..</table>, <tr>..</tr>, <th>..</th>, and <td>..</td>). HTH, peace - קיפודנחש (aka kipod) (talk) 15:49, 12 August 2016 (UTC)
- Mediawiki parses the "|" character expecting a new parameter after it. To escape it, you have to use nested templates to escape this character. This was mentioned above by קיפודנחש (aka kipod) -- Don't forget that the same goes for the "=" character as well. -- Matroc (talk) 19:19, 12 August 2016 (UTC)
- Thanks for the replies. If I undestand right, you are saying that I should change the Wikitext passed by the parameters to make it work ? What I don't get is why the non-Lua version works fine but not the Lua-based sandbox, in cases like
{{Artwork|permission = {{PD-art}} }}. - @Trappist the monk: the template works, but is really not suited for integrating somewhat complex Wikidata retrieving features that would be really useful for internationalized artwork descriptions on Commons. --Zolo (talk) 21:31, 12 August 2016 (UTC)
- The module needs to get a wikitable as an argument only because a table is the only kind of output produced by the permissions template, right? Wouldn't it make sense then to change the permissions template so that it can optionally produce its output in another, more parseable, format? Disclaimer: I don't know much about either Lua or templates Uanfala (talk) 21:53, 12 August 2016 (UTC)
- Thanks for the replies. If I undestand right, you are saying that I should change the Wikitext passed by the parameters to make it work ? What I don't get is why the non-Lua version works fine but not the Lua-based sandbox, in cases like
- Mediawiki parses the "|" character expecting a new parameter after it. To escape it, you have to use nested templates to escape this character. This was mentioned above by קיפודנחש (aka kipod) -- Don't forget that the same goes for the "=" character as well. -- Matroc (talk) 19:19, 12 August 2016 (UTC)
- this issue is not specific to lua - it is a general thing with passing tables as parameters to templates. basically, there are 2 ways to handle this: (1) replace the | and || with {{!}} and {{!!}}, or (2) use html tags for the tables instead of wikicode (i.e., <table>..</table>, <tr>..</tr>, <th>..</th>, and <td>..</td>). HTH, peace - קיפודנחש (aka kipod) (talk) 15:49, 12 August 2016 (UTC)
Lua table for airports destinations[edit]
Hello everyone-that-are-well-of-Lua, any help would be greatly appreciated.
I know that one can pass wikidata<->Lua to write down a wikitable with information issued from wikidata, thanks for Mr Stradivarius.
I've started to work on an idea that would enable multilingual use of Wikidata to build for any airport XXX a table in which all linked airports would appear, and would be always up to date in any language [provided Wikidata is properly filled]. ==> The aim : prevent the fastidious work of updating airport pages.
For instance, this code (in french wikipedia) : {{Aéroport-Destinations|entity=Q17430|property=P521|P521|P931|P137|P521=Aéroport|P931=Ville|P137=Compagnie(s)}} would return the result shown in my page Utilisateur:Bouzinac. This code has been inspired of this one fr:Modèle:Tableau qualificateurs.
I'd like to have a finally simple template {{Aéroport-destinations}} which could be inserted into an airport wiki article.
This template would call a LUA script that will check and return all destinations for the said airport into a table with these properties =>
- "Airport name in short" (P1813)
- "City served by airport" (P931)
- "Airline" (P137)
- "Start time" (P580), [if destination hasn't started yet, background-color in green]
- "End time" (P582) [if destination has ended, no line show for this destination/airline OR background-color in red]
- "Comment and reference(s)" (P2315)+(P854)
This new lua code would be properly working with airports https://www.wikidata.org/wiki/Q17430 or https://www.wikidata.org/wiki/Q642313
Should this new code be working, it would then be adapted to destinations served by one airline.
Any help would be greatly appreciated. --Bouzinac (talk) 12:52, 26 August 2016 (UTC)
- I had a go at creating a airport destinations table. It takes into account P931, P137 and P582, but not any of the other properties. If P582 is specified then that line is not processed at all. It is currently limited to show only one airline, just for now. The first argument is used to specify an item id, feel free to play with it as you see fit. Example below.
-
Aéroport Compagnie Ville Dzaoudzi Pamandzi International Airport Air Austral Dzaoudzi Orly Airport Air France Paris Paris-Charles de Gaulle Airport Air Austral Paris Sir Seewoosagur Ramgoolam International Airport Air Mauritius Mauritius Seychelles International Airport Air Austral Ivato Airport Air Madagascar Chennai International Airport Air Austral OR Tambo International Airport Air Austral Prince Said Ibrahim International Airport Air Austral Fascene Airport Air Austral Nosy Be Marseille Provence Airport XL Airways France Toamasina Airport Air Austral Suvarnabhumi Airport Air Austral Bangkok
--Snaevar (talk) 15:18, 28 August 2016 (UTC)
-
- Hi Snaevar, thanks for this nice first job. The closure of a destination is properly erased (ex of Réunion-Sydney closed 2008 but Nouméa should still appear as I've put a false end to 2020). May I ask you to add the following, should you have time :
- use wikitable common formatting (+sortable and hiddable)
- cite all airlines doing A>B, be them 1 or many, with a comma separating them
- show a link to relevant wikiarticles
- present columns in this order : Airport name / City / Airline(s) / Start time (to fill if info exists + green color if not started) / End time (to fill if info exists + red color if closure in the future) / Comments and references.
- Present columns titles with wikidata, so as to make the lua interlinguical
- "Aéroport" with the name of Q1248784
- place served by airport with Q515
- airline with Q46970
- début with Q345407
- end with Q12769393
- Q1141067 + Q3523102
-
- Are the other properties difficult to insert, as you did not include them ?
- I have a question : do you think feasible to automatically present city served by -P931- in a lookup regarding to what has been filled in "Airport name" (P1813) ==> in other words, can one fill only airport name, and automatically have the result of P931, thus one don't need to fill all information ?
- Again, thanks to work with me on this developpement! Alex
--Bouzinac (talk) 22:20, 29 August 2016 (UTC)
ColPollTable[edit]
Not sure where else to put this. I turned Template:ColPollTable into a module (small test here). But it's weird because this is set to replace 20 independent templates. What bugs me though is whether or not the template is necessary. It seems to be used on only a few pages, which makes me wonder if its functionality might be covered by a superior template. If that's not the case and the template serves a unique function, then I'm not sure exactly how I should proceed to update the templates and their calls. moluɐɯ 13:35, 30 August 2016 (UTC)
- If you check WhatLinksHere with normal links hidden, you'll see that the template doesn't even have a single transclusion. It should probably be nominated at TfD as unused, not converted to Lua. There's no problem with converting it if you plan to actually use it, of course, but I can see why it's not been adopted anywhere - even on my huge 1920px monitor it still scrolls horizontally. That can't be fun if you're using a mobile device. — Mr. Stradivarius ♪ talk ♪ 14:30, 30 August 2016 (UTC)
- The main template isn't used anywhere, but its various subtemplates are. moluɐɯ 15:38, 30 August 2016 (UTC)
- The link provided by Mr.S. shows that Template:ColPollTable is not transcluded anywhere—it is not used. I have not looked at what's going on, but the subtemplates must not be calling it. Are you saying that your new code could be used to replace the subtemplates, despite {{ColPolTable}} being currently unused? Johnuniq (talk) 00:45, 31 August 2016 (UTC)
- Yes. I guess I should clarify what's going on then. This seems to be an old and rather unsophisticated template. The base template, ColPollTable, provides 20 columns for weeks, invariably. To use a number of weeks less than 20, 19 other templates exist—ColPollTable/1–ColPollTable/19. I took this idea and merged it into a single module. Instead of explicitly defining how many weeks to display, the module looks for the highest week number defined, and works from there, eliminating the need for each of these subtemplates. moluɐɯ 11:17, 31 August 2016 (UTC)
- Ah, that makes more sense. I see that Template:ColPollTable/20 is transcluded 12 times, for example. I also see that there are subtemplates that number higher than 20. For now I think it would be fine to just update the transclusions to use the new module; we can worry about how to make things look nice on mobile later. However, before that, it might be a good idea to ask at the relevant WikiProjects as to whether they have a better/more standard way of doing things. — Mr. Stradivarius ♪ talk ♪ 01:48, 1 September 2016 (UTC)
- Yes. I guess I should clarify what's going on then. This seems to be an old and rather unsophisticated template. The base template, ColPollTable, provides 20 columns for weeks, invariably. To use a number of weeks less than 20, 19 other templates exist—ColPollTable/1–ColPollTable/19. I took this idea and merged it into a single module. Instead of explicitly defining how many weeks to display, the module looks for the highest week number defined, and works from there, eliminating the need for each of these subtemplates. moluɐɯ 11:17, 31 August 2016 (UTC)
- The link provided by Mr.S. shows that Template:ColPollTable is not transcluded anywhere—it is not used. I have not looked at what's going on, but the subtemplates must not be calling it. Are you saying that your new code could be used to replace the subtemplates, despite {{ColPolTable}} being currently unused? Johnuniq (talk) 00:45, 31 August 2016 (UTC)
- The main template isn't used anywhere, but its various subtemplates are. moluɐɯ 15:38, 30 August 2016 (UTC)
Different options[edit]
In Module:Routemap/sandbox, I'd like to use the option removeBlanks = false for the p._BSrow function, but only that function. Is it necessary to make another module for this? Jc86035 (talk • contribs) Use {{re|Jc86035}} to reply to me 12:25, 1 September 2016 (UTC)
- I think you are saying that wikitext calling a template might include
|removeBlanks=falseto not remove blanks, or might omit that parameter to include them. And the template would invoke functionBSrowin the module. I don't see a problem and don't see why another module might be needed. What is the concern? - My instinct is telling me there is a problem with the
positive(x)andnegative(x)functions that would presumably be used to testargs.removeBlanks. If the wikitext omits the parameter (or equivalently, given that Module:Arguments is used probably with defaults, omits the value),positive(args.removeBlanks)would evaluate as false, and so wouldnegative(args.removeBlanks). That's a bit awkward. Johnuniq (talk) 00:20, 2 September 2016 (UTC)- @Johnuniq: I meant as in the Module:Arguments option, not adding it from the frame or whatever. (The
positive(x)andnegative(x)functions are purely for internal use and I'm not sure why I'd use an args.removeBlanks in them.) Would having a makeInvokeFunction2 (duplicate but using removeBlanks = false) work, or is there a better solution? Jc86035 (talk • contribs) Use {{re|Jc86035}} to reply to me 07:08, 2 September 2016 (UTC)- @Jc86035: Oops, you can tell I haven't used Module:Arguments! No wonder I didn't understand what the concern was. Have a look at my diff to the sandbox which I think will do the job. You don't need another module, and if what I did doesn't work, it can be fixed. You might test it with a few lines of test code that returns dummy text depending on the arguments so you can see if it does what is expected. Johnuniq (talk) 07:44, 2 September 2016 (UTC)
- @Johnuniq: I meant as in the Module:Arguments option, not adding it from the frame or whatever. (The
Module:Coordinates[edit]
The Wikidata implementation in {{Coord}} (activated when |1= and |2= are both missing) doesn't seem to be working. On, for example, Empire State Building, {{Coord}} returns "40.7483°N 73.9853°WInvalid arguments have been passed to the {{#coordinates:}} function". Coordinates seem to be fine (other than that the coordinates were originally imported to Wikidata with 1⁄1000th of an arcsecond's accuracy), but it still returns the error. Does anyone have any idea why? Thanks, Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 13:22, 7 September 2016 (UTC)
- I have only glanced at Template:Coord but doesn't it invoke the module and
{{#coordinates:...}}? I don't understand what the bits and pieces are supposed to do, but it looks like #coordinates will output that error message unless it is fed valid data, and putting "{{Coord}}" on a page would not feed it anything valid that I can see. Johnuniq (talk) 02:26, 8 September 2016 (UTC)- In fact, previewing "
{{#invoke:Coordinates|coord}}" at the article displays what is wanted without an error. Johnuniq (talk) 02:28, 8 September 2016 (UTC){{#property:P625|from=Q9188}}- 40°44'54"N, 73°59'7"W if you just want standalone coordinates (with no links). -- Matroc (talk) 03:15, 8 September 2016 (UTC)- @Johnuniq and Matroc: Oh, I see. Thanks. (Would it be possible for the
{{#coordinates:}}part to be put into the module as well, since otherwise the Wikidata implementation is a bit broken? There's Module:WikidataCoord, but it doesn't have a template wrapper and is only used on a few pages.) Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 05:10, 8 September 2016 (UTC)- I remember that there was a problem with some kind of incompatibility between #coordinates and #invoke when the module was first written, which is why it's not already included. I'm not sure if that still applies. — Mr. Stradivarius ♪ talk ♪ 05:30, 8 September 2016 (UTC)
- @Mr. Stradivarius: Could this be solved by making a subtemplate containing just
{{#coordinates:}}(and using it through the module), or is there a better solution? Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 07:06, 8 September 2016 (UTC) - Yes, back in the early days there wasn't a good way to use #coordinates within Lua. I think "frame:callParserFunction" makes this possible now, though I haven't tried it. Dragons flight (talk) 07:26, 8 September 2016 (UTC)
- @Dragons flight: Tried it; returns an error: Lua error in Module:Coordinates/sandbox at line 592: attempt to index local 'frame' (a nil value). Maybe it's because everything goes through Module:Arguments? A similar setup works for Module:Geobox coor though. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 10:18, 8 September 2016 (UTC)
- @Dragons flight: Tried it; returns an error: Lua error in Module:Coordinates/sandbox at line 592: attempt to index local 'frame' (a nil value). Maybe it's because everything goes through Module:Arguments? A similar setup works for Module:Geobox coor though. Jc86035 (talk) Use {{re|Jc86035}}
- @Mr. Stradivarius: Could this be solved by making a subtemplate containing just
- I remember that there was a problem with some kind of incompatibility between #coordinates and #invoke when the module was first written, which is why it's not already included. I'm not sure if that still applies. — Mr. Stradivarius ♪ talk ♪ 05:30, 8 September 2016 (UTC)
- @Johnuniq and Matroc: Oh, I see. Thanks. (Would it be possible for the
- In fact, previewing "
- In my module in pl wiki (pl:Moduł:Koordynaty) this call works:
-- https://bugzilla.wikimedia.org/show_bug.cgi?id=50863 RESOLVED
return mw.getCurrentFrame():callParserFunction("#coordinates", params) or ""
where params is a table with parameters as described in mw:Extension:GeoData. Paweł Ziemian (talk) 20:30, 8 September 2016 (UTC)
-
- Also, a bit off-topic; with Kartographer extension (if installed) you can create a link to a map (using decimal coordinates found in Wikidata):
<maplink zoom="13" longitude="-73.985656" latitude="40.748433" />40°44′54″N 73°59′8″W or<maplink zoom="13" text="Click Me!" longitude="-73.985656" latitude="40.748433" />Click Me! - The decimal coordinates can be found by querying Wikidata. -- It all depends on what you are trying to do and what can be done with available tools/templates/modules etc. - Check out Solomon R. Guggenheim Museum Best wishes!-- Matroc (talk) 02:26, 9 September 2016 (UTC)
- @Paweł Ziemian: Thanks! @Matroc: Looks very nice. Does this have any implications for {{Coord}} and Geohack, and their future prospects? I'm working on Help:Coordinates in infoboxes (i.e. converting the newly-deprecated
|latd=,|latm=,|longd=etc. parameters in several hundred thousand infoboxes to just|coordinates=) and this could have quite some changes in how the replacement's being carried out. (Side note: what do the Geohack parameters in{{#coordinates:}}actually do?) Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 05:12, 9 September 2016 (UTC) - Pinging JJMC89 and Jonesey95. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 05:13, 9 September 2016 (UTC)- Thanks for the ping, but this is over my head. I can code templates, but Lua and wikidata calls are out of reach for me. – Jonesey95 (talk) 05:40, 9 September 2016 (UTC)
- That was just a quick demo of getting the coordinates for creating a map using maplink or mapframe as I use in enWikivoyage... I think I marked that as off-topic earlier as I thought I was getting away from what you might be trying to accomplish. Different animals. I do search Wikidata for latitude and longitude (in decimal dms) form for use by maps and listings by using the Wikidata ID (Qnnn) and lookup up the coords property (P625) and look for the array value for longitude and latitude. It can be complex and confusing at times. I wish I could help you more. All the best! -- Matroc (talk) 06:39, 9 September 2016 (UTC)
- @Johnuniq, Mr. Stradivarius, and Dragons flight: I've tried adding it to the sandbox; however, there seem to be some weird errors (see Module talk:Coordinates/testcases) which don't occur when I'm testing the template in WP:Sandbox (specifically with the testcase with missing minutes/seconds). Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 08:37, 9 September 2016 (UTC)
- @Paweł Ziemian: Thanks! @Matroc: Looks very nice. Does this have any implications for {{Coord}} and Geohack, and their future prospects? I'm working on Help:Coordinates in infoboxes (i.e. converting the newly-deprecated
- Also, a bit off-topic; with Kartographer extension (if installed) you can create a link to a map (using decimal coordinates found in Wikidata):
trouble with Expansion depth[edit]
Commons is a project where we spend a lot of effort on presenting everything in the language of the person viewing the page. That was traditionally done by layers and layers of very large and complicated templates, some of which become so complicated as to become unmanageable. Over the last several years we were working on transitioning some of them to Lua, which is a great improvement. Recently me and others were working on transition of c:Template:Creator and c:template:Artwork to c:Module:Creator and c:Module:Artwork and we are running into a problem of Expansion depth. Template version of the templates do not trigger it, but Lua versions do. See for example c:Module talk:Creator/testcases. The issue seems to be that if a template written in Lua is processing output of another template written in Lua than that triggers Expansion depth error. I reported some earlier case in phabricator:T133918, it seems like it will be a blocking issue before c:Module:Creator can be used. Do anybody have experience with working with that limit or understands logic of how Lua triggers Expansion depth. --Jarekt (talk) 13:18, 17 September 2016 (UTC)
- @Jarekt: In Module:Creator (in the
p.creatorfunction, line 262) you seem to be using bothArgsandargs; is this intended? I'm not sure where the expansion depth error is in the page. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 13:37, 17 September 2016 (UTC) - Oh, I see the expansion depth error. Not sure about that; are there normally that number of creator templates on the same page? Might have something to do with it Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 14:04, 17 September 2016 (UTC)- c:Module:Creator is still being written, but use of Args and args parameters was intentional as I am trying to switch to case non-sensitive parameters. Maybe I should use better variable names. Page User:Jarekt/a has a single Creator template with bunch of expansion depth errors. Same parameters passed to current {{Creator}} page are no problems. According to the documentation Expansion depthshould not depend on how many templates you have, but how many templates you have nested. At least that how it worked with templates. --Jarekt (talk) 16:22, 17 September 2016 (UTC)
- @Jarekt: Whatever this is, it's a pretty fundamental problem: I can reproduce the expansion depth error by simply replacing the module content with
return {
creator = function (frame)
return frame.args.Workloc
end
}
- and by previewing Module talk:Creator/testcases using the "preview page with this template" feature. — Mr. Stradivarius ♪ talk ♪ 16:45, 17 September 2016 (UTC)
-
- User:Mr. Stradivarius thank you for looking into it. I agree that it is quite fundamental. I had the same problem with using string templates (based on module:String) to process a string that come from another LUA based template. The issue seem to be with nesting of 2 lua based templates, no matter how simple. The troubling thing is that as more and more of our templates are converted to Lua, that will happen more often. The behavior does not seem to follow the documented rules of expansion depth error. --Jarekt (talk) 19:22, 17 September 2016 (UTC)
- I did some debugging for you. The PHP stack trace looks, in part, like this repeated several times:
- User:Mr. Stradivarius thank you for looking into it. I agree that it is quite fundamental. I had the same problem with using string templates (based on module:String) to process a string that come from another LUA based template. The issue seem to be with nesting of 2 lua based templates, no matter how simple. The troubling thing is that as more and more of our templates are converted to Lua, that will happen more often. The behavior does not seem to follow the documented rules of expansion depth error. --Jarekt (talk) 19:22, 17 September 2016 (UTC)
#8 PPTemplateFrame_Hash->getArguments() called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:782]
#9 Scribunto_LuaEngine->preprocess(current, {{int:lang}}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaSandbox/Engine.php:407]
#10 Scribunto_LuaSandboxCallback->__call(preprocess, Array)
#11 LuaSandboxFunction->call(Object of class LuaSandboxFunction could not be converted to string, getLabel) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaSandbox/Engine.php:319]
#12 Scribunto_LuaSandboxInterpreter->callFunction(Object of class LuaSandboxFunction could not be converted to string, Object of class LuaSandboxFunction could not be converted to string, getLabel) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:245]
#13 Scribunto_LuaEngine->executeModule(Object of class LuaSandboxFunction could not be converted to string, getLabel, tplframe{"entity":"<value><tplarg><title>1</title><part><name index=\"1\"/><value/></part></tplarg></value>", "lang":"<value><tplarg><title>2</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><tplarg><title>link</title><part><name index=\"1\"/><value>wikipedia</value></part></tplarg> </value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:898]
#14 Scribunto_LuaModule->invoke(getLabel, tplframe{"entity":"<value><tplarg><title>1</title><part><name index=\"1\"/><value/></part></tplarg></value>", "lang":"<value><tplarg><title>2</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><tplarg><title>link</title><part><name index=\"1\"/><value>wikipedia</value></part></tplarg> </value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/common/Hooks.php:121]
#15 ScribuntoHooks::invokeHook(Object of class Parser could not be converted to string, tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}, Array) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3352]
#16 Parser->callParserFunction(tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}, invoke, Array) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3076]
#17 Parser->braceSubstitution(Array, tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016]
#18 PPFrame_Hash->expand(<root><ignore><includeonly></ignore><template><title>#invoke: Wikidata </title><part><name index="1"/><value> getLabel </value></part><part><name>entity</name><equals>=</equals><value><tplarg><title>1</title><part><name index="1"/><value/></part></tplarg></value></part><part><name>lang</name><equals>=</equals><value><tplarg><title>2</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><tplarg><title>link</title><part><name index="1"/><value>wikipedia</value></part></tplarg> </value></part></template><ignore></includeonly></ignore><ignore><noinclude> {{documentation}}</noinclude></ignore></root>) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3229]
#19 Parser->braceSubstitution(Array, tplframe{}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016]
#20 PPFrame_Hash->expand(<root><template><title>Label</title><part><name index="1"/><value>Q47465</value></part><part><name index="2"/><value><tplarg><title>1</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><template><title>#if:<tplarg><title>nolink</title><part><name index="1"/><value/></part></tplarg></title><part><name index="1"/><value>-</value></part><part><name index="2"/><value>wikipedia</value></part></template></value></part></template><ignore><noinclude> {{Documentation|Template:GeoName/doc}} [[Category:Multilingual tags: Locations in France|{{PAGENAME}}]] [[Category:Aix-en-Provence|~{{PAGENAME}}]] [[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]] </noinclude></ignore></root>, 0) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1449]
#21 PPTemplateFrame_Hash->cachedExpand(Template:Aix-en-Provence, <root><template><title>Label</title><part><name index="1"/><value>Q47465</value></part><part><name index="2"/><value><tplarg><title>1</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><template><title>#if:<tplarg><title>nolink</title><part><name index="1"/><value/></part></tplarg></title><part><name index="1"/><value>-</value></part><part><name index="2"/><value>wikipedia</value></part></template></value></part></template><ignore><noinclude> {{Documentation|Template:GeoName/doc}} [[Category:Multilingual tags: Locations in France|{{PAGENAME}}]] [[Category:Aix-en-Provence|~{{PAGENAME}}]] [[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]] </noinclude></ignore></root>) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3226]
#22 Parser->braceSubstitution(Array, frame{}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016]
#23 PPFrame_Hash->expand(<value> <template><title>Aix-en-Provence</title></template>, <template><title>Paris</title></template>, <template><title>city</title><part><name index="1"/><value>Auvers-sur-Oise</value></part></template>, <template><title>Marseille</title></template> </value>, 4) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1529]
#24 PPTemplateFrame_Hash->getNamedArgument(Workloc) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1541]
#25 PPTemplateFrame_Hash->getArgument(Workloc) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1473]
-
-
- What seems to be happening there is that MediaWiki attempts to expand the
Worklocparameter (#25-23), which expands {{Label}} (#22-18), which invokes c:Module:Wikidata (#17-11), which callsframe:preprocess('{{int:lang}}')in some manner (#10-9), which needs to expand the parameters passed into the current frame (#8), which includesWorklocso repeat until the expansion depth is exceeded. The top-levellocal defaultlang = mw.getCurrentFrame():preprocess("{{int:lang}}")in c:Module:Wikidata, c:Module:Wikidata/Tools, c:Module:Wikidata/FormatEntity, and so on looks particularly suspicious. BJorsch (WMF) (talk) 23:54, 17 September 2016 (UTC)- BJorsch (WMF) thanks I will study this chain. I think I get it.
It returns users preferred language and there was a discussion lattely here how it no longer works. @Zolo: as the author of c:Module:Wikidata maybe you can look at this as well. We should not need to callframe:preprocess('{{int:lang}}')is actually usually written asmw.message.new( "lang" ):plain()to avoid calling preprocess.frame:preprocess('{{int:lang}}')as the language parameter should be passes from outside (you only get users language if you pass it from the outside, like here). --Jarekt (talk) 02:32, 18 September 2016 (UTC)- I was wrong: output of
mw.message.new( "lang" ):plain()is not equivalent toframe:preprocess('{{int:lang}}'). --Jarekt (talk) 15:42, 19 September 2016 (UTC)-
replacing Some usage of c:Module:Wikidata with much much smaller c:Module:Wikidata label fixed the problem. Thanks everyone. Jc86035 after working more on the code I understand your comment about
ResolvedArgsandargs. That part of the code was wrong, but I was focusing on the expansion depth issue. --Jarekt (talk) 13:52, 20 September 2016 (UTC)
-
- I was wrong: output of
- BJorsch (WMF) thanks I will study this chain. I think I get it.
- What seems to be happening there is that MediaWiki attempts to expand the
-
Module:Coordinates (used in other modules)[edit]
(Pinging Braveheart.) Module:Coordinates now calls the {{#coordinates:}} parser function through mw.getCurrentFrame():callParserFunction. This unexpectedly broke Module:HS listed building, which calls Module:Coordinates' coordinates.coord function directly. Any way of fixing this? Jc86035 (talk) Use {{re|Jc86035}}
to reply to me 14:46, 20 September 2016 (UTC)
Sensitive IP modules and libLua[edit]
I've just started a discussion at VPT about rolling out the new sensitive IP modules, which might be of interest to people who want to use information about sensitive IPs in other modules or templates. Another item in the proposal which might be of interest is libLua.js, a library for calling Lua functions from JavaScript more easily than is currently possible with the "scribunto-console" API action. — Mr. Stradivarius ♪ talk ♪ 14:10, 22 September 2016 (UTC)
How mw.html.tag() works?[edit]
For example:
local tab = mw.html.create('table')
tab
:addClass('wikitable')
:tag('caption'):wikitext('something '):wikitext('and something')
:tag('tr'):tag('td'):wikitext('a')
:tag('tr'):tag('td'):wikitext('b')
return tab
Why it knows that I want to get:
<table class="wikitable">
<caption>something and something</caption>
<tr><td>a</td></tr>
<tr><td>b</td></tr>
</table>
rather than:
<table class="wikitable">
<caption>something and something
<tr><td>a
<tr><td>b</td></tr>
</td></tr>
</caption>
</table>
Where the :tag('caption') is closed?--A Sword in the Wind (talk | changes) 06:01, 15 October 2016 (UTC)
- The Sribunto HTML library method mw.html.tag() doesn't perform any sort of "smart" closure of tags. The problem is that you accidentally misinterpreted the output of your code. When I run the code sample you provided I get the following output...
-
<table class="wikitable"><caption>something and something<tr><td>a<tr><td>b</td></tr></td></tr></caption></table>
- ...which is equivalent to...
-
<table class="wikitable"> <caption>something and something <tr> <td>a <tr> <td>b</td> </tr> </td> </tr> </caption> </table>
- ... which is the same as your "rather than" output. So, everything is working as expected. If you actually want code that outputs HTML equivalent to your first sample, you could do the following...
-
local tab = mw.html.create('table') tab:addClass('wikitable') tab:tag('caption'):wikitext('something '):wikitext('and something') tab:tag('tr'):tag('td'):wikitext('a') tab:tag('tr'):tag('td'):wikitext('b')
- ...which outputs...
-
<table class="wikitable"><caption>something and something</caption><tr><td>a</td></tr><tr><td>b</td></tr></table>
- If it helps to show what is going on, the following code outputs the same HTML as the code immediately above:
-
local tab = mw.html.create('table') tab:addClass('wikitable') local caption = tab:tag('caption') caption:wikitext('something ') caption:wikitext('and something') local tr1 = tab:tag('tr') local td1 = tr1:tag('td') td1:wikitext('a') local tr2 = tab:tag('tr') local td2 = tr2:tag('td') td2:wikitext('b')
- —RP88 (talk) 09:44, 15 October 2016 (UTC)
- If your first code box is what you're seeing in your browser, it's probably due to HTML Tidy fixing the broken HTML. SiBr4 (talk) 14:08, 16 October 2016 (UTC)