Wikipedia talk:Lua

From Wikipedia, the free encyclopedia
  (Redirected from Wikipedia:Lua requests)
Jump to: navigation, search
  WP:Lua
Project
  WT:Lua
Project talk
  Help
 
  To do
 
  Resources
en: m: mw: external
 

Template:cfd all[edit]

Can some one please convert {{cfd all}} intoa module-based template? Please set it up so that all the numbered parameters currently used will be derived from a single letter passed as a parameter (i.e {{cfd full}} will send a parameter "d" to represent the type of CfD tag, along with date parameters and an optional section parameter the way it does now; add a target parameter for the other CfD tags to work). עוד מישהו Od Mishehu 20:40, 11 July 2016 (UTC)

@Od Mishehu: It sounds like just replacing numbered parameters with one named parameter wouldn't need Lua. It might be simplest just to edit the template to add that parameter without converting it to Lua at all. I would try to do it myself, but from your description I'm sure exactly what you want to be done. Maybe make a more detailed suggestion on the template's talk page? Best — Mr. Stradivarius ♪ talk ♪ 23:36, 12 July 2016 (UTC)
If you look at {{cfr full}}, you'll see that it starts with: {{cfd all|renaming to {{#if:{{{target|}}}|{{cat|{{{target}}}}}|some other name}}|cfr|Rename|rename|renaming; I would like this to be replaced with {{tl|cfd all|r (note that {{{target}}} is passed on later in the list parameter list). עוד מישהו Od Mishehu 02:54, 13 July 2016 (UTC)

Lua conversion for Template:Sensitive IP addresses, and is a Lua-to-JSON feature possible?[edit]

Following up on Wikipedia:Village_pump_(technical)#51.171.156.10, I wonder if it's possible to convert Template:Sensitive IP addresses to use Lua. And whether it's possible to make such a module create either wikitext output or JSON output, the latter for MediaWiki:Group-sysop.js - as discussed in the VPT thread the JSON there is far outdated. If that is possible, a good setup may be Module:Sensitive IP addresses containing the Lua code proper and Module:Sensitive IP addresses/List of addresses containing the list of IPs and associated owners.Jo-Jo Eumerus (talk, contributions) 21:44, 12 July 2016 (UTC)

Yes, it's possible. I did something similar with Lua data for Module:Signpost, its data tables at Module:Signpost/index/2016 etc., and User:Mr. Stradivarius/gadgets/SignpostTagger.js. I've actually started working on this, but I decided to go about it in a slightly roundabout way - I've started writing a library for dealing with IP addresses at Module:IP, and I plan to convert Template:Sensitive IP addresses after that's done. — Mr. Stradivarius ♪ talk ♪ 23:23, 12 July 2016 (UTC)
Sweet. Mr. Stradivarius, take note that I've proposed to use Template:Sensitive IP addresses on MediaWiki talk:Blockiptext and Wikipedia:Blocking policy, so some alterations may happen.Jo-Jo Eumerus (talk, contributions) 23:29, 12 July 2016 (UTC)
Module:IPblock does a lot of work with IPv4 and IPv6 addresses. It can parse them from wikitext and put each address in a table (same structure for both v4 and v6). Addresses can be compared, sorted, and masked, and the number of common prefix bits can be calculated (function common_length is astonishing!). It can output the text representation of an IP. Johnuniq (talk) 23:50, 12 July 2016 (UTC)
That's an impressive module! Thanks for pointing it out - I wasn't aware of it before. My instinct would be to move the generic IP functions to Module:IP so that other modules can use them, and keep the range-calculating code in Module:IPblock. There are already at least three modules that need to work with IP addresses - Module:IPAddress, Module:IPblock, and the new proposed Module:Sensitive IP addresses. What do you think? And also, what do you think of the interface I have sketched out? That is still a work in progress, and we can change stuff as necessary. — Mr. Stradivarius ♪ talk ♪ 02:01, 13 July 2016 (UTC)
Moving the code is fine. I'd like to postpone thoughts from me for 24 to 48 hours. If you're in a hurry, go for it; otherwise, you might wait for me to copy in the functions I think would help so they can be massaged into the required form. I do not understand what SignpostTagger.js or the module are doing, but it looks like the js is writing the module code—amazing! By the way, if you've never tried it, it can be quite easy and efficient for a module to parse a long string. That might be a good technique for the current IP application where all that is wanted is a plain-text list of IP addresses, possibly with CIDR ranges, and that would be simple to parse although my module does not handle big CIDR ranges because of some internal calculations it does (it keeps a list of every IP in a range, and that's not feasible for IPv6 or big IPv4 ranges). For an example of parsing a long string, see the "list" parameter in Template:Football manager history#Examples. The code which parses that is function make_list in Module:Football manager history. Johnuniq (talk) 04:50, 13 July 2016 (UTC)

@Mr. Stradivarius: I put some preliminary thoughts at Module talk:IP. Johnuniq (talk) 11:10, 14 July 2016 (UTC)

Adding references to Infobox template[edit]

I would like to be able to add references to lua template and have them show up at the bottom of the wikipedia page as when the <ref> tag is used. Is there a lua module somewhere to help me do this? https://en.wikipedia.org/wiki/User:Julialturner/RELN see the section with diseases. These numbered references items should correspond to those numbered in the reference section. Thanks you. Julialturner (talk) 05:53, 13 July 2016 (UTC)

The only way to get a reference is for the wikitext to include <ref> tags. I don't think Module:Sandbox/genewiki/alllua outputs any refs. Modules are run after several other steps in preparing the wikitext are completed, and one of those steps involves processing ref tags. I think that means that any ref tags output by a module won't work. Instead, it appears a module would need to use extensionTag. I have never tried that. By the way, Lua handles true/false variables. Instead of f = "true" (a string), use f = true. After doing that, f can be tested with if f then ... (no need to mention true). Johnuniq (talk) 06:14, 13 July 2016 (UTC)
Thank you for the extensionTag suggestion I will try to go that route and also for the true false pointer. Julialturner (talk) 19:16, 13 July 2016 (UTC)
if you need to process stuff that is typically processed before the module is invoked, use frame:callParserFunction(), frame:extensionTag(), or frame:expandTemplate() (the last one only works if you have a template that produces the tag, which is often the case with ref tags) . it's explained here, and interestingly enough, the documentor(s) (sp?) chose the "ref" tag for one of the examples. peace - קיפודנחש (aka kipod) (talk) 22:49, 13 July 2016 (UTC)
I think you made a typo there - that should be frame:expandTemplate, not frame:extendTemplate. — Mr. Stradivarius ♪ talk ♪ 23:17, 13 July 2016 (UTC)
thanks. fixed. whoever reads this should not go by what i wrote directly - the important part was the link to the section on the manual page. peace - קיפודנחש (aka kipod) (talk) 14:03, 14 July 2016 (UTC)

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.


Many thanks --פוילישער (talk) 05:41, 27 July 2016 (UTC)
I have just tried again without the modifications I made and have been successful this time. I must have introduced some error in the code. --פוילישער (talk) 05:55, 27 July 2016 (UTC)

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().args is 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:
  1. frame.args parameters from the template invoking the module
  2. frame:getParent().args parameters 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().args was 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 from frame.args to frame:getParent().args for 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().args over frame.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 using frame:getParent().args and 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)

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 tried frame: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)

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)
Alright thanks. I'll do that. moluɐɯ 10:53, 1 September 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=false to not remove blanks, or might omit that parameter to include them. And the template would invoke function BSrow in 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) and negative(x) functions that would presumably be used to test args.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 would negative(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) and negative(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: Seems to be working ({{User:Jc86035/sandbox3|||*3|||O5=utSTRq|bg=}} returns \\*3\\!~utSTRq~~ ~~ ~~ ~~ ~~bg=); thanks! Jc86035 (talk • contribs) Use {{re|Jc86035}} to reply to me 07:49, 2 September 2016 (UTC)

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 11000th 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)
		-- 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)

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.creator function, line 262) you seem to be using both Args and args; 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:
#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 Workloc parameter (#25-23), which expands {{Label}} (#22-18), which invokes c:Module:Wikidata (#17-11), which calls frame:preprocess('{{int:lang}}') in some manner (#10-9), which needs to expand the parameters passed into the current frame (#8), which includes Workloc so repeat until the expansion depth is exceeded. The top-level local 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. frame:preprocess('{{int:lang}}') is actually usually written as mw.message.new( "lang" ):plain() to avoid calling preprocess. 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 call 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 to frame:preprocess('{{int:lang}}'). --Jarekt (talk) 15:42, 19 September 2016 (UTC)
Resolved
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 Args and args. That part of the code was wrong, but I was focusing on the expansion depth issue. --Jarekt (talk) 13:52, 20 September 2016 (UTC)

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)