Wikipedia talk:Lua/Archive 6

Latest comment: 6 years ago by Trappist the monk in topic Length of table inside code
Archive 1Archive 4Archive 5Archive 6Archive 7Archive 8Archive 10

Module:Infobox table row problems

Currently, Module:Infobox requires HTML Tidy for child infoboxes and fails to render properly if there are more than two child infoboxes in one table cell and the child infoboxes are separated by line breaks (example). This is because using child infoboxes nests <tr>...</tr> inside <td>...</td>, which would probably have worked with normal wikitable syntax (although this would have generated an extra blank table row) but not with HTML tags. The best fix would probably be to prevent the generation of the <tr> and <td> tags in the parent infobox row if <tr> but not <table> is detected inside a table cell with colspan=2, and to add <table>...</table> for all other instances. I don't know how to do this with the syntax style used in the module, so asking for help here. Regexes could be </?tr[ >] etc. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
11:05, 24 May 2017 (UTC)

The module might also need to handle wikitext tables with HTML table tags used in them (or a mixture of wikitext and HTML tables in the same data cell). I'm not sure whether it's better to handle them or just remove wikitext tables from child infoboxes. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
11:13, 24 May 2017 (UTC)

In addition, {{Collapsed infobox section begin}} and {{Collapsed infobox section end}} can cut off ending tags which are in the infobox template but not in the parameter. For example, in the two incident infoboxes on Watford Junction railway station, the </caption> ending tag is split by the begin template and ends up in the collapsed table. I'm not sure whether to handle this in the module, or if this causes any actual problems. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
12:26, 24 May 2017 (UTC)

Jc86035, I had a couple potential solutions, (1) this solution which should basically fix it, and also should remove any spurious blank cells generated by the embedding, or (2) this solution which isn't as aggressive. both solutions require string processing of the input, which may be expensive? so, a third option would be to have a new way to generate/pass child boxes so that they are injected as table rows, rather than using the tidy hack. but, that would require a lot more work to find/fix all of the existing uses. Frietjes (talk) 15:28, 24 May 2017 (UTC)
by the way, for the "My Sweet Lord" example, if you generated the headers using <div>...</div> instead of using infobox|child=yes, you could probably avoid these issues, and reduce the overall complexity of the child modules. Frietjes (talk) 15:31, 24 May 2017 (UTC)
@Frietjes: I don't think the string processing should be expensive, since there are only a couple of functions which are explicitly marked as "expensive" in the Lua manual, unless you're referring to something else. (to clarify: this has nothing to do with the collapsible infobox stuff, right?)
As for the example, I think the group of infoboxes works well enough, however flawed the nesting may be, and I don't really want to spend more time rewriting them. They should work fine if the module is updated, in any case. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
15:38, 24 May 2017 (UTC)
string processing of arbitrarily large input can be expensive, but I suppose one could just try it an see what happens. the {{Collapsed infobox section begin}} and {{Collapsed infobox section end}} are a total hack that I created in response to another hack. we could try to make those templates more robust, but that's a separate issue (related but would require a separate solution). basically, you would want Module:infobox to keep track of begin/end and make sure there are always matched pairs. Frietjes (talk) 15:46, 24 May 2017 (UTC)
@Frietjes: Tested with both versions in {{Infobox/testcases}}. All three (main, sandbox, sandbox2) fail to remove the tr and td tags of |data1=. However, the rendering error is due to HTML Tidy and has nothing to do with the extra HTML tags, as all of them display well in Special:ExpandTemplates. The rendering error persists even after the extra tags are removed. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
07:37, 27 May 2017 (UTC)
Pinging Life of Tau, who I reverted with an incorrect edit summary (the rendering error is due to the parser/HTML Tidy, not the module). Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
07:43, 27 May 2017 (UTC)
Jc86035, the the new version of the module only works if both the parent and child infoboxes are generated by new version of the module. the way it works is that the child injects markers to delimit the start and end of the child infobox, and then the parent splits the table cells based on those markers. hence, if the child doesn't inject the markers, then the parent will do nothing. Frietjes (talk) 12:53, 27 May 2017 (UTC)
@Frietjes: Sorry, my mistake. I've repaired the testcases and it seems to work now (was probably the placement of the tags within the table which was breaking Tidy earlier). Module:Infobox/sandbox2 creates empty rows, which could be stripped out by the module as well. Since both versions continue working without the stripping of the tracking categories, do they need further testing before being put in use? Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
13:55, 27 May 2017 (UTC)
Jc86035, the "empty row stripping" feature is what I meant by also should remove any spurious blank cells generated by the embedding when I described (1) and (2) above. I would think that stripping empty rows would be a good in feature in general, but I could imagine someone using empty rows with background colouring to create a visual gap between sections. we could (a) go for the more aggressive version 2 and see if any problems are reported, or (b) be more conservative and go with version 1 (which is basically how child boxes function right now after tidy). I, personally, think that either one is probably ready for deployment, but I would welcome feedback from Jackmcbarn, Mr. Stradivarius, Johnuniq, etc. since I may be doing something boneheaded in the lua code that could be improved. Frietjes (talk) 14:05, 27 May 2017 (UTC)
I added some trivial comments at Template talk:Infobox#Module:Infobox/sandbox. Johnuniq (talk) 05:45, 28 May 2017 (UTC)
@Frietjes: Would it be possible to do something like mw.ustring.match(mw.ustring.sub(data, 1, 3), '<tr') for each data cell, or is this unnecessary? Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
11:38, 29 May 2017 (UTC)
Jc86035, assuming that the child box is the first thing in the data cell would work in many cases. unfortunately, child boxes are being used in many ways right now, including at the end of a data cell in a label/data pair. as far as I can tell, the most significant deficiency of my two proposed solutions is that both the inner and outer boxes must be generated by the infobox module. hence, if (a) someone inserts other table content into an infobox, the infobox module won't tidy it, and if (b) the outer container isn't generated by the infobox module, it won't be tidied either. I don't know of a general way to address "(a)" without introducing some serious string parsing, and "(b)" isn't really fixable, but will be tracked in the tracking category. Frietjes (talk) 12:56, 29 May 2017 (UTC)
Frietjes, then maybe it's better to separately track templates which begin with <tr>. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
13:36, 29 May 2017 (UTC)

Merged changes to main version. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
13:50, 29 May 2017 (UTC)

@Frietjes: It doesn't seem to be working properly, although this might be due to a delay in the propagation of the change. For example, Fleetwood Mac (1975 album) only contains the infobox templates {{Infobox album}} and {{Singles}}, both of which use {{Infobox}}. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
14:00, 29 May 2017 (UTC)

Jc86035, yes, there are some problems there that need to be studied. another outcome was it completely broke template:Infobox college coach. back to the drawing board. Frietjes (talk) 14:14, 29 May 2017 (UTC)
Jc86035, I think I have a more robust version now in Module:Infobox/sandbox. I tested it with template:infobox model and template:infobox college coach, both which broke with the last version. there is no tracking with this version and all the logic for tidying the child box done by the parent, so you can test it by changing the parent to use the sandbox and you don't need to change the child to use the sandbox. Frietjes (talk) 21:18, 29 May 2017 (UTC)
@Frietjes: Looks good. I think it should be possible to remove empty rows without any problems, as AFAIK they can't be added in {{Infobox}} since empty parameters are stripped. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
07:47, 3 June 2017 (UTC)
Jc86035, the empty rows that I was referring to are the ones added by tidy when it fixes the broken HTML. for example, when a child box is the only thing in a data cell, an empty row is generated right above the child box. this still happens with this new version, so no change there. there is no real clean way to fix that problem without some more serious code changes. I plan to look through the code a little bit more, but it should be generally ready to go. Frietjes (talk) 12:05, 3 June 2017 (UTC)
@Frietjes: Tried it and had to revert again due to problems with succession boxes ({{S-line}} uses HTML tags whereas other templates use wikitable syntax). Should {{S-line}} be "fixed" or should the module handle them? Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
12:16, 7 June 2017 (UTC)
Jc86035, can you put an example demonstrating the breakage in the testcases? otherwise, I don't know what we are asking the module to fix. Frietjes (talk) 13:06, 7 June 2017 (UTC)
{{Infobox/sandbox|data1=
{{S-start}}
{{s-rail|title=PM}}
{{s-line|system=PM|line=1|previous=Saint-Paul|next=Gare de Lyon}}
{{S-end}}
}}
@Frietjes: Example using the sandbox template. An extra table cell is inserted after {{S-line}}. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
15:17, 7 June 2017 (UTC)
Jc86035, mixing wikitable syntax with HTML syntax always seemed slightly wrong to me. I have added some additional matches to the sandbox which appears to fix the example you posted here. hopefully it didn't cause any new problems. another option would be to disable the transformations if it detects wikitable markup. it's not clear what is the best solution. Frietjes (talk) 16:47, 7 June 2017 (UTC)
Thanks, Frietjes. I don't think it's possible to insert half a wikitable inside <table>...</table>, so it should be good to go when you think it's ready. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
05:16, 8 June 2017 (UTC)

Module:Linguistic & Module:Fallback

 

An editor has asked for a discussion regarding Module:Linguistic and Module:Fallback. Input from those familiar with modules is welcome at Wikipedia:Miscellany for deletion/Module:Linguistic. Thanks, — Godsy (TALKCONT) 03:10, 17 June 2017 (UTC)

Module:Formatnum

 

An editor has asked for a discussion regarding Module:Formatnum. Input from those familiar with modules is welcome at Wikipedia:Miscellany for deletion/Module:Formatnum. Thanks, — Godsy (TALKCONT) 04:10, 18 June 2017 (UTC)

(Urgent) Help needed for intensively used Module:Syrian_Civil_War_detailed_map

Hi,

We had to split the intensively used Module:Syrian_Civil_War_detailed_map into a detailed map and an overview map.

Because the huge middle eastern conflict map could no longer include the whole detailed map because it had become to large.

After a lot of work Module:Syrian_Civil_War_detailed_map now successfully inlcudes Module:Syrian_Civil_War_overview_map with all the large towns and strategic places and the huge middle eastern conflict map succesfully includes the new Module:Syrian_Civil_War_overview_map instead of the Module:Syrian_Civil_War_detailed_map

Yet a new problem occurred with the Module:Syrian_Civil_War_detailed_map that I don't understand can't solve.

All villages after +- line 2700 won't display. While before it displayed more than 7000 lines.

Can anyone look at it and try to solve it?

The module is intensively monitored by large amount of people and it should be remain out of fully working order for to long.

Kind regards, --Niele~enwiki (talk) 20:13, 26 July 2017 (UTC)

Per Talk:Cities and towns during the Syrian Civil War#when will the map be restored, the problem may be resolved now? Johnuniq (talk) 01:29, 27 July 2017 (UTC)

Script error

Hi, Could someone please help me to fix Module:Location map's coord2text problem on Bengali wikipedia. See the problem here. Because of this, 200+ pages showing script error. --Aftabuzzaman (talk) 16:42, 22 April 2017 (UTC)

I can't take the time now to fully investigate, but for anyone wanting a quick introduction, the problem appears to be as follows.
Module:Location map has been copied to bn:Module:অবস্থান মানচিত্র.
The latter has been edited to translate error messages.
However, it also translates some other items such as:
local moduletitle = mw.title.new('Module:Location map/data/' .. map)
local moduletitle = mw.title.new('মডিউল:অবস্থান মানচিত্র/উপাত্ত/' .. map)
It is conceivable that a problem could arise because the required subpage is missing or has a problem.
My first approach was going to be pasting a copy of the enwiki module into the bnwiki page (but not saving), then use the preview to show what happens on one of the pages with an error. Would the result (using the enwiki version) display an error? The same error? However, the page is protected so I can't do that, and setting up a sandbox test would take too long.
I see there are some mw.log lines in the module. I wonder if they show any useful information when the module is somehow invoked while editing the module. Johnuniq (talk) 05:40, 23 April 2017 (UTC)
@Johnuniq: Another issue is that the regex for the coord2text function doesn't work because while it searches for strings like 22.467°N 92.117°E, in bnwiki the equivalent text generated by {{Coord}} is <span dir="ltr">২২.৪৬৭°</span> উত্তর <span dir="ltr">৯২.১১৭°</span> পূর্ব. I cannot read the text and don't really know how Lua handles this, so alternatively the module could search for <span class="geo">22.467; 92.117</span>. Jc86035 (talk) Use {{re|Jc86035}}
to reply to me
07:04, 23 April 2017 (UTC)
@Jc86035: Thanks, that sounds like the reason. I worked on bn:Module:Convert three years ago and have code to convert bn digits to en. That might help if the module needs the actual values (I suspect something needs them because I have seen a couple of coord errors in articles where 0° W was used, and that is rejected, while 0° E is accepted. Johnuniq (talk) 07:47, 23 April 2017 (UTC)
@Jc86035 and Johnuniq: I removed those <span dir="ltr"></span><span dir="ltr"></span> tags from module. I set up test pages for you. Please use Module:Location map/sandbox, Module:Coordinates/sandbox & Template:Location map/sandbox (for testing module). Do whatever you need to do. --Aftabuzzaman (talk) 17:08, 23 April 2017 (UTC)

Preliminary results follow. I might be able to think more in a day or two. Pasting {{Coord|44|26|N|15|3|E}} into bn:Special:ExpandTemplates shows a long result. Some of that is:

৪৪.৪৩৩° উত্তর ১৫.০৫০° পূর্ব

At enwiki, the corresponding text is:

44.433°N 15.050°E

The module fails with the "Malformed coordinates" error because it looks for the exact format used at enwiki, namely

<number>°N<space><number>°E

where <number> consists of enwiki digits or a dot. This is due to the regex mentioned by Jc86035 above. Johnuniq (talk) 11:39, 24 April 2017 (UTC)

@Johnuniq: I think i found a solution on persian wikipedia. It seems working. See the test page (& diff). Is it ok? is any correction needed? --Aftabuzzaman (talk) 17:00, 24 April 2017 (UTC)
It seems fine although I have not studied the details. However I tell you about a couple of problems that I noticed. You can fix them, or if wanted, I can have a go later.
First, repeating code is not desirable. I can see the rationale behind using a separate require for Module:Numeral_converter, once for each of the five times it is used. It is possible to do a single require on the first call (that is, only call require if it is needed), but it would make the code a bit harder to follow. However, there are 12 lines repeated in p.main and p.mark. They should be put into a function and called when needed. And the two loops are unnecessary—one is all that is needed and it would be easier to comprehend.
Second, I'm not sure why the new coord2 variable is used, although if I were to study it I would probably see a reason. However, there is a bug. If mw.ustring.match fails to find a match (very possible given that it is working with user input), coord2 would be nil. Executing coord2:gsub would then crash the script. The code has coord2 or '' but that comes too late.
I had a very quick look at bn:Module:Numeral converter and noticed that p.convert is not efficient. If there is ever a problem from it being used many times on a page and the result being too slow, I could speed it up, although the cost would be some increase in code complexity. Johnuniq (talk) 05:19, 25 April 2017 (UTC)
@Johnuniq: Please fix there and for Module:Numeral converter here. You know i don't understand much lua, it is difficult for me to fix them.--Aftabuzzaman (talk) 14:50, 25 April 2017 (UTC)
@Johnuniq: any progress? --Aftabuzzaman (talk) 14:09, 10 May 2017 (UTC)
Sorry, I've been busy, and still am. I might be free in about a week. Johnuniq (talk) 03:22, 11 May 2017 (UTC)
Ok, no problem. I can wait. --Aftabuzzaman (talk) 15:38, 11 May 2017 (UTC)
@Johnuniq: Sorry for disturbing. I waited 3 months but no one even comment here. Could you please take a look. You don't have to explain here, just edit there. Thanks again. --Aftabuzzaman (talk) 16:56, 3 August 2017 (UTC)

@Aftabuzzaman: Please briefly bring me up to date about the current status. Do the three pages you mentioned at "test pages for you" above contain the current wikitext, and are they are ready for me to experiment? I'm wondering about your "I think i found a solution" above. Did that solution get implemented and did it work? It seems bn:মধ্যমগ্রাম is showing the "Malformed coordinates" error due to what I said at 11:39, 24 April 2017 above. I should be able to have a look when you reply, although it won't be quick. Johnuniq (talk) 05:48, 4 August 2017 (UTC)

@Johnuniq: No, i didn't implemented because of what you said at 05:19, 25 April 2017 (UTC). Yes, those three page has same wikitext as en.wiki (with solution). Solution still works but as you said, solution have some problem, 12 lines repeated there, If mw.ustring.match has bug (see your comment at 05:19, 25 April 2017 (UTC)). Yes, they are ready for your experiment. --Aftabuzzaman (talk) 15:37, 4 August 2017 (UTC)
I have started looking at the issue and further discussion is at bn:User talk:Johnuniq#Module:Location map. Johnuniq (talk) 10:22, 5 August 2017 (UTC)

Why does a reverted change persist?

  Resolved

Despite this removal of code "ç" from Module:IPAc-en/phonemes, it still persists in pages that use it. Before the code was added, the error "[invalid input: 'ç']" showed at Mary Hamilton#Lyrics amidst the pronunciation spelling of note 3. Why does this error not show again now the code has been removed? Is this a caching issue? — Sebastian 08:42, 9 August 2017 (UTC)

No, it is not a caching issue. An easy way to see that is to edit the whole page, then preview the result. Observe that the error appears in the preview, then close the window to discard the edit.
Consider:
What should the first template (copied from the article) do? Johnuniq (talk) 10:48, 9 August 2017 (UTC)
Thank you for your patient answer and for the editing trick, which I will use next time. (BTW, it now shows up as error even in the article itself without editing. So, if not caching, at least time appears to be involved somehow. Or maybe that is because I displayed this page first, which may have triggered a rerun of the script.)
The template {{IPAc-en}} is used to display English International Phonetic Alphabet (IPA). The change in question is now under discussion at Template talk:IPAc-en/Archive 2#Addition of /ç/Sebastian 11:30, 9 August 2017 (UTC)
I guess I disagree a bit with Editor Johnuniq. Editor SebastianHelm added the code for 'ç' to Module:IPAc-en/phonemes with this edit and in the same minute added {{IPAc-en|n|i|ç|t}} to Mary Hamilton with with this edit. And all was good; no errors. Half-hour later, Editor Nardog rises to object and reverts. The question was: Why does this error not show again now the code has been removed? (emphasis added). The error did not show because the job queue had not yet got round to refreshing all of the pages that use Module:IPAc-en/phonemes. The error shows now because someone purged or null edited Mary Hamilton or because the job queue got round to refreshing it.
Trappist the monk (talk) 12:10, 9 August 2017 (UTC)
Thank you, Trappist the monk, that explains it very well. — Sebastian 13:00, 9 August 2017 (UTC)
Oh. I was a bit rushed and did not see the point in the OP. When I looked at the article, it was showing the red "invalid input: 'ç'" above, and I imagined the question was why was the error visible. Johnuniq (talk) 10:57, 10 August 2017 (UTC)

Did someone write a text-to-math module yet?

Last I knew, eval() was disabled for security reasons and seemed highly unlikely ever to be available. I ran across a comment on the Refdesk that "The metabolic cost of walking (Cw) in J/(Kg *m) was empirically determined to be 280.5i5-58.7i4-76.8i3+51.9i2+19.6i+2.5 where i is the incline..." which is when I remembered that I'd meant to write some kind of function to evaluate math expressions input as text. I'd probably want to access it indirectly from my old prototype Module:Plotter to do something like {{#invoke:Plotter|eval|280.5*i^5-58.7*i^4-76.8*i^3+51.9*i^2+19.6*i+2.5|left=0|right=0.9|step=0.05}} So I'd want to chunk the text according to at least five basic arithmetic operators and have a pass-through for Math. and Module:Math functions. Anyway, it would be a big project if done right, so I should check to see if anyone has done it. Also I think there was some magic word to do it in wikipedia format and maybe it can be sent out as a call also; I'm not sure how that would compare with just doing it by Lua. I won't ask anyone to write this since it seems like a good exercise to refresh my memory, and not urgent. Wnt (talk) 20:30, 11 August 2017 (UTC)

If {{#expr:}} would do what you want, you could use mw.ext.ParserFunctions.expr to do it. Anomie 23:05, 11 August 2017 (UTC)
I put a simple expression evaluator in Module:Convert/makeunits—search for "evaluate expressions" to see it. It will not do anything like the ambitious project in the OP, but it allows the scale of a unit to be specified with simple operators such as 0.9144^3/3600. It does not support unary operators (negation). I mention that for anyone interested but WOSlinker is correct that #expr should be used. Try this in a module:
return frame:callParserFunction{ name = '#expr', args = { '0.9144^3/3600' } }
However, it uses #expr syntax. Johnuniq (talk) 23:31, 11 August 2017 (UTC)

Need Help with Template:Dts

I want to extend / refine the nowrap=off argument of the dts template in such a way, that only the year is wrapable, (for rationale see here Template talk:Dts). Best way is probably to create a new argument like wrap=year, however I leave that to the implementer. The Lua code for dts is here: Module:Dts. Any help greatly appreciated, thanks. Wikiinger (talk) 10:05, 17 August 2017 (UTC)

Discussion at Template talk:Authority control

  Would someone familiar with Lua and Wikidata please take a look at Template talk:Authority control#Tracking categories. Thanks. — JJMC89(T·C) 17:43, 18 August 2017 (UTC)

Wikipedia:Miscellany for deletion/Module:Property

Hey, I just wanted to make 100% sure that I'm not going to break anything by closing this MfD as delete. I trust Pppery's judgement as a Lua user but since no one else weighed in on the MfD I just want to make absolutely sure that there's no one who needs this who somehow didn't see the MfD. ♠PMC(talk) 04:08, 30 October 2017 (UTC)

Hi everybody! Google Code-in (GCI) will soon take place again - a seven week long contest for 13-17 year old students to contribute to free software projects. Tasks should take an experienced contributed about two or three hours and can be of the categories Code, Documentation/Training, Outreach/Research, Quality Assurance, and User Interface/Design. Do you have any Lua / template related idea for a task (needs documentation, or some code / code changes) and can imagine enjoying mentoring such a task to help a new contributor? If yes, please check out mw:Google Code-in/2017 and become a mentor! Thanks in advance! --AKlapper (WMF) (talk) 19:50, 16 October 2017 (UTC)

@AKlapper (WMF): Would converting a MediaWiki parser code template to Lua count? I'd like to see Template:Term and perhaps some of the draft features in Template:Term/sandbox, redone in Lua for efficiency. In a long glossary article like Glossary of cue sports terms this template can be used hundreds of times. Ideally the |id= parameter would be made more "bulletproof"; I did a little work on that earlier today, but it's still fairly easy to break it, either by producing invalid output or just not useful output (it should produce a "clean" word to serve as a link target, like "break" or "stakehorse", without any extraneous markup, even if people don't read the docs and just put something they shouldn't in there, like a bunch of markup: {{small|'[[Stake (gambling)|Stakehorse]]'}}.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  10:01, 17 October 2017 (UTC)
@SMcCandlish: Thanks for the interest! Anything task that is not too complex (or can be broken down into subtasks) is welcome, if you volunteer to mentor such tasks or have a mentor in mind! :) --AKlapper (WMF) (talk) 16:04, 18 October 2017 (UTC)
@AKlapper (WMF): This could be broken down into subtasks, though rather sequential ones; someone who knows Lua well could do the whole thing within the 2–3 hour limit (someone skilled at the MW implementation of Lua for Scribunto modules could probably do it in half an hour). I haven't tried mentoring, but could give it a whirl, though I know other languages much better than Lua, otherwise I would just whip up this module myself.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  20:53, 19 October 2017 (UTC)
@SMcCandlish: We can have sequential tasks in GCI by either adding to the task description that "This task can only be claimed and worked on once task XY has been successfully finished", or even publish followup tasks (so they become available for students to claim) at any stage later in the contest. If you enjoy mentoring students, have some patience, and if mw:Google Code-in/Mentors#Task requirements sounds fine, give it a try? :) I've sent you an invitation via email for the GCI website and would ask you to add yourself to the Mentors table on mw:Google Code-in/2017. Thanks! --AKlapper (WMF) (talk) 13:08, 4 November 2017 (UTC)
Will try to have a look at it soon.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  13:32, 4 November 2017 (UTC)

Help requested with Template:Shortcut

Hello, I am having trouble understanding Lua and would like some help. I'm trying to underline the 'Shortcuts' text in Template:Shortcut, as shown here:

In wikicode I just place the text inside a div block as follows: <div style="display: inline-block; border-bottom: 1px solid #aaa;">[[Wikipedia:Shortcut|Shortcuts]]</div>. But I have no idea how to translate this into Lua.

Could anyone please show me how to do it, or give me a hint about how it could be done? Thank you. Atón (talk) 17:55, 10 November 2017 (UTC)

Atón, I am assuming you are working with Module:Shortcut/sandbox. if you replace
:wikitext(shortcutHeading)
with something like
:tag('div'):css('display','inline-block'):css('border-bottom','1px solid #aaa'):wikitext(shortcutHeading)
, you should get closer to what you want. Frietjes (talk) 19:04, 10 November 2017 (UTC)
But why would we want to underline shortcuts? This would probably just piss off all those who don't like our perhaps too-frequent use of shortcuts and the effect they have on the abiliity to make sense of what people are saying on talk pages.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  19:29, 10 November 2017 (UTC)
SMcCandlish your comment would be more impactful at Template talk:Shortcut#Protected edit request on 11 October 2017. Frietjes (talk) 19:43, 10 November 2017 (UTC)
Thanks, and never mind. I see it's just a proposal to reformat the {{Shortcut}} output and underline the word "Shortcuts", which doesn't trigger the concern I had at all.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  19:50, 10 November 2017 (UTC)
Ah, dank je wel Frietjes! Thank you. Unfortunately, with that code the line comes at the end of the list of shortcuts, not below the heading, as you can see in Template:Shortcut/testcases. I bet it's not too complicated to solve, but Lua looks Martian to me. Would you mind taking a look on how this could be solved? Atón (talk) 20:05, 10 November 2017 (UTC)
Atón, I probably fixed it. basically, you need to break up the statement so that the shortcutList points to the outer div and not the inner div. Frietjes (talk) 21:40, 10 November 2017 (UTC)
Yay!   Thank you. Atón (talk) 09:32, 11 November 2017 (UTC) PD: Frietjes, one last stupid question, how can I remove the colon ( : ) after the "Shortcuts" heading? I've been looking at the code and I can't make any sense of it. Thanks! Atón (talk) 10:25, 11 November 2017 (UTC)
Atón, that's in Module:Shortcut/config. Frietjes (talk) 14:17, 11 November 2017 (UTC)
Thanks! Atón (talk) 14:45, 11 November 2017 (UTC)

Extrapolated world population table

I started {{Pop row wikidata}} for use in World population#Largest populations by country. at the moment, it's not entirely correct since the percentages are calculated using different points in time. the current table in World population#Largest populations by country uses extrapolation, so I was thinking we could probably take the last two wikidata population values and extrapolate automatically. is this a reasonable idea, or is it too much work (or too expensive)? an alternative would be to keep all the population data for the countries of the world in one module, and then extrapolate from that. Frietjes (talk) 21:25, 2 November 2017 (UTC)

@Mnnlaxer: who recently updated {{data China}}. Frietjes (talk) 21:27, 2 November 2017 (UTC)
Thanks for the ping, but I'm not up to snuff on template creation to have an opinion. I do know the current system is certainly jerry-rigged and complicated. I saw List of countries and territories by population density and List of countries and dependencies by population had some old extrapolation dates, and did the best I could to update {{Worldpop}}, {{worldpop-base}} and {{worldpop-daily-inc}}. I agree the percentage of world population is tricky, but it's not usually going to be off that far. But Wikidata certainly seems the way to go. If you always update to the last two data points to get the next year's growth for the world and each country, that makes sense to me. - Mnnlaxer | talk | stalk 21:48, 2 November 2017 (UTC)
@Mnnlaxer: I got something working in Template:Pop row wikidata, which uses a LUA module (inspired by the work in the thread below on the FIFA ranking module) to extrapolate based on the last two population figures in wikidata (including extrapolating from the wikidata entry for Earth). I am still working on the best format for the table. we probably want (1) country (2) population est. and (3) percentage of the world's pop. but, do we also want "last actual population" and "last actual population date"? or density estimates or ...? Frietjes (talk) 17:32, 20 November 2017 (UTC)

Module help

Hello. el:Module:FIFARankingMin This module is finding the most recent value of values of a wikidata property. Can anyone change it to show the lowest value/values with the date in bracket? Just to change the most recent value with the min value. For example for d:Q79800, now is showing 4 (16 October 2017). Is must show 2 (1 August 2017). Check the result here. Xaris333 (talk) 17:13, 18 November 2017 (UTC)

Is el:Module:FIFARankingMin from another module? I'm not sure why there would be a need for a module to find a minimum value. Is there some other module which finds the FIFA ranking? If so, a function to find the minimum should be there. Is there an example of an article where this would be used? I ask because it may be better to address the whole issue of extracting FIFA rankings in one place. Johnuniq (talk) 22:58, 18 November 2017 (UTC)
@Johnuniq: Yes. There is el:Module:FIFARanking. I am using it to fetch the current FIFA Ranking in template el:Πρότυπο:Κουτί πληροφοριών εθνικής ποδοσφαιρικής ομάδας. We need the current ranking, the minimum ranking and the maximum ranking. I think we can't have only one module. If you can correct Module:FIFARankingMin it will be very easy for me to do the Max. The template is been using by all national football teams. This is an example that may help you [1]. Don't worry about the language. Except labels, all the others are in English. Xaris333 (talk) 16:01, 19 November 2017 (UTC)
@Xaris333: See my el sandbox for the results of preliminary work on el:Module:FIFARankingMin. My code should be in el:Module:FIFARanking because only one module is needed, however I did not change that module because it is currently used in some articles. As you will see in my sandbox, if no parameter is given, the current (latest timestamp) ranking is shown. The result is the best ranking if parameter min is used, and is the worst ranking if parameter max is used. I need to read the code more slowly to check it is ok, but I won't do that until you have had a look at it. Johnuniq (talk) 10:00, 20 November 2017 (UTC)
@Johnuniq: Thanks! It's working. I have moved your code to el:Module:FIFARanking. Why "The result is the best ranking if parameter min is used, and is the worst ranking if parameter max is used."? I changed that [2]. It seems OK. One more thing. The data in wikidata has source. How can the module show the source of the data? By fetching data from wikidata with el:Module:Wikidata and el:Module:Wikidata/cite is possible. Why is not with Module:FIFARanking? Xaris333 (talk) 12:58, 20 November 2017 (UTC)
When copying text or module code from one page to another, an edit summary with a link to the source page should be used. My first question was where el:Module:FIFARankingMin came from, and in the future others might wonder where el:Module:FIFARanking came from.
By the way, the best/worst rankings might occur in more than one year. The current code will show only the year that is first encountered in Wikidata.
I can't take any more time on this at the moment. Later I might get a chance to look some more, but I would want to see a clear example of what output was wanted. A simple example where Wikidata/cite does something might also help. Johnuniq (talk) 22:18, 20 November 2017 (UTC)

Location of Module XfDs

There is a discussion about the proper venue for deletion discussions of Module pages at Wikipedia talk:Templates for discussion#Should pages in the "Module:" namespace be discussed at TfD instead of MfD? that might be of interest to Module editors here. ♠PMC(talk) 04:29, 22 November 2017 (UTC)

Probably-simple conversion

It's been requested that Template:Reign be changed so that when neither {{{1}}} or {{{2}}} contain whitespace (i.e., when they both contain only simple dates like "983" or "2017", rather than something like "c. 983" or "2017 BCE"), that the template emit no spacing around the en dash between the two date parameters. That might be feasible to do in some blecherous manner with parser functions, but this really sounds like a job for Lua.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  06:09, 24 November 2017 (UTC)

I can see that parameters 1 and 2 should be as in your examples, but the rule for a module could be to use an unspaced en dash if:
  1. parameters 1 and 2 are pure numbers (no non-digit characters); or
  2. parameters 1 and 2 do not contain a space.
Which of those would you recommend? It doesn't particularly matter because it could always be changed, but if I get time to look at it I would like somewhere to start. Johnuniq (talk) 06:28, 24 November 2017 (UTC)
In the meantime, I've implemented the blecherous solution in Template:Reign/sandbox for Johnuniq's "do not contain a space" option. It spaces the en-dash when there's whitespace in either date, but that includes leading and trailing spaces, and it naturally doesn't space when there's no space between e.g. "c." and the date:
  • {{Reign/sandbox |1207|1272}}r. 1207–1272  Y
  • {{Reign/sandbox |1 October 1207|1272}}r. 1 October 1207 – 1272  Y
  • {{Reign/sandbox |1207|16 November 1272}}r. 1207 – 16 November 1272  Y
  • {{Reign/sandbox |c. 1207|1272}}r. c. 1207 – 1272  Y
  • {{Reign/sandbox |1207 |1272}}r. 1207–1272 {cross} (now fixed)
  • {{Reign/sandbox |1207| 1272}}r. 1207–1272 {cross} (now fixed)
  • {{Reign/sandbox |c.1207|1272}}r. c.1207–1272  N
A Lua solution would make the fixing of common errors like leading and trailing spaces simpler to fix as well as checking for a pure number if option 1 is preferred. --RexxS (talk) 15:47, 24 November 2017 (UTC)

Forgive me, but all this is a little unclear for me; I don't completely understand what SMcCandlish requested or the replies, but you don't have to explain. If you'll look at my comment at User talk:SMcCandlish#Reign that begins "By the way", you'll see that I had asked for an additional option at the Template:Reign. I'm not sure why there is an option (at Template:Reign) for a thin space to follow "r." Maybe that is what is used in publishing, but I think a simple, regular space after "r." looks nice. I just wanted it to be non-breaking, and with no spaces either side of the years; it looks like the first one in the list above is the one I was looking for. If you want to get rid of the thin space option (at Template:Reign), that would be fine with me, but maybe some editors prefer it; that's why I asked for an additional option. I kind of understand the list of items above; I understand that there may be times when "r. c." before the first year should be used, and that there may be times when a complete date is known and should be used. In the one with "r. c.", I hope it is non-breaking between both the "r." and the "c." and after the "c.". Well, I very much appreciate your help with this.  – Corinne (talk) 16:09, 24 November 2017 (UTC)

Forget what I wrote here. I just looked at the template page (Template:Reign), and it looks really good now. (Why would you want to let the line break after "r.", though? It's just one letter.)  – Corinne (talk) 17:05, 24 November 2017 (UTC)

@Corinne: The thin-space stuff was just wrong, and I removed that code before this thread even started here. One would not "want" to let the line break after "r.", it just would be possible do so (i.e., as an incidental side effect) if the template were used as {{reign}} 1207–2172; the undesirability of this result is the primary reason to fix the template to just parse different sorts of data in {{{1}}} and {{{2}}} and ti not emit a spaced en dash when the unspaced one is needed.

RexxS's sandbox version is already an improvement, and I think the first two red X cases in his output above are fixable by pre-processing the input with {{Trim}}, while the third is a markup error, so we don't care much. That said, I looked at Template:Reign/sandbox and a) it is forcing display of {{{2}}} even if it's empty, which it should not ("Elizabeth II, r. 1952– ") and it has a hard-coded date in it somewhere with an unspaced "c.", which looks like some temporary test code.

Johnuniq, in answer to your questions, we need no. 2, as no. 1 would unnecessarily space the en dash in the case of {{reign|1952|present}} (it should render as r. 1952–present), which is the most common use case for living monarchs.Anyway, we might not need to use Lua after all; I suppose a call to {{trim}} and another to {{#invoke:String}} are not terribly burdensome. :-)

PS: The italicization option can just be removed; it's against MOS:NUM and MOS:ABBR and MOS:ITALICS, so there is no legit use case for it. I'm going to go remove it now from the extant template.
 — SMcCandlish ¢ >ʌⱷ҅ʌ<  20:23, 24 November 2017 (UTC)

Thanks for spotting that hard-coded date that I'd been using to test the string.find function. What do you want to display for {{Reign/sandbox |1207}}? Are you expecting 1207 or 1207–? Here are the test cases as currently implemented:
  • {{Reign/sandbox |1207}}r. 1207– 
  • {{Reign/sandbox |1207}}r. 1207–present
I fixed the trimming of parameters, and I've added the new cases to the "Sandbox testing block" that you made. Cheers --RexxS (talk) 21:09, 24 November 2017 (UTC)
Yeah, edit-conflicted with me on same fix, ha ha. I'm now adding some display options for use in tables. Seems to be in good shape now, though I'm sure it could be make more efficient in Lua if we cared enough (I don't!). Thanks for the help.  — SMcCandlish ¢ >ʌⱷ҅ʌ<  21:12, 24 November 2017 (UTC)
Sorry about the ec. I've now assumed you want {{Reign/sandbox |1207}} to give just 1207, so I've ditched any further output if parameter 2 is missing. It still works (I think) when parameter 1 is empty.
  • {{Reign/sandbox ||1207}}r. ?–1207
  • {{Reign/sandbox |2=1207}}r. ?–1207
If you let me or John know when the code has settled down and we have enough edge cases to be certain we've tested for everything (famous last words), I'm sure one of use could re-write it in Lua as the conversion is pretty trivial. My only reservation is that it reduces the potential pool of editors who are comfortable editing these templates once they have become "Lua-ised". --RexxS (talk) 21:33, 24 November 2017 (UTC)
This stuff is easy to do, and to do reliably, in a module. However I don't want to overwrite people's work on the template unless there is a clear agreement here to try it. If prompted, I will quickly produce a module that can be tried in {{reign/sandbox}} (or elsewhere?) and tweaked to do whatever is wanted. Or, stick with the template if it works. Johnuniq (talk) 22:14, 24 November 2017 (UTC)
The work done so far is worthwhile whichever way it's developed because it's prompted us to list a fairly comprehensive collection of possible inputs and desired outputs. I always find that it makes the coding easier if I have all the edge cases in mind as I'm writing. --RexxS (talk) 22:47, 24 November 2017 (UTC)
I'm really glad there are editors like you all who understand this stuff. While you're at it, you might take a look at Template:Circa just to be sure it is up-to-date (no thin space, no italics, etc.) Thanks again for your attention to this.  – Corinne (talk) 01:31, 25 November 2017 (UTC)
With only marginal further effort the mass of stuff I've done with {{Reign}} (you may need to purge the page to see the new documentation) can encompass all the functionality of {{Circa}} and {{Floruit}} and move to a meta-template, with those three templates being shells that just pass stuff to it. I've made a proposal to this effect at Template talk:Reign and notified the other two templates' talk pages. The end result could be generalized enough to handle number ranges, period, without them being date-specific, so the underlying "engine" could be used to make additional templates for things like sports scores and whatever. After being Lua-ized (if we do that) it could also test for specific common input errors like "c.1312" and "ca. 1312" (errors from a MOS:NUM perspective, anyway – both are attested styles), and issue some kind of warning. It could also do my laundry and bring me coffee. >;-)  — SMcCandlish ¢ >ʌⱷ҅ʌ<  09:39, 26 November 2017 (UTC)

Is it possible to reverse lookup of Wikidata items by Lua

Hello. Let me ask bit complicated question here, which relates to both Lua and Wikidata.

subclass of
  brain   edit
▼ 0 reference
+ add reference
+ add value
  • 2. But there are no information relating to giraffe or elephant in the brain page (d:Q1073).

In such situation, is it possible to know "giraffe brain" or "elephant brain" from "brain" page by Lua. In other words, can I know "What uses this item as value of subclass of"?

More technically speaking,

Only from "Q1073" (ID of brain) and "P279" (ID of subclass of), can I get "Q25685967" (ID of giraffe brain) or "Q25683977" (ID of elephant brain) by Lua?

SQID service provides this at this URL https://tools.wmflabs.org/sqid/#/view?id=Q1073 (at middle of the page, Classification -> Direct subclasses -> All. That section lists up 7 pages). But as far as I see mw:Extension:Wikibase Client/Lua, there seem to be no such function which afford reverse lookup. I want to know whether there is function or technique/trick to do this. Thanks.

(This question is splited from discussion at d:Wikidata talk:WikiProject Anatomy) --Was a bee (talk) 11:00, 26 November 2017 (UTC)

Was a bee, you can get the entire table of entries from a property, and then iterate over the list of properties. so, you could walk the tree in one direction, but I don't know if it's possible to go in the reverse direction. you might consider pinging some of the contributors to Module:Wikidata like RexxS. another great resource is the Wikibase Client extension documentation. Frietjes (talk) 13:33, 26 November 2017 (UTC)
I'm pretty sure the Scribunto documentation does not mention any method to achieve this. A good test would be to see how long the SQID service takes to run. If it is always well under one second (even on the first run), it is conceivable a Scribunto function might exist or might be developed. However, it's not, so it won't happen. I see the issue is at d:Wikidata talk:WikiProject Anatomy and someone at d:Wikidata:Project chat might have further ideas. Johnuniq (talk) 22:16, 26 November 2017 (UTC)
@Was a bee: As far as I'm aware, what you see at a Wikidata page like brain (Q1073) is a representation of what is stored in the actual database. So as you observed, there's nothing that contains a link from brain (Q1073) to giraffe brain (Q25685967), or to any of the other subclass instances. As there are no indices generated or stored either, there's no way I can see that you can read the id of any subclasses from what is stored at brain (Q1073). In those sort of cases, the usual means of determining something like whether "brain" is a superclass of other entities like "giraffe brain", etc. would be to scan every entity and look for "brain" as the value for subclass of (P279). Given the time it takes for SQID to return a result, I'm reasonably confident that is pretty much what it is doing. I suppose that it would be possible to write an extension to the WikiBase software that effectively created a cache of all results from SQID searches over all items, and then you could create a function that would do an direct lookup, but there would almost certainly be significant performance hits because of regular cache updates, so it's unlikely to happen. --RexxS (talk) 00:06, 27 November 2017 (UTC)
Thank you. Very helpful advice to me. I understood that SQID uses some special way. And formerly I wondered that protein/gene data structure in Wikidata may be bit redundant (Template:Infobox_gene#Data_structure), but now I've understood that it is well thought-out minimum necessary style. From the help of this talk, I continue to consider the discussion at Wikidata. Again, thank you very much.--Was a bee (talk) 11:00, 30 November 2017 (UTC)

Alexa template

Hi, could someone hack together a Lua module which does what {{Alexa}} does, but using {{IncreaseNegative}}, {{DecreasePositive}} and {{Steady}} and calling data from the article's Wikidata item? (Since the only bot on Wikimedia sites updating this information is on Wikidata and the information changes all the time there's not much point in allowing data to be locally added, but the bot doesn't seem to be perfect yet so it'd probably still be needed.) Jc86035 (talk) 16:06, 16 December 2017 (UTC)

The only article using {{Alexa}} is Loudwire, but Loudwire (Q6686082) doesn't have an Alexa ranking property. Were you thinking that we could get the data from somewhere else? --RexxS (talk) 17:30, 16 December 2017 (UTC)
@RexxS: I'm not entirely sure where the bot scrapes URLs from but it's only adding the property to some items which have websites linked from enwiki currently, so Loudwire would have to use local data until its item has some data added. Currently it uses the {{Increase}} icon, which probably means {{DecreasePositive}} since a numerically smaller Alexa rank is better, but I can't be sure. It would work on the article Wikipedia, which currently has Alexa data added manually, since Wikipedia (Q52) has Alexa rank (P1661) for 20 November (@Tozibb: is Wikipedia in the list of items to have data automatically added? there isn't one for 1 December). Jc86035 (talk) 06:57, 17 December 2017 (UTC)
@Jc86035: I've got something working in Module:Sandbox/RexxS/Alexa with a few test cases in Module talk:Sandbox/RexxS/Alexa. Three questions:
  1. The date is in ISO format for the moment, because I don't know how you want to handle date formatting. The documentation at Template:Alexa is a bit difficult to follow.
  2. I'm returning a note for now if there's no Alexa rank. Did you want to allow local values as an override? or would you prefer to only accept local values when there's no Wikidata?
  3. Would you be able to test/preview the module {{#invoke:Sandbox/RexxS/Alexa|main}}, particularly in some articles that may be edge cases, please?
Let me know if you find any bugs/problems (other than the ones above). Cheers --RexxS (talk) 20:16, 17 December 2017 (UTC)
[Update:] I've implemented date formatting by using a |df= parameter with dmy as default. --RexxS (talk) 22:33, 17 December 2017 (UTC)
@RexxS: Thanks, looks good. It might help to show a reference as well (since December 1 the bot has added references with archive URL etc.), though I don't know how you would do this in Lua. I would personally prefer to accept local values (probably two values, with their own dates and archive links, and no manual setting of the arrow to avoid confusion) if they are more recent than the two most recent Wikidata values, if any. What sorts of articles would be edge cases? Would they be ones with incomplete or invalid data, or ones with no Wikidata item, or…? Jc86035 (talk) 09:39, 22 December 2017 (UTC)
Also, what's the significance of 27 April 1952? Jc86035 (talk) 09:49, 22 December 2017 (UTC)
@Jc86035: Thanks for the amendments. Your code for the local parameters looks good.
It looks like I was working on the opposite understanding of what the icons "Decrease Positive" and "Increase Negative" would mean when applied to rankings.
I usually write the explicit lnk="" (which of course becomes " ... lnk='' .. " when quoted as a string constant) as I find it makes the code more readable when I look back later – I'm not left scanning the line for what the value of lnk is set to. But that's trivial.
The [[File: ... ]] inline construction can use the caption as the html title, and hence the tooltip, so there's no point in trying to set it explicitly.
The only problem I found is that MOS:FONTSIZE sets a bright-line at a minimum font size of 85% of the normal page font size. Because an infobox already sets font-size to 88%, there's no room for making text any smaller in infoboxes, so I've removed that.
I have a problem with getting references from Wikidata because of WP:CITEVAR. Whatever style I use for a reference, it is bound to be wrong in some article. And because editors are free to make up their own citation style, it is impossible to pass a parameter that defines every possible style in use. Frankly I'm so sick of Wikidata-haters picking fights over that sort of trivia – and believe me, they will – that I simply refuse to implement references from Wikidata. I hope you can understand that.
The sort of edge cases I had in mind was where you had a mixture of local and Wikidata-derived parameters. Do we have to deal with cases when the latest date is from Wikidata and the previous one is locally-supplied? or are they so rare that a manual fix is easiest? It needs somebody who knows the prevalence of those sort of situations to be able to make the judgement. Obviously, we ought to write code robust enough to cope with malformed dates without splodging cryptic red error messages all over an infobox, but what behaviour is best when that happens?
The date is a date far enough back in pre-history that it must be earlier than any possible bot-created date from Wikidata. It's used to create a date for a rank without a date, forcing that rank to be earlier than any other ranks that do have a date. It's also somebody's birthday. --RexxS (talk) 12:13, 22 December 2017 (UTC)
@RexxS: I think it could ignore local values if there are Wikidata values (since the bot is adding them), but it could alternately ignore Wikidata values if the displayed local value is newer, and ignore the local values if the newest Wikidata value is newer. I don't have a preference for either, and all articles which have Alexa rankings with arrows should have had the arrow added manually so there is no precedent for using two values. However, the bot will probably be adding data for every item with an official website (P856) on Wikidata from January, so local values themselves – if not required after a Wikidata RfC, anyway – should be rare enough that the former is possible without significant decrease in data quality. There could be a tracking category for local values, or Alexabot could move them automatically if there are archive links. Jc86035 (talk) 12:31, 22 December 2017 (UTC)
@Jc86035: OK, then I would suggest that you might want to create Template:Alexa/sandbox as a wrapper for the module, and try that out in a few selected articles - or at least preview it, pending negotiations on implementing the functionality of fetching the data directly from Wikidata. Good luck with that (sincerely!). We can always tweak the code as we get feedback once we have a few trials going. Please ping me if there are are any problems, or if you want another voice to help explain the value of this sort of process. Cheers --RexxS (talk) 14:01, 22 December 2017 (UTC)
@RexxS: Done. By the way, I think referencing could potentially be done as |ref=no/|ref=yes (equal to |ref=CS1), with case-insensitive options |ref=CS2, |ref=harvard, |ref=author-title etc. and default to either no or CS1, though using parenthetical citations would mean that a second template (or the same template with |ref=text/inline or something) would have to be added at the bottom of the page. Unless there's something objectionable about even that? Jc86035 (talk) 14:17, 22 December 2017 (UTC)
There is. See the train-wreck at Wikipedia:Featured article candidates/Jane Austen/archive2 and Talk:Jane Austen/Archive 7 (and then archives 8 and 9) for a classic example, if you really want to get depressed about the issue. I've already lost too much of my life to senseless arguments like that. --RexxS (talk) 14:50, 22 December 2017 (UTC)
@RexxS: As depressing as that is to read (I didn't get to the end of it), I think it should be fine because most articles on websites use CS1 and should only very rarely (or even never) use MLA or other formats, which could be added as options if needed. Is there an existing Lua module which can format a reference in the different styles based on one parameter? (Templates like {{Single chart}} appear to get away with only allowing CS1, for what it's worth.) Jc86035 (talk) 17:59, 22 December 2017 (UTC)

Different content by IP/OS country/browser language settings

Hello, as the title says, I need to know if there is a way to display different content according to geolocation provided by user IP address, and/or OS country settings, and/or browser language settings.

If it's not, which technical hurdles should be overcome to be able to use it in the Wikipedia through a template/module?

I have zero knowledge about coding. But I've looked into the Lua reference manual from mediawiki.org, and haven't found anything useful. I left a similar message in the support page there.[3]

Thanks in advance. Mapep (talk) 21:35, 8 January 2018 (UTC)

I'm about 99% certain this can't be done in Lua. The difficulty is at least twofold: one is parser caching; the second is privacy. The techies don't like fighting with the former and the general view to the second is "the more private, the better". What do you want to do? Maybe we can figure something else out. --Izno (talk) 22:14, 8 January 2018 (UTC)
Hi, thanks for your fast response. I can't see why this would be against privacy, but it has some practical uses. In particular, I was looking for a way to display values in the user's currency. I know this probably could be done by adding a setting in user preferences. However, this would not work for a casual reader which is not a registered user.
I've been doing some experiments with currency related templates. Here in the enwiki there are two templates, one for currency conversion and the other for inflation adjustment. My idea was to create a new one to combine it with them, to show inflation adjusted values in a currency the reader knows best (its own).
Probably is not a big deal in this wiki, since most values will be displayed in USD or GBP, and perhaps EUR, all three with close rates. But I come from the spanish wiki, and we have about 20 different currencies with figures that vary greatly. Mapep (talk) 22:36, 8 January 2018 (UTC)
You could probably do that with Javascript, but that would probably not be supported at a site-wide level on any wiki (but who knows?), which would mean a gadget, so no unregistered users unless they were using a Greasemonkey script. --Izno (talk) 23:36, 8 January 2018 (UTC)

mw.loadData

Is there a way to only load data with mw.loadData if certain conditions are met? My module only uses it occasionally and it would seem inefficient to always load a large table. Szqecs (talk) 03:34, 11 January 2018 (UTC)

Sure, just put whatever if logic is wanted in front of mw.loadData. The same applies to require. They are just statements which can be called if certain conditions are met. Johnuniq (talk) 03:46, 11 January 2018 (UTC)

Need help with code using lang:formatNum()

Hi. I need help with a problem at line 60 of my module Module:Sandbox/Szqecs/New Taiwan dollar that uses lang:formatNum(), as shown in User:Szqecs/sandbox. Thanks. Szqecs (talk) 05:17, 12 January 2018 (UTC)

I made several changes (diff) to remove the global variables. The docs at mw:Extension:Scribunto/Lua reference manual#mw.language:formatNum assume you have put a language object in a variable called lang. That means you have to use the provided function to create the object. The idea is that you might want the formatting as done at enwiki, or the formatting as done somewhere else, and the language object specifies what language is wanted. Johnuniq (talk) 06:18, 12 January 2018 (UTC)
Thanks! Szqecs (talk) 07:16, 12 January 2018 (UTC)

Template feedback

Hi. I'd like to request some feedback on Template:New Taiwan dollar. Thanks. Szqecs (talk) 13:38, 12 January 2018 (UTC)

Lua request for form

Hi all

I can't find a place for a Lua requests on Wikidata like here so I'm hoping someone can help me out, I want to create a very easy to use form for the Wikidata Data Import Hub for people to record new datasets. Currently there is a prefilled template which uses Source Editor which many non Wikimedian's find confusing and hard to fill out (one of the key demographics I'm trying to reach). All I want is a when you click a button you get a pop up box with a few fields with a short desciption next to them. I would really love something similar to when you click this link, chose any section and then click add new resource, I understand this is all done in Lua. The fields I would like are (with guidance after the colon):

  • Name: The name of the dataset you want to import
  • Source: The source of the dataset e.g the organisation who created it or published it
  • Link: A URL link to the dataset
  • Description: A short (less than 20 word) description of the dataset outlining the contents e.g A list of protected areas in Pakistan

These fields then then populate a new section on the main Wikidata Import Hub page like so:

==NAME==

Description of dataset Create and import data into spreadsheet Structure of data within Wikidata Format the data to be imported Match the data to existing data Importing data into Wikidata Date import complete and notes
Name:NAME

Source:SOURCE

Link: [LINK here]

Description: DESCRIPTION

Link:

Done:

To do:

Notes:

Structure:

Example item:

Done:

To do:

Done:

To do:

Notes:

Done:

To do:

Notes:

Done:

To do:

Notes:

Date complete:

Notes:

Is this possible/easy for someone to set up? Note: I also asked this request on Wikidata project chat here

Thanks

John Cummings (talk) 23:01, 16 January 2018 (UTC)

John Cummings, your request is not possible in Lua. It can be done in JavaScript possibly, but I do not know where to request that. --Izno (talk) 06:28, 17 January 2018 (UTC)
Hi Izno, thanks for your reply, do you mean that it is not possible to produce the form in Lua, or that it is not possible for Lua to create a new section on a page? If the second one, would it be possible for Lua to offer the same functionality in a different way? Thanks again, John Cummings (talk) 08:33, 17 January 2018 (UTC)
@John Cummings: The Scribunto (Lua) extension cannot create forms. Scribunto can only output wikitext onto a page. VisualEditor could be enabled on the page, or someone could write a form in JavaScript for you. Jc86035 (talk) 10:55, 17 January 2018 (UTC)
Thanks @Jc86035:, it was my understand that the form that pops up on this page when you chose a section and then click add new resource were done in Lua? John Cummings (talk) 23:48, 17 January 2018 (UTC)
It's not done in Lua. A Lua module is only invoked when a page is served. The page you are looking at almost certainly uses JavaScript to either alter the css display property of a block of hidden content or add a new item to the document on a mouse click. Lua doesn't interact with a page like that. You could perhaps make requests interactively on IRC #wikimedia-dev --RexxS (talk) 01:23, 18 January 2018 (UTC)
Thanks very much for the explanation @RexxS:, I'll try your suggestion. Thanks again, John Cummings (talk) 11:26, 18 January 2018 (UTC)

Requesting a LUA coder to assist with something at Wikisource....

There are some templates at Wikisource whose logic has become highly convoluted and where a cleaner LUA version may be better for performance reasons.

The first of these would be https://en.wikisource.org/w/index.php?title=Template:Cl-act-paragraph&action=edit which only just works..

It would be appreciated if this could be converted to a cleaner LUA version, at some point for performance reasons.

I have a few other complex templates that may also benefit from being re-written.

I was advised to ask in here, because there are not necessarily many people with LUA experience on Wikisource.ShakespeareFan00 (talk) 21:00, 21 January 2018 (UTC)

In addition the expertise of LUA coders in analysing modules used by English Wikisource for potentialy malformed code generation ( in relation to the ongoing process of the parser migration would also be appreciated.). I don't have the competence to do this, and changing module on Wikisource has the potential to break hundreds of pages rapidly :( ShakespeareFan00 (talk) 21:03, 21 January 2018 (UTC)

Module:TreeChart so that boxes use more/less than 3 spaces

I'd like to edit TreeChart so that boxes use more or less than three spaces. As you can see at Template:Chart, a given box takes up three cells in the table. I'd like to use more or less than three cells so that a timeline can better be presented, for something like Template:CIEC merge history. Unfortunately, I don't really know Lua. Any suggestions/help would be greatly appreciated. :) Banaticus (talk) 18:12, 20 February 2018 (UTC)

hmmmm.... interesting. it seems the module supports several undocumented parameters, specifically "colspan". did not fully figure out how they work exactly, but they definitely do _something_: see, e.g., the following two copies of the first example, where the 2nd one adds "colspan=7" to the last row:

_____ raw example

GrandmaGrandpa
MomDadAunt Daisy
My brother JoeMe!My little sister

________ with colspan=7 on last row (brother-me-sister)

GrandmaGrandpa
MomDadAunt Daisy
My brother JoeMe!My little sister
would be nice if someone can figure it out and augment the documentation. peace - קיפודנחש (aka kipod) (talk) 16:18, 21 February 2018 (UTC)

Error

I actually doesn't know how to work with Lua. I have seen a script error in one of the pages. I couldn't correct it due to lack of knowledge in lua. The page is: User:Masti/100wikidaysCEEwomen Just scroll down to see that error. Adithyak1997 (talk) 17:06, 21 February 2018 (UTC)

Adithyak1997 You mean m:User:Masti/100wikidaysCEEwomen..the problem is that there are the tables are taking more than 10 seconds total to be generated. Splitting the page into multiple pages can fix that. Galobtter (pingó mió) 17:18, 21 February 2018 (UTC)

Thank you. I will mention this in the talk page of that article.Adithyak1997 (talk) 17:20, 21 February 2018 (UTC)

Module help (2)

Hello again. A user edit Module:FIFARanking so it can show current FIFA Ranking, Man and Min values from wikidata items. (You can see Wikipedia talk:Lua/Archive 6#Module help. Last few days I was adding (and still do) all FIFA Ranking for 1992 to 2017 with sources to Wikidata. Its a lot of work. I think all Wikipedias can use this data. For example see Spain men's national football team (Q42267) ( d:Property:P1352 ). I am planning to suggest the module to all Wikipedias that are using the template Template:Infobox national football team.

But there are some problems with the module. You are my last hope :)

1) Big problem. If a team no longer exist ( Serbia and Montenegro national football team (Q1131732) or Netherlands Antilles national football team (Q1037645) ), the module shows as current ranking the last one they had. But this is wrong. The module must show nothing. If a team no longer exist I thought to use d:Property:P576 as a condition. If the item has P576 then there is no current ranking (after 4 years of the dissolved). But a better solution is to have a condition that the module shows the most recent ranking only if there are not 4 years before the current date. For example, If the last ranking is 4/12/2013 will show the current ranking. If it is 30/11/2013 it will not show it. (Teams inactive for more than four years do not appear on the ranking table). Example: [4]

2) Big problem: Max, Min: the module shows only one date. For example, Spain was at the first place many times. So after the max they must show many dates. But it only shows the first one that appears in the item. The module must show all the dates. Do you have any other more practical idea? Example: [5]

3) Small problem: Wikipedia templates show the dates in brackets in smaller letters/numbers.

4) The module don't show the source. In Greek Wikipedia we are using el:Module:Wikidata/cite but it is working only if we take the information with el:Module:Wikidata.

Can anyone solve any of these 4 problems? Thanks. Xaris333 (talk) 10:51, 2 December 2017 (UTC)

@Xaris333: I am very new to Wikipedia but not new to programming; I think № 1 would be very easy to check for dates in last 4 years or halt display. I am looking at how it all works now. –ASiplas (talk) 18:22, 20 February 2018 (UTC)
@Xaris333: There are now Test Cases(run) it would be good to edit and identify some expected outputs to check; I am working to add a few placeholders now. (Expected output goes as second parameter to preprocess_equals()—blank to start until you or I figure out what output should be and add it there inside quotes) –ASiplas (talk) 00:41, 23 February 2018 (UTC)
@Xaris333: I am trying to finish up but was wondering about Σεπτεμβίου vs. Σεπτεμβρίου; much of the code is duplicated between FIFARanking, FIFARankingMin, and FIFARankingMax. It seems all code should be in FIFARanking where you pass in min / max or whatever through {{template|min}}, etc.
What is preferred spelling of the month? Two files had two different versions—Σεπτεμβίου vs Σεπτεμβρίου.
ASiplas (talk) 00:50, 24 February 2018 (UTC)
Nevermind using mw.getContentLanguage().formatDate() for i18n of month names. –ASiplas (talk) 05:35, 24 February 2018 (UTC)

Linking to icons in Template:Routemap

BSicon

BSicon

 

STR

BSicon overlaid

 
 

STR!~uSTRq

Link to Example works

 
STR!~uSTRq!@Example

Link to Example doesn't work, but at least the rest of the code works properly

 
 

STR!~uSTRq!~ACC!@Example

Link to Example still doesn't work, and now the code is messed up


STR!~uSTRq!@Example!~ACC

Cross-posted from Template talk:Routemap#Possible bug. For context, Template:Routemap/doc deals with the placement of BSicons, or route diagram icons, with the file naming format "File:BSicon xxx.svg". Basically, these icons are placed in square or rectangular "boxes" spread out among a field of rows and columns, e.g.   (STR). It is possible to overlay two, three, or more BSicons into the same "box", as seen in the second example.

The documentation page says that to link a BSicon to another page, you use the code !@ after the BSicon When using icon overlay and icon link for the same icon cell, the icon link separator (!@) must follow the last (top) overlaying icon ID. I noticed that when I try to link an icon that has more than one overlay, the link doesn't work (as shown in the box). How can this be fixed? epicgenius (talk) 18:07, 23 March 2018 (UTC)

@epicgenius: I put a fix in Module:Routemap. The code is too complex for me to be sure of what I'm doing but I suspect my edit fixed the problem. Please purge a couple of articles with complex diagrams and check that they work! Johnuniq (talk) 01:28, 24 March 2018 (UTC)
@Johnuniq: Thanks for making the edit. It looks like it worked, although there aren't many articles/templates that use this function. I tested it on Template:Lower Manhattan transit, where the link shows up even with 5 icon overlays. epicgenius (talk) 01:53, 24 March 2018 (UTC)

Help needed

Hi. I'm making a Lua version of {{S-line}}. However I can't figure out why the table is wider (Module:L-rail/LUL). Help is appreciated. Szqecs (talk) 03:12, 25 March 2018 (UTC)

{{S-rail-start}}
{{S-rail|title=LUL}}
{{S-line|system=LUL|line=Central|previous=Foo|next=Bar}}
{{S-end}}
Preceding station   London Underground Following station
Foo Central line Bar
{{#invoke:Sandbox/Szqecs/L-rail|main|system=LUL|line1=Central|left1=Foo|right1=Bar}}
@Szqecs: It appears to be because the version generated by the module has fewer <br> tags in the text. Since there is nothing stopping the table from expanding, the table expands. I would put a max-width: in ems on the whole table instead of requiring editors to use <br> tags by trial and error to avoid a very wide table (as the current template does); see if that works. Jc86035 (talk) 05:44, 25 March 2018 (UTC)

wanted: module maintainer

hi all.

some years ago, i've written Module:Chart, to plot bar graphs and pie charts using html (as oppose to other techniques, such as svg). until then, charts on wikipedia were generated either by the timeline extension (mw:Extension:EasyTimeline), which creates an image, or by one of several special "chart" templates, that produce HTML code (from one of which i "stole" its ingenious and bizarre way of creating pie charts using <almost> straight html - amazing trick!).

these tools are cumbersome to use, so more commonly, people create charts externally, using, e.g., excel, and upload the images. this is unsatisfactory, because it's practically impossible for other editors to update the numerical data, and such charts are incompatible with the spirit of wikipedia.

the main reason i created the module was to build a tool that squirts out "reasonably attractive" charts, using sane syntax - something that can't be said about either timeline or the specialized chart templates.
my main focus then, was ease of use, i.e., convenient way to pass the numerical data (so the series of numbers were passed as "10 : 20 : 30...", instead of the templates way of "culumn1=10 | column2 = 20 | column3 = 30..."), and i think i succeeded in creating a tool with sane syntax, where it's relatively easy and straightforward to create, and easy to update the numerical data displayed.

this all was in 2013-2014. since then, a few other editors added and improved the module, but to a large extent it remained as i left it in 2014.

a couple of years later, other/better tools arrived, specifically mw:Extension:Graph, Module:Graph which uses the extension, and Template:Graph:Chart that uses the module (developed on dewiki).

i expected the uses of "my" Module:Chart to be ported to the new tools, but apparently, its use continues, and even expands. over the years there were requests for fixes and enhancements in Module talk:Chart. i did respond to bug reports, but usually not to enhancement requests.

seeing that the module is still used, pretty widely, i think it will be good if someone would take ownership of it, maybe even act on some of the requests in the talk page, so i call for volunteers here.

peace - קיפודנחש (aka kipod) (talk) 01:14, 14 February 2018 (UTC)

Thanks for writing such an awesome module! I would like to maintain your module. Luis150902 (talk | contribs) 16:41, 26 March 2018 (UTC)

Canadian election module request

After conferring with a few editors I was encouraged to post here for a template to succeed the old method used here. I posted a brief summary of what the behaviour should be at Requested templates but later decided that a Lua module would be more suited for this task. Jon Kolbert (talk) 02:00, 26 February 2018 (UTC)

@Jon Kolbert: I probably won't write this module myself, but: is this for Canadian elections only; what should the parameters look like (named, numbered, parameter(s) internally separated using other delimiters…); should the called templates like {{Canadian party colour}} also be converted to Lua? I assume you would want one template to generate the entire table. Jc86035 (talk) 10:50, 24 March 2018 (UTC)
@Jc86035: Thanks for the response. I'd say the parameters should be named, something like candidate1name, candidate1party, candidate1votes etc. As Canadian elections already have their separate template, I think it ought to be kept that way just to keep the template simple with as few parameters as possible. That being said, it would not be difficult to adapt the code to work for other countries' elections. Jon Kolbert (talk) 16:24, 26 March 2018 (UTC)

We need your feedback to improve Lua functions

Hello,

If you’re regularly using Lua modules, creating and improving some of them, we need your feedback!

The Wikidata development team would like to provide more Lua functions, in order to improve the experience of people who write Lua scripts to reuse Wikidata's data on the Wikimedia projects. Our goals are to help harmonizing the existing modules across the Wikimedia projects, to make coding in Lua easier for the communities, and to improve the performance of the modules.

We would like to know more about your habits, your needs, and what could help you. We have a few questions for you on this page.

Thanks a lot for your help, Lea Lacroix (WMDE) (talk) 08:50, 27 March 2018 (UTC)

There's a problem with navbar templates.

I saw the message "Lua error in Module:Navbar at line 66: Tried to write global div. Lua error in Module:Navbar at line 66: Tried to write global div." appear on varius pages. Since I lck any clue where the problem is, I think it's best toreport it here. Examples: WP:CIVIL and Jacobite Syrian Christian Church (navbars "Indian Christianity" and "Nasrani people" removed by yours truly in leu of a solution). Please help. Thanks. Kleuske (talk) 13:03, 9 April 2018 (UTC)

looks like a temporary glitch introduced here by Galobtter and Primefac and subsequently fixed here by Trappist the monk. any persistent errors will appear in Category:Pages with script errors. Frietjes (talk) 16:28, 9 April 2018 (UTC)

Module:Unknown parameters

Hello, is it possible to integrate Module:Check for unknown parameters to Module:Infobox itself? Would anyone like to help? Capankajsmilyo (talk) 19:06, 11 April 2018 (UTC)

Seeking assistance

Hello, I'm looking for help with an article table, I'd like to add a numbers column to rank all the entries. The problem with current wiki-tables is if you add this column, when you change one of the entries or rows of the table, you have to manually re-number every entry/row after it. I'm looking for a way to have that done automatically, the way '#' characters will number entries in a list and automatically keep all the list entries numbered consecutively, even if you make changes. It was suggested at Village Pump/Technical that this could be accomished with a Lua code. If anyone here is able to help out with this, it would be appreciated. Thanks - theWOLFchild 14:35, 10 April 2018 (UTC)

There is a phabricator task related to this request. --Izno (talk) 14:39, 10 April 2018 (UTC)

I don't know how a module could help unless it were to write the table for you or were to wrap a table. In either of these cases, the table would need some sort of carefully chosen specific keyword in each row of the table (the # should probably not be used because that character also appears in section links thus: [[Wikipedia talk:Lua/Archive 6#Seeking assistance]]) which the module would replace with n+1 where n is initially 0.

Here is the result of a wrapping experiment:

{{row counter|
<nowiki>{| class="wikitable"
|+test incrementor
!counting
|-
|_row_count
|-
|_row_count
|-
|_row_count
|-
|_row_count
|-
|_row_count
|}</nowiki>}}

note that the <nowiki>...</nowiki> tags wrapping the table markup are required so that the module doesn't confuse the pipes used in the table as pipes used in the module call.

test incrementor
counting
1
2
3
4
5

A keyword than row_count should probably be devised.

Trappist the monk (talk) 15:56, 10 April 2018 (UTC)

Ah, good ole' Ttm... why am I not surprised? You always seem to have the answers for this stuff. Thanks for putting this together. I'd like to add it to the table at List of motor yachts by length. So, each instance of "row_count" is the beginning of a row, right? Do I separate the words "row_count" and the first cell of the row (yacht name) with a pipe? Single or double? Thanks again - theWOLFchild 17:58, 10 April 2018 (UTC)
Don't be jumping the gun and implementing this in article space yet. Give me some time to hack at it some more.
Trappist the monk (talk) 19:09, 10 April 2018 (UTC)
Trappist the monk - Nope, not doing anything yet, I was waiting to hear back from you. Besides, that List is a pretty big table, 183 rows at last count. I'm in no rush to start writing in all that code yet (I'll do it when I'm bored and on someone else's dime). Anyway, I'll wait til I hear further from you. Cheers - theWOLFchild 19:28, 10 April 2018 (UTC)

Well, it mostly works; see my sandbox. But, references are broken. Not sure how to fix that. Ideas?

Is it necessary to parse apart each <ref>...</ref> to get the attributes and content, build a table of the attributes, and then replace the <ref attributes>content</ref> with the return from

frame:extensionTag{ name = "ref", args = attributes_table, content=content };

Trappist the monk (talk) 12:31, 11 April 2018 (UTC)

Some progress. What I failed to understand is that references, and all other html-like markup, are nowikied by replacing '<' with &lt; and '>' with &gt;. So, replacing these character entities with their actual characters 'fixes' the referencing problem; mw.text.decode() is rather a brute-force way of restoring the character entities: '&lt;', '&gt;', '&amp;', '&quot;', and '&nbsp;' because it will restore them everywhere in the table. Not sure that that is the best approach. Perhaps the best approach is to simply and only replace '&lt;' and '&gt;'.
The odd spelling of 'Lц╪rssen' is in the original source and is not my fault.
Trappist the monk (talk) 16:55, 11 April 2018 (UTC)

Moved out of the sandbox and uses template {{row counter}}. If it breaks, let me know.

Trappist the monk (talk) 12:22, 12 April 2018 (UTC)

Trappist the monk, testing ...
test
rank name
1 a
2 b
3 c
4 d
5 e
not sure what went wrong here. Frietjes (talk) 13:38, 12 April 2018 (UTC)
Nor am I. I did tweak the test pattern a bit. The only thing that the module should see as input is a nowiki strip marker with optional leading and trailing white space. The strip marker pattern was malformed; strip markers are hexadecimal, not decimal. But, there are only seven <nowiki>...</nowiki> tags in use on this page at the time of this writing so the decimal/hexadecimal change should not matter. I also replaced the trailing `\"\' with [^\127]* but am at a loss to see how that would have remedied the issue.
Trappist the monk (talk) 14:21, 12 April 2018 (UTC)
  • FYI - seven entries were added to the table at once and it appears all the rows re-numbered accordingly with no issue. So far so good... Thanks again - theWOLFchild 22:01, 23 April 2018 (UTC)

My first Lua module

Would someone mind looking over Module:Italian provinces and Module:Italian provinces/data which are designed to replace the functions of Template:ProvinciaIT and its subtemplates. Any suggestions would be welcome. Thanks — Martin (MSGJ · talk) 19:36, 23 April 2018 (UTC)

Consider adding require('Module:No globals'); at the top of Module:Italian provinces; it can trap unexpected use of globals.
Consider adding local data = mw.loadData('Module:Italian provinces/data'); at the top of Module:Italian provinces and replacing this kind of use:
local p_data = mw.loadData('Module:Italian provinces/data')[args[1]]
with:
local p_data = data[args[1]];
Why the extra return statement in p.region()?
Trappist the monk (talk) 20:48, 23 April 2018 (UTC)
Many thanks for the good suggestions! I tried putting local p_data = mw.loadData('Module:Italian provinces/data')[args[1]] at the top and then using p_data['short'] in a function, but didn't get that to work. Your suggestion is working nicely though. I also see there is no benefit in returning an empty string. — Martin (MSGJ · talk) 21:18, 23 April 2018 (UTC)
The modules are good to go! Some unimportant thoughts follow.
  • Omit semicolon statement terminators (from C).
  • Replace config["link"] (Python) with config.link (Lua convention for alphanumeric keys).
  • Similarly, p_data['full'] is clearer as p_data.full.
  • If the module would usually only be called once in an article, and if the module won't be expanded with hundreds more lines, there is no benefit from having a separate data module—it could be a table at the top of the main module.
  • The current functions are very clean and I wouldn't refactor them, but a purist would argue that a function like p.short should be a single line like:
    return lookup(frame, 'short')
    and lookup would do all the work for each of the p functions to avoid code duplication.
Johnuniq (talk) 03:34, 24 April 2018 (UTC)
There are about 100 provinces currently (and I would guess some similar magnitude historic). The separate data module seems reasonable, and it's not much overhead. --Izno (talk) 04:01, 24 April 2018 (UTC)
Thanks Johnuniq, I have followed those suggestions. Just one query: I was trying to use |link=true and |link=false but I found that Lua did not recognise those as booleans, and false was being evaluated to true. So I am just comparing the text values instead now. Is this normal? — Martin (MSGJ · talk) 07:39, 24 April 2018 (UTC)
The parameters passed to #invoke are always strings so in |link=true the 'true' is a string, not a boolean. I saw your code and it was fine. A more general method is to have a function to translate the string parameter into a boolean. I don't like supporting more options than required so I am inclined to write my own helper functions that permit parameters that are needed for the job, and do not permit more. For an example, search Module:Football manager history for function yes. The modular approach would be to use Module:Yesno. Johnuniq (talk) 08:14, 24 April 2018 (UTC)
It's always useful to make parameter passing as robust as possible because your users can (and will) supply every possible value for the parameters. If the parameter is blank (i.e. |link=), then your module gets the empty string; if they omit the parameter altogether, your module gets the value nil. If you want to pass a boolean, I suggest that you decide on a default (which will be either true or false) and then accept a few likely alternatives as the opposite. I often use something like this:
local link = frame.args.link or ""
link = link:lower()
if link == "true" or link == "yes" or link == 1 then
  link = true
else
  link = false
end
That will accept true or yes or 1 as (boolean) true and anything else, including blank and omitted, as (boolean) false. Similar code can be written to handle passing string or numeric parameter values. You can simplify it; define a default; make it a local function, etc. but writing clean, readable code benefits new programmers who will want to examine your code for their own re-use. That's more important at this stage than optimising the last few microseconds out of the execution. --RexxS (talk) 00:20, 25 April 2018 (UTC)

Module:Message box

Would someone be willing to help with this? – Srdjan m (talk) 09:10, 1 May 2018 (UTC)

@Srdjan m: I need more translations and answers to questions about the bosnian language in order to do this properly, but yes, I can adjust it. There are a few arguments missing from bs:Šablon:Ambox/test. Could you please translate the following arguments (I have put each one on it´s own line) and answer the questions below ? Within parentheses is an explaination of what the argument does.

  • page (page title, fetches it if empty) – stranica
  • subst (used to specify substitution with "SUBST", which is programmed to be disallowed, see mw:Help:Substitution) – zamijeni
  • id – id
  • plainlinks (activates an html style called plainlinks, explained further on mw:Manual:Plainlinks) – plainlinks
  • class – klasa
  • attrs – attrs
  • textstyle – tekststil
  • name (name of the template, fetches it if empty) – ime or naziv
  • smalltext – malitekst
  • sect - How do sentances like "This article needs additional citations" or "This article includes a list of references" change in bosnian when they are used for sections (chapters) ? In english the prefix "this article" is used for the whole page, while the prefix "this section" is used instead for sections. Would it be enough just to change the prefix as in English?
    • sect is odlomak, and the sentence structure is the same.
  • issue – problem
  • fix (allows text to be added to the messagebox, most likely to explain what needs to be fixed) – popraviti
  • date - Also which format is used for dates in bosnia? Currently the module is configured to show the full month name followed by the year.
    • date is datum, and we use two date formats – "3. maj 2018." and "3. 5. 2018."
  • smalltext – malitekst
  • below – ispod
  • smallimage (image specified limited to 20x20px in size) – malaslika
  • smallimageright – malaslikadesno

Translate the following category names. These are categories which the module itself places pages in when they belong in them. If there are existing categories for those, then please use those. "Article message templates", "Article message templates with missing parameters", "File message boxes" and "Talk message boxes". You could translate those category names in the configuration module file, instead of letting me do that, if you want to.--Snaevar (talk) 19:06, 3 May 2018 (UTC)

@Snaevar: Translated the arguments and added the info you asked for. Here are the categories:
"Article message templates" → "Šabloni za informativne kutije o člancima"
"Article message templates with missing parameters" → "Šabloni za informativne kutije o člancima s nenavedenim parametrima"
"File message boxes" → "Šabloni za informativne kutije o datotekama"
"Talk message boxes" → "Šabloni za informativne kutije o stranicama za razgovor"
Let me know if you need more info. :-) – Srdjan m (talk) 19:53, 3 May 2018 (UTC)
@Snaevar: Any update on this? – Srdjan m (talk) 09:46, 11 May 2018 (UTC)

Help needed for bn.wiki

  Resolved

Hi, we have this module on bnwiki which help us to detect english letter. You can see it's example of use here or here. This module have a problem and need improvement. I wrote everything here (#Problem 2). Please help. Thank you. --আফতাব (talk) 23:01, 12 May 2018 (UTC)

One possibility:

p={}
function p.tag (text)
	local t= {};																-- table of html-like tags removed from text
	local no_tag_string;
	local restored_string;
	
	for tag in text:gmatch ('%b<>') do											-- look an html-like substring
		table.insert (t, tag);													-- save a copy
		text = text:gsub (tag, '~', 1)											-- replace the substring with a 'special character'
	end																			-- tilde used here because it was handy and isnt in the '%a' character set
	
	no_tag_string = text;														-- no_tag string is text with all tags replaced with the 'special character'
	
	-- highlighting stuff happens here
	
	restored_string = no_tag_string;											-- initial restored_string is the highlighted text
	
	for _, tag in ipairs(t) do													-- get each tag from the table of tags
		restored_string = restored_string:gsub ('~', tag, 1);					-- and replace each 'special character' in order
	end

	return no_tag_string, restored_string
end

return p;

Copy/paste the above into the code editor and in the debug console put:

=p.tag ('some <big>big</big> text, <small>small</small> text, and <s>struckout</s> text.')

you should get back:

some ~big~ text, ~small~ text, and ~struckout~ text. some <big>big</big> text, <small>small</small> text, and <s>struckout</s> text.

Trappist the monk (talk) 00:25, 13 May 2018 (UTC)

@Trappist the monk: It's works in the debug console but i don't know how add this code into module. Can you please add this here? Thanks. --আফতাব (talk) 14:45, 13 May 2018 (UTC)
@Trappist the monk: Thank you. --আফতাব (talk) 16:18, 13 May 2018 (UTC)

Might be a job for Lua

  FYI
 – Pointer to relevant discussion elsewhere.

Please see Template talk:Abbr#Link error detection; I'm not entirely sure about this one.  — SMcCandlish ¢ 😼  01:58, 13 June 2018 (UTC)

Module:Routemap

Does anyone know how {{Routemap}} could be made to run more efficiently without sacrificing functionality? The module caused Select Bus Service to exceed the template limits earlier this month. (Maybe the module could be split into subpages, although this would also have to be done on about 28 other wikis which also have the module.) Jc86035 (talk) 16:23, 16 June 2018 (UTC)

Viewing a permalink for 23:41, 31 May 2018 at that article, then viewing the parser report shows:
Post‐expand include size: 2097152/2097152 bytes
That means there was an attempt to transclude over 2MB of templates. That limit cannot be avoided (apart from substing some of the templates). No adjustment to the module can fix that problem. The only solution is to examine the output from each template (say in Special:ExpandTemplates) and decide whether there is any fluff that could be omitted without significantly impacting on the result. Johnuniq (talk) 01:27, 17 June 2018 (UTC)
It appears that 72.5% of the template output is inline CSS, based on {{East Coast Main Line diagram}}, so TemplateStyles should significantly take care of that. Jc86035 (talk) 07:48, 17 June 2018 (UTC)
Wow, that would be interesting. Please start planning! Johnuniq (talk) 08:10, 17 June 2018 (UTC)
@Johnuniq: I've created de:Modul:Routemap for testing (and also because {{BS-table}} really is overdue for a replacement over there). There's a lot that could be done just by looking at the source of a test diagram and copying all of the CSS; a lot of it is hardcoded into the table near the top which contains most of the table structure for input into string.format(). Jc86035 (talk) 08:45, 18 June 2018 (UTC)
Already about a 10% reduction in the size of the expanded wikitext. More to come some time later. Jc86035 (talk) 09:34, 18 June 2018 (UTC)
Non-rendered expansions during the processing of the page still count towards the limit and might be reduced without affecting the final result but I haven't examined the code. See Help:Template#Template limits. PrimeHunter (talk) 15:48, 17 June 2018 (UTC)
@PrimeHunter: I tested this partially with an empty transclusion of {{Routemap/sandbox}}. Deleting half of the text in Module:Routemap/sandbox had no effect on the post-expand include size, although maybe {{Rail-interchange}} (which needed a Lua conversion years ago) is also to blame. Jc86035 (talk) 18:24, 17 June 2018 (UTC)

Digit grouping example

It's not immediately obvious how to do this, and I've tried (probably incorrectly due to the lack of examples here) string.format & mw.language:formatNum, but couldn't get either to work 'out of the box'.   ~ Tom.Reding (talkdgaf)  00:29, 18 June 2018 (UTC)

These debug console statements seem to work for me:
=mw.language.getContentLanguage():formatNum (123456789.123) → 123,456,789.123
=mw.language.getContentLanguage():formatNum (123456789.123, {['noCommafy']=true}) → 123456789.123
Trappist the monk (talk) 00:44, 18 June 2018 (UTC)
Thank you Trappist. No wonder mw.language:formatNum( n ), as implicitly suggested in the MediaWiki doc, wasn't working... getContentLanguage() was the unintuitive (to me) bit missing. I'll try to make the instructions more clear.   ~ Tom.Reding (talkdgaf)  12:16, 18 June 2018 (UTC)
@Tom.Reding: It's difficult to make any progress with the weak documentation on MediaWiki. I had to use trial-and-error to figure out that the globalSiteId corresponding to the "be-tarask" code is actually "be_x_oldwiki", and I really think it's time we created our own resource by making pages here that contain useful examples for those calls. The way formatNum works is as a method on a language object, so if you already have a language object available for the language you want to use to format a number, you can write myLangObject:formatNum( number, options ). If you are working on enwiki, which is a monolingual wiki, then mw.language.getContentLanguage() will give you a language object for English. if you're interested in other language formats as well, there's an example call in Module:WikidataIB:
  • {{#invoke:WikidataIB |formatNumber | 123456780.123}} → 123,456,780.123
  • {{#invoke:WikidataIB |formatNumber | 123456780.123 |lang=de}} → 123.456.780,123
  • {{#invoke:WikidataIB |formatNumber | 123456780.123 |lang=hi}} → १२,३४,५६,७८०.१२३
Anybody else interested in creating examples here on enwiki? --RexxS (talk) 21:39, 18 June 2018 (UTC)

Length of table inside code

Hello, is there any limit in table data ? I'm working on Module:IATA and ICAO code/Data‎ and wondering if it would block if too large file? Thanks Bouzinac (talk) 07:36, 9 June 2018 (UTC)

The size is ok, but the style is not good. See Module:Convert/data and Module:Team appearances list/data for examples. I don't have time to say more at the moment but in a couple of days I could have a look at what is needed at Module:IATA and ICAO code/Data. Johnuniq (talk) 11:32, 9 June 2018 (UTC)
As John says, you are making work for yourself by trying to specify everything as a single element. Lua is very efficient at handling tables, so I would always recommend keeping the structure as uncluttered as possible. Perhaps John has a different idea, but I would suggest something like this to get data into the module, as it looks like each item has four pieces of data associated with it:
local p= {}
p.codetbl = {
--Australia/New Zeland/Oceania
	{ 'AAA', 'NTGA', 'Anaa Airport', 'Anaa' },
--Italy
	{ 'AHO', 'LIEA', 'Alghero-Fertilia Airport', 'Alghero' },
	{ 'ALL', 'LIMG', 'Riviera Airport', 'Albenga, Savona' },
	{ 'AOI', 'LIPY', 'Marche Airport', 'Ancona' },
-- and so on
}
You could then create whatever arrays you wished in this sort of way:
p.IATA = {}
p.ICAO = {}
p.WikiName = {}
for k, v in ipairs(p.codetbl) do
	p.IATA[v[1]] = v[3]
	p.ICAO[v[2]] = v[3]
	p.WikiName[v[1]] = v[4]
	p.WikiName[v[2]] = v[4]
end
The overhead in computation is really quite small because of Lua's efficiency with nested tables and it allows you generate reverse-lookup tables quite easily as well. You can make codetbl a local variable if you have no need to export it. This sort of scheme ought to be far easier to maintain and troubleshoot in any case. All of this is probably a bit late considering the amount of work you've already done, but it is something to bear in mind for the future. HTH --RexxS (talk) 12:36, 9 June 2018 (UTC)
I've added error messaging to your Module:IATA and ICAO code because it is nice to know why something isn't producing the expected results. The failed output of [[ | ]] is meaningless.
Do the data in Module:IATA and ICAO code/Data come from an official source that exists on the internet somewhere? If so, perhaps the correct thing to do is to do as I did for the various data tables required by Module:Lang. The data are periodically updated. To keep the lang data tables up to date I wrote a handful of small Lua modules that read data that I get from official sources. The helper module translates the source's format into a table that Module:Lang can use. For example, this html table is used to identify ISO 639-2 codes that have ISO 639-1 equivalents. Module:Language/name/data/ISO 639 synonym extraction tool reads that file and writes a Lua table that Module:lang uses. I copy the table from the source and past it into a sandbox page (because I do this periodically I have one set aside for the purpose). See [6]. Click Show preview to see the results.
Trappist the monk (talk) 13:11, 9 June 2018 (UTC)
Thank you everybody for your tips and help. It is useful and would facilitate maintenance, so I'll follow your tips for sure, all the more as the template is still at first stage. My wonder is that it sometime happens an airport can have only one ICAO or one IATA code. What to do when nil? Example for Canala Airport which ICAO is NWWX ==>
{ '', 'NWWX', 'Canala airport', 'Canala' } ?--Bouzinac (talk) 16:46, 9 June 2018 (UTC)
You might modify RexxS's code so that it looks like this:
p.IATA = {}
p.ICAO = {}
p.WikiName = {}
for k, v in ipairs(p.codetbl) do
	if '' ~= v[1] then		-- if iata code is defined for this airport
		p.IATA[v[1]] = v[3]
		p.WikiName[v[1]] = v[4]
	end
	if '' ~= v[2] then		-- if icao code is defined for this airport
		p.ICAO[v[2]] = v[3]
		p.WikiName[v[2]] = v[4]
	end
end
Trappist the monk (talk) 17:10, 9 June 2018 (UTC)
Thank you gentlemen! I'll work it out sooner or later :) --Bouzinac (talk) 20:27, 9 June 2018 (UTC)
Ok, I've given some tries at Module:IATA and ICAO code/sandbox‎ and Lua still not behaving as expected with data in sandbox being
 { 'AAA', 'NTGA', 'Anaa Airport', 'Anaa' }
. Any clue? Thank you again, folks. --Bouzinac (talk) 13:50, 10 June 2018 (UTC)
Have a look at Module:IATA and ICAO code/data/sandbox1 - note that the data module internally constructs all of the auxiliary arrays p.IATA, p.ICAO and p.WikiName which are exported to the module that uses them. That means that they are constructed once per page load and are then available in as many modules or functions you want to use them in. I think that Module:IATA and ICAO code/data/sandbox on line 3 has 'WikiName' and 'airportCityName' transposed compared with what you wrote at Module:IATA and ICAO code/data.
I've constructed a few example functions in Module:IATA and ICAO code/sandbox1. As you can see, the name values are immediately accessible via the IATA or ICAO code as an index to the respective table/array, which is accessed as part of the table you use to import the data - you called it master. So master.IATA["LSS"] contains "Les Saintes Airport" for example. I've done a few tests for you to look at at Module talk:IATA and ICAO code/sandbox1. Hopefully that will give you a start in whatever functionality you want to create. Cheers --RexxS (talk) 17:16, 10 June 2018 (UTC)
Thank you everybody and a coffee for Trappist the monk (talk · contribs) ! I think we're it. I'll put the sandbox code into primary code. Then further tests and parameters and data and then we might tell the template/module are functioning and usable. Un grand merci, again ! Bouzinac (talk) 18:55, 10 June 2018 (UTC)
The question that I asked but apparently not well enough, is: can the iata and icao airport names ever be different? You answered the question I didn't ask about the length of the iata and icao codes. Also, before you rush off to make this code live, I added a couple of TODOs: what should the table assembly code do when it encounters empty-string iata or icao codes in the tables in master? I think that nil or empty string values should be skipped.
Trappist the monk (talk) 19:20, 10 June 2018 (UTC)
An IATA code will ever be different from an ICAO code, for the very reason they do not have the same length (3 positions versus 4 positions). And to my mind, these codes should always refer to an airport (hence the link to the wiki airport page). Sometimes, you might have an old IATA code referring to an old airport and a new one. Ex : NKC nowadays ==> Nouakchott–Oumtounsy International Airport and before ==> Nouakchott International Airport, now closed. It is obvious only current and valid codes are to be shown. Nevertheless, an airport might happen to have only IATA code and not ICAO (and vice versa). Say : Canala airport, only NWWX and Kourou airport, only QKR. Did I reply to your interrogation? I'll look at your todo lists, so let's keep in sandbox for time being. Bouzinac (talk) 20:07, 10 June 2018 (UTC)
No, you did not. My question was about airport names can the name associated an iata code be different from the name associated with the 'equivalent' icoa code?
Trappist the monk (talk) 20:35, 10 June 2018 (UTC)
OK, get it. IATA and ICAO always refer to one airport, so same name result.--Bouzinac (talk) 20:39, 10 June 2018 (UTC)
Hello @Trappist the monk:, I've added an UPPER function. Are you content with the sandbox code scripting, may I put it into main code? Bouzinac (talk) 09:16, 11 June 2018 (UTC)
It occurs to me to wonder if some or all of the functions that Editor RexxS wrote in Module:IATA and ICAO code/sandbox1 should be included. Perhaps they'll be useful in future, perhaps not.
Trappist the monk (talk) 11:46, 11 June 2018 (UTC)
More things that occur to me:
  1. the function is called recode() but that doesn't seem like a very sensible function name to me; the name should either be specific to what the function does (it makes a wikilink) or very generic like main() – not a good choice if you elect to include Editor RexxS's functions.
  2. the data tables contain an airport name (IATA, ICAO) and a wkilink label (WikiName). The airport name is used as a wikilink target so the documentation in Module:IATA and ICAO code/sandbox should say that index[3] of the tables in master is the name of a wikipedia article about the airport. Similarly, index[4] is a the airport's city name used as a wikilink label. And this all leads me to suggest that perhaps renaming of the tables is in order, perhaps: IATAIATA_airport, ICAOICAO_airport, and WikiNamewikilink_label (and yeah, written this way because I find underscored names easier to read than CamelCase, especially as the the names get longer)
  3. if you are going to bold the erroneous code in one error message, not really necessary in my opinion, should you not do the same in others?
Trappist the monk (talk) 14:25, 11 June 2018 (UTC)
Not really, have you tried running it? It should not work because it has Lua code in Module:IATA and ICAO code/data/sandbox which is accessed via mw.loadData. I would use .. to concatenate strings rather than table.concat but I guess that's a style issue and doesn't matter. I would hope there is a more efficient way to look up information. At the moment the module loops over 600 items in a table to find what it needs. How many times would this module be used in one article? Roughly how many articles? Johnuniq (talk) 10:40, 11 June 2018 (UTC)
mw.loadData only cares about what they data module returns; it can compute that data any way it wants as long as it doesn't try to do things with frame objects. {{3x|p}}ery (talk) 11:28, 11 June 2018 (UTC)
(edit conflict)
I believe that you are mistaken (you know, it just astonishes the hell out of me to write that). See mw.loadData(), particularly these two bullet points:
  • The value returned from the loaded module must be a table. Other data types are not supported.
  • The returned table (and all subtables) may contain only booleans, numbers, strings, and other tables. Other data types, particularly functions, are not allowed.
As I understand it, there is nothing to restrict restrict how the returned table(s) is/are created, just a restriction that the module may only return tables.
The code in /data/sandbox is called once from /sandbox to create the three tables IATA, ICAO, and WikiName. Because this is an mw.loadData() call, the data tables are created only once per page rendering, not at every {{#invoke:IATA and ICAO code/sandbox}} in that page.
Yeah, .. v. table.concat() is a style choice, but since Lua is 'optimized' for table operations, I have taken to using table.concat except for very simple things.
Trappist the monk (talk) 11:39, 11 June 2018 (UTC)
Addendum: Yeah, the code does run, see Module:IATA and ICAO code/sandbox in the documentation transclusion.
Trappist the monk (talk) 11:46, 11 June 2018 (UTC)

Hello, so that everyone are aware, so far as I know, there is roughly ~12,000 ICAO and when known, ~5,600 IATA codes in the world. It would be specified in a wikipedia airport destination list table as many times as airports flown from this airport. I feel the sandbox module functionning very quick, but there are only France+USA codes in the sandbox data. Would the performance still good with 12000 lines in data ? Thanks again, Bouzinac (talk) 13:52, 11 June 2018 (UTC)

As a guess, probably not an issue. The {{lang}} and {{lang-??}} templates use several individual data modules, seven of which are massaged in one way or another in the mw.loadData (Module:Language/name/data) call. These several modules add up to about 16k lines. In a blank sandbox page I previewed these and took the results from the parser profiling data (drop-down at the bottom of the previewed page):
{{lang|es|casa}} – 8.78 MB/50 MB, 0.108/10.000 seconds
{{#invoke:IATA and ICAO code/sandbox|recode|AAA}} – 1.04 MB/50 MB, 0.010/10.000 seconds
Trappist the monk (talk) 14:50, 11 June 2018 (UTC)
I thank RexxS (talk · contribs) for his proposals but I don't think it is useful to have functions that would ask ""Paris - Charles de Gaulle"" returning result "CDG" (or LPFG). The only use case is to ask "CDG"===>wikilink+name or "LPFG"===>wikilink+name. However, an interesting function would be a module using sparql that would ask wikidata which airport wikilink has CDG as IATA airport code property... Are we set for move from sandbox to daylight? Thanks! Bouzinac (talk) 21:42, 11 June 2018 (UTC)
@Bouzinac: I think you'll find that sparql queries don't run in modules at the moment. You'll also find it is horribly inefficient to search through Wikidata for matching values, especially when you have key-value pairs that won't change very much over many years, and particularly given the fears of vandalism which might occur on Wikidata. In these sort of cases a look-up table is more controllable and efficient, and you have the right solution already. Obviously you could easily generate tables that were indexed by name and had the code as the value (reverse lookup), as easily as I generated the tables that lookup the name from the code. I'm not suggesting an immediate application for that sort of functionality, but it's worth you knowing that it's available, should someone require it in the future. --RexxS (talk) 22:38, 11 June 2018 (UTC)

@Pppery and Trappist: Thanks for the correction above, I was bitten by mw.loadData years ago but did not learn that detail which makes sense. It is counter-intuitive because a key design concept for Scribunto is that it should be possible to translate the wikitext at one point of a page to rendered output without any knowledge of any other wikitext on the page (there is no context). I wonder if the first call to a module that uses mw.loadData could pass a parameter that caused it to change the returned data. A second call would get mw's cache of the data and would therefore have context information from the first call. Johnuniq (talk) 00:04, 12 June 2018 (UTC)

On reflection, I can't think of a way to pass context other than what is globally obvious and fixed, such as the page title. I was wondering if an infobox could load a module and tell it key facts from the infobox, but it appears that it can't. Johnuniq (talk) 00:47, 12 June 2018 (UTC)

Reworked

@Bouzinac: I put a new version of the code in the sandbox (Module:IATA and ICAO code/sandbox + Module:IATA and ICAO code/data/sandbox). With this arrangement, the data is ready for use without the need for code to rearrange it. I guess it doesn't matter because the original version is very fast, but the new version is more efficient!

I noticed the following issues while extracting the data:

  • IATA duplicate codes: AAA, BOD, BVE, XCR.
  • Kourou has no IATA and no ICAO.
  • Ouanary has no IATA and no ICAO.
  • Assumed LSZM and LFSB are alternate ICAO codes for EAP.

Examples:

  • {{#invoke:IATA and ICAO code|main|LSZM}}
    {{#invoke:IATA and ICAO code|main|LSZM}}
  • {{#invoke:IATA and ICAO code/sandbox|main|LSZM}}
    {{#invoke:IATA and ICAO code/sandbox|main|LSZM}}

Johnuniq (talk) 10:12, 12 June 2018 (UTC)

@Johnuniq Thank you for your re-work of the function. However I don't find the data be easy to maintain:I'd rather prefer a data table looking like { 'AAA', 'NTGA', 'Anaa Airport', 'Anaa' } : every info is on a single line, easy to sort, edit and check in an excel sheet, so that everyone can maintain it.
  • You pointed out duplicate codes: so I'd would put a warning somewhere in the doc like "warning, there are twice AAA codes in data // There are twice "Kourou airport" in data //etc ". Is this possible to read the data and express some warnings when duplicates or lacks of airport wikipage name ?
  • Kourou has {'QKR', '','Kourou Airport','Kourou'} (no ICAO code). There is other wrong line of data, indeed.
  • EAP airport is specific because it has two ICAO code, based on the fact your airplane is bound to French side of Mulhouse airport == LFSB // bound to Swiss side == LSZM (France and Switzerland share the same airport building)
So the data (same building) {'EAP','LSZM, LFSB','EuroAirport Basel Mulhouse Freiburg','Basel, Freiburg im Breisgau, Mulhouse'},is wrong :), corrected. I'll work out code for Switzerland
Thank you again !Bouzinac (talk) 11:48, 12 June 2018 (UTC)
And I'm thinking to add the country, to help data be sorted and easy to be maintained. Bouzinac (talk) 11:49, 12 June 2018 (UTC)
The above tweaked per WP:LISTGAP.
Were it possible to get a data dump from the 'official' sources that could be massaged programmatically into the format suggested by Editor Johnuniq, a form that human editors didn't need to maintain, then that format should be preferred. But, I agree with Editor Bouzinac, that the single line, four member table, is more easily maintained by human editors who may be unfamiliar with Lua tables.
Trappist the monk (talk) 12:14, 12 June 2018 (UTC)
Just because I was curious, I repeated test I did before. The parser profiling data show:
{{#invoke:IATA and ICAO code/sandbox|recode|AAA}}
1.04 MB/50 MB, 0.010/10.000 seconds – tables built on-the-fly
1,009 KB/50 MB, 0.008/10.000 seconds – Johnuniq's static table
Trappist the monk (talk) 12:32, 12 June 2018 (UTC)
It's not fair that my code should be rewarded with such a pathetic performance boost! I tried to check a couple of others but it wasn't reasonable because currently the sandbox has old data while the main module has many more entries. I might play with it later, but I guess the take-home message is that there is a fair bit of overhead in Scribunto set up, and having Lua loop over a table a thousand times is comparatively minor. I couldn't do it because I remember when a floating point addition took a millisecond but it works. Johnuniq (talk) 07:15, 13 June 2018 (UTC)

Almost full data

Hello, I've build data from Wikidata. I might have to check for duplicates inside the data. How fares the quickness of the code? Bouzinac (talk) 22:34, 12 June 2018 (UTC)

There is an encoding problem with some of the country information:
Africa, République du Congo
Africa, République démocratique du Congo
Africa, Sainte-Hélène, Ascension et Tristan da Cunha
Asia, République populaire de Louhansk
South America, Saint-Christophe-et-Niévès
The way to check for duplicates and other detectable problems, and to have an easy-to-edit interface, is to enter the data as plain text in a specified format, and have a module which generates the data from that text. An extreme example of that is Module:Convert/data which is 100% generated from the input at Module:Convert/documentation/conversion data/doc. The current project does not need all that complexity but something a lot simpler could be devised.
The performance is fine as shown when previewing a couple of examples, although it is doing a lot of churning work. Johnuniq (talk) 01:22, 13 June 2018 (UTC)
I'm relieved with the performances being still fair. Is there a LUA function that I can copy-paste, so that the documentation of data renders a "human-readable" HTML sortable table with all data ? (or perhaps better to simply copy-paste inside Excel sheet). So that checking for duplicates+bad characters might be easy. Thanks again for this interesting project Bouzinac (talk) 07:02, 13 June 2018 (UTC)
My comment above was about checking during creation of the input data, but output of human-readable text is also possible with a bit of work. I've done that a couple of times, most recently at c:Module:Countries which has several data subpages. The show function displays all the data here using {{#invoke:Countries|show}}. You can copy/paste a table into Excel although Excel has an annoying habit of "fixing" your data so it cannot be relied on. In due course I may be able to help either on the input or the output side but probably not right now. Johnuniq (talk) 07:29, 13 June 2018 (UTC)
I have added a function to Module:IATA and ICAO code, duplicate_check() that scans the raw content of Module:IATA and ICAO code/data looking for improper iata and icao code lengths and for duplicates.
{{#invoke:IATA and ICAO code|duplicate_check}}
{{#invoke:IATA and ICAO code|duplicate_check}}
The code is mostly untested but as you can see it found a duplicate of the DHN code.
Trappist the monk (talk) 12:29, 13 June 2018 (UTC)
That's nice because it has helped detect a problem in wikidata for 2 airports with DHN, corrected both in wikidata and data for the module... Thanks for this useful function, Trappist the monk (talk · contribs) ! Bouzinac (talk) 14:46, 13 June 2018 (UTC)

Multiples codes and automatic alphabetic sort

Hello, I might have another thing to ask you : let's suppose we code {{IATA and ICAO code|GRU|PEK|other codes etc}}, it would produce following result: Beijing–Capital, São Paulo–Guarulhos (Beijing being put alphabetical first, other airports sorted by alphabetical name). Would it be possible ? Bouzinac (talk) 09:34, 19 June 2018 (UTC)

I don't see why not. Instead of {{#invoke:IATA and ICAO code|main|{{{1}}}}}, write {{#invoke:IATA and ICAO code|main}}. In the module, take all inputs from the parent frame, process each code and store the results in a table, write a sort function to sort the results table according to the wikilink label, and output the result as a comma separated string.
Trappist the monk (talk) 11:05, 19 June 2018 (UTC)
I'll give it a try inside sandbox :) Bouzinac (talk) 11:37, 19 June 2018 (UTC)
Hi again, how is that you can have a "virtual" table filtered with frame.args, sort that virtual table, and export out wikilink labels comma separated ? Bouzinac (talk) 13:02, 20 June 2018 (UTC)

First, in the sandbox, start with a clean copy of the working live module using the live data set (we won't be changing that). I moved p.count(). Why is that function in the sandbox?

I created {{IATA and ICAO code/sandbox}} which invokes Module:IATA and ICAO code/sandbox but does not pass it any parameters. I then modifier the module sandbox to take the single argument from the parent frame. These should work correctly:

  • {{IATA and ICAO code/sandbox|KORD}}==>
    {{IATA and ICAO code/sandbox|KORD}}
  • {{IATA and ICAO code/sandbox|ORD}}==>
    {{IATA and ICAO code/sandbox|ORD}}
  • {{IATA and ICAO code/sandbox|AA A}}==>
    {{IATA and ICAO code/sandbox|AA A}}
  • {{IATA and ICAO code/sandbox|AAA}}==>
    {{IATA and ICAO code/sandbox|AAA}}
  • {{IATA and ICAO code/sandbox|AHO}}==>
    {{IATA and ICAO code/sandbox|AHO}}

Trappist the monk (talk) 13:43, 20 June 2018 (UTC)

And support for multiple codes in pframe:
  • {{IATA and ICAO code/sandbox|KORD|ORD|AAA|AHO}}==>
    {{IATA and ICAO code/sandbox|KORD|ORD|AAA|AHO}}
Trappist the monk (talk) 14:02, 20 June 2018 (UTC)
The above example should now be sorted.
Trappist the monk (talk) 14:18, 20 June 2018 (UTC)
(edit conflict) Seemed a good idea to remove duplicate wikilinks; in the above example, KORD and ORD are the same so one got removed from the final list.
Trappist the monk (talk) 15:12, 20 June 2018 (UTC)
I am in awe of such a simple and efficient code. Many thanks Trappist the monk (talk · contribs) !Bouzinac (talk) 15:09, 20 June 2018 (UTC)