Wikipedia talk:Lua

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

Do you have small Lua related tasks suitable for new contributors?[edit]

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)

Wikipedia:Miscellany for deletion/Module:Property[edit]

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)

Extrapolated world population table[edit]

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)

Help requested with Template:Shortcut[edit]

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
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! Face-smile.svg 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)

Module help[edit]

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[edit]

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[edit]

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 YesY
  • {{Reign/sandbox |1 October 1207|1272}}r. 1 October 1207 – 1272 YesY
  • {{Reign/sandbox |1207|16 November 1272}}r. 1207 – 16 November 1272 YesY
  • {{Reign/sandbox |c. 1207|1272}}r. c. 1207 – 1272 YesY
  • {{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[edit]

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

subclass of
Normal rank brain Arbcom ru editing.svg 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 (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)

Module help (2)[edit]

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#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 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: [3]

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: [4]

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)

Alexa template[edit]

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[edit]

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, and haven't found anything useful. I left a similar message in the support page there.[5]

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)


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()[edit]

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[edit]

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[edit]

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:


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


Link: [LINK here]

Description: DESCRIPTION



To do:



Example item:


To do:


To do:



To do:



To do:


Date complete:


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


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)