Jump to content

Wikipedia talk:Lua: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
Line 166: Line 166:
::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 13:32, 27 August 2020 (UTC)
::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 13:32, 27 August 2020 (UTC)
:::::Errors in station articles (such as [[Yaroslavsky suburban railway line]]) pop up regularly and I have given up trying to solve them. Instead, I use "related changes" to find, for example, that [[Module:Adjacent stations/MZD]] (moved to [[Module:Adjacent stations/Moscow Metro]] and then to [[Module:Adjacent stations/Nizhny Novgorod Metro]]) was changed by {{u|AJP426}} a week ago, then I alert them and they fix it. One more point: the error category can be weeks behind a change. Generally, if you edit a module and it breaks something, the error category will show a dozen or a few hundred errors within a few hours. However, after they are fixed, a trickle of other problems might appear in the category weeks later because it is only updated when pages are rendered. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 23:44, 27 August 2020 (UTC)
:::::Errors in station articles (such as [[Yaroslavsky suburban railway line]]) pop up regularly and I have given up trying to solve them. Instead, I use "related changes" to find, for example, that [[Module:Adjacent stations/MZD]] (moved to [[Module:Adjacent stations/Moscow Metro]] and then to [[Module:Adjacent stations/Nizhny Novgorod Metro]]) was changed by {{u|AJP426}} a week ago, then I alert them and they fix it. One more point: the error category can be weeks behind a change. Generally, if you edit a module and it breaks something, the error category will show a dozen or a few hundred errors within a few hours. However, after they are fixed, a trickle of other problems might appear in the category weeks later because it is only updated when pages are rendered. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 23:44, 27 August 2020 (UTC)
:: [https://en.wikipedia.org/wiki/Category:Pages_with_script_errors This link] may help.If you click on the error message in RED itself a cryptic Lua error summary can be viewed. Apologize if I have repeated some of the information found above. I also try to find if some change occurred on the page that may have initiated the error. -- [[User:Matroc|Matroc]] ([[User talk:Matroc|talk]]) 06:27, 28 August 2020 (UTC)

Revision as of 06:27, 28 August 2020

Retrieving the display title value

Is there a way in Lua, magic words or regular template syntax to get the Display title value of a page (which doesn't involve reading the page content)? Wondering since its a value shown in the Page information of a page. --Gonnym (talk) 07:56, 20 May 2020 (UTC)[reply]

See phab:T154738 * Pppery * it has begun... 13:18, 20 May 2020 (UTC)[reply]
@Gonnym: Is this sufficiently different from {{FULLPAGENAME}} to cause problems for your application?
One workaround might be to use the fact that almost all articles (and some other pages) have an associated Wikidata entry that has a sitelink back to the article using its display title. So for iCarly, season 6 (Q10044351), you can use {{#invoke: WikidataIB |getSiteLink |qid=Q10044351}} to get 'ICarly season 6'. Leaving out the |qid= will use the connected article for the page: {{#invoke: WikidataIB |getSiteLink}} → Wikipedia talk:Lua.
Obviously it won't work on pages that don't have a connected Wikidata item. --RexxS (talk) 16:43, 20 May 2020 (UTC)[reply]
If the Display title is the desired result then the wikidata won't work because the displayed title is: iCarly (season 6) – italics and first character lowercase. Even if it were possible to get the displayed title, how would it be returned?
as wiki markup? ''iCarly'' (season 6)
as html? <i>iCarly</i> (season 6)
Trappist the monk (talk) 16:54, 20 May 2020 (UTC)[reply]
RexxS, I think maybe Wikidata might be overkill for this. The problem isn't that big, so was hoping that there might have been a simple solution. Thanks for the help guys. --Gonnym (talk) 17:11, 20 May 2020 (UTC)[reply]
  • Rough Lua code to parse the page content (definitely needs care (not that expensive (about 1.0 out of 50 MB)):
    • {{#invoke:Sandbox/Matroc/Misc|getdisplay|page=ICarly (season 6)}} (can be used with (safesubst) and getdisplay function can be modified as to error checking and whats to be output.
    • iCarly (season 6) -- result is iCarly (season 6) -- Matroc (talk) 06:54, 31 May 2020 (UTC)[reply]
You may be able to adapt Module:Template parameter value, which relies on the value being introduced by a pipe rather than a colon. However, many articles have their displaytitle modified by a template such as {{lowercase title}}, or indirectly via an infobox template per WP:ITALICTITLE. Certes (talk) 08:36, 31 May 2020 (UTC)[reply]
Thank you for further clarification - my example was a simple solution and does not cover the variety of ways a DISPLAYTILE can appear -- Matroc (talk) 01:56, 1 June 2020 (UTC)[reply]

Radio buttons for switching between historical maps

El'ad is located in Central Israel
El'ad
El'ad
El'ad (Central Israel)
El'ad is located in Israel
El'ad
El'ad
El'ad (Israel)
El'ad 2020 street map overlaid on Survey of Palestine map from 1941

Please could someone help to create radio button functionality for switching between historical maps?

Currently Module:Location map gives the ability for a reader to switch between contemporary map views using radio buttons (see example on the right). For historical maps, comparing what an area looks like today to how it looked historically, there is no template or module which can do the same. It would benefit articles about historical settlements which look very different today (for example Tenochtitlan in Mexico City, Cahokia in St. Clair County, Illinois, Londinium in London and Lutetia in Paris). The best I have been able to come up with is the gif on the right, but it has been fairly derided as overly "distracting".

Would it be possible to extract the relevant code from Module:Location map into a new "Module:Image select" or similar? It doesn't need any of the other functionality (e.g. coordinates, labels) as it can all be covered by the buttons and captions.

Onceinawhile (talk) 09:21, 24 June 2020 (UTC)[reply]

You're looking for {{switcher}} * Pppery * it has begun... 13:56, 24 June 2020 (UTC)[reply]
@Pppery: that is perfect, thank you. Onceinawhile (talk) 14:19, 24 June 2020 (UTC)[reply]

Help find and remove a testing module

Right now Module:SimpleDebug is transcluded into Cynthia Brewer. My assertion is that we should avoid transcluding testing modules. Can someone see if they can remove that use from there? --Izno (talk) 15:01, 20 July 2020 (UTC)[reply]

Commented out the require in Module:TNTTools because it did not appear to be used in that module.
Trappist the monk (talk) 15:18, 20 July 2020 (UTC)[reply]
It comes from {{BrewerColors}} which I believe is a recreation of {{BrewerPalette}} (TfD). I think merging it with the article and then G4 would be a proper course of action. Alternativley it could be removed as too much detail instead relying on the external link to ColorBrewer2.org. --Trialpears (talk) 15:20, 20 July 2020 (UTC)[reply]
No, it is not a recreation. TFD is probably reasonable. --Izno (talk) 15:38, 20 July 2020 (UTC)[reply]
As the nominator of the aforementioned TfD, I can say clearly that {{BrewerColors}} is not a recreation of {{BrewerPalette}} (the latter template used the former). Nor do I see why {{BrewerColors}} should be deleted. @Izno and Trialpears: What's the problem with {{BrewerColors}} exactly? * Pppery * it has begun... 16:08, 20 July 2020 (UTC)[reply]

Throughout the motorsport we use mostly similar color schemes and tables. And in the popular motorsport we use and update the same data but we update it on the different pages doing more edits than we actually need. I made an intermediate solution but it is a bit clumsy. All motorsport community will be pleased if you help us to made a module for the motorsport tables (their common look here. P.S. Also we had two slightly different tables , but probably they also could have connection and receive updates from the same source template/module. The example of the cells from such tables below: {{F1R2020|HAM|HUN}}

1PF
HUN
1

P.S.S. The issue with Module:Sports rbr table is that we can't add Template:F1 race position or bold/italics. Also we need a possibility to add extra column for positions and numbers (in the case of the teams' standings). Corvus tristis (talk) 03:39, 26 July 2020 (UTC)[reply]

Election results module

Hello. Is anyone able to help me sort out Module:Election results/sandbox? I can't work out what I've done wrong to make {{Election results/testcases}} go wrong for the latter two tables. I suspect it's something to do with the second elseif cand then section. There are a few other functions I'd also like to add to it, which I was planning to do by trial and error, but if anyone has a bit of time to assist, I'd be most appreciative. Cheers, Number 57 21:36, 2 August 2020 (UTC)[reply]

cand and sc don't appear to be initialized by your code (Lua inits them to nil) and both are globals. Generally not a good idea to have globals if they can be avoided. Consider adding require('Module:No globals') at the top of your sandbox. It will help find (mis)used globals.
Trappist the monk (talk) 21:54, 2 August 2020 (UTC)[reply]

Hello Trappist. Thanks for your response at Wikipedia talk:Lua, but TBH I don't understand, as I don't know Lua at all (I have no idea what a global is). I saw someone else created this module (which is great) and want to widen its use. However, I don't know how to code it, so have just been messing around doing it by trial and error... If there's any chance you could fix it (if it's a quick fix), that would be great. Cheers, Number 57 22:11, 2 August 2020 (UTC)[reply]

It isn't clear to me what it is that you are wanting to do. If I preview the example templates at Template:Election results/testcases using the live template and module, I see what looks to be correct rendering. I added {{Testcase table}} to give side-by-side renderings.
What is wrong with the live version that you want changed?
Globals are items that have global scope – are visible and changeable (that's the dangerous part) from anywhere in the module. For safety and reliability, every function, table, and variable in a module should be declared local so that its scope is limited to where it is used. Stuff will still go wrong but the wrongness is usually confined to a smaller portion of the code.
Trappist the monk (talk) 22:46, 2 August 2020 (UTC)[reply]
I believe the issue with the sandbox is cand is never set to true, so rows are never populated. But, like Trappist the monk, I don't quite see what you're trying to do in the sandbox. ProcrastinatingReader (talk) 02:22, 3 August 2020 (UTC)[reply]
As as a comment about as I don't know Lua at all. Not sure how wise this is as you'll need to maintain this module and handle errors and feature requests. Just throwing stuff together until it works is almost never the correct thing to do. --Gonnym (talk) 06:39, 3 August 2020 (UTC)[reply]
@Trappist the monk: As a starting point, the current version in the Parliamentary testcases should ideally spit out something like the below.
Party Votes % Seats +/–
bgcolor=Template:Kuomintang/meta/color| Kuomintang 5,813,699 71.88 50 +50
bgcolor=Template:Democratic Progressive Party/meta/color| Democratic Progressive Party 2,274,586 28.12 45 –50
Valid votes 8,088,285 98.57
Invalid votes 117,160 1.43
Total votes 8,205,445 100
Registered voters/turnout 14,313,288 57.33
Source: CEC
@Gonnym: The module already exists. I'd just like to make it more flexible to deal with other types of elections or electoral systems. I can produce a list of features that would need to be incorporated to allow it to cover (probably) 95% of elections if that would help. Number 57 12:46, 3 August 2020 (UTC)[reply]
As an example of an issue you can run into. If the table above will be produced by the module then it's producing semantically incorrect rows (as the last 5 rows aren't header rows) and 2 of the columns aren't following MOS:ABBR and WP:HEADERS. These issues will make any page using this fail FA and should be fixed. Also, the sorting messed up the table. --Gonnym (talk) 12:58, 3 August 2020 (UTC)[reply]
What do you mean by 'semantically incorrect rows'? Perhaps you could show what a corrected version would look like? Number 57 16:04, 3 August 2020 (UTC)[reply]

Need some Lua help for Template:Subject bar

Could someone with Lua skills please look at this discussion:

--Timeshifter (talk) 10:12, 12 August 2020 (UTC)[reply]

Added what I think you're trying to achieve to the module sandbox. See testcases. ProcrastinatingReader (talk) 11:16, 12 August 2020 (UTC)[reply]
ProcrastinatingReader, Thanks! I will ask that your change be implemented in the module. --Timeshifter (talk) 12:01, 12 August 2020 (UTC)[reply]

Any way to see pages where my Lua module is throwing errors?

I've done a little searching on the Wikipedia Lua resources and I don't think this is possible, but it would be great if it was so I figured I'd ask: is there any way to see a list of pages that are throwing errors when running a Lua module? Specifically, I recently revamped the {{LDS}} template, which is used to cite to Mormon scriptures like the Book of Mormon, so that it calls a Lua module (LDSverse). It works great, but there were a few places where people were misusing the original version of the template in a way that would just create broken external links—aka errors that were invisible to the reader on Wikipedia—but now when those bad parameters are passed to the Lua module it tends to create one of those big red Lua script error messages in the middle of Wikipedia pages. I might change how errors are handled to make the module fail more gracefully, but ideally it would be nice to find the handful of pages that are causing the errors and just fix them.

So is there by any chance a page that lists all the instances of the module causing an error? Or any way to somehow (easily) create that? If not, no worries, but I didn't want to find out there is after putting in a few hours of other work! ― biggins (talk) 10:49, 27 August 2020 (UTC)[reply]

I'm not sure if there is a way to see where the errors are, but in general, if you know a way code that you write can produce an error (such as accessing a nil parameter), then your code should always handle it, regardless if there are current errors or not. I see you've added /testcaeses which is great, so try and think of how your code can break, and make sure you handle anything you find. Unrelated, it might be better to move the module to be the same name as the template, as is common. --Gonnym (talk) 10:57, 27 August 2020 (UTC)[reply]
I've been occupied elsewhere for a while and consequently have been very lazy. However, I often monitor Category:Pages with script errors using this link for errors in articles. A couple of days ago I saw some errors (at least two pages, maybe four) which were due to your change to use the module. After working that out, I wondered whether to alert you but decided not to because it can be a bit in-your-face to present a list of problems while you are part-way through a large update. That is, I decided to leave it for a day or two to see if the problem was fixed. That appears to have happened because there is nothing at the link showing an LDS problem now. The advantage of leaving the big red error message is that someone, perhaps me, will notice it and take action eventually. By contrast, some custom error message might never be seen except by occasional baffled readers. Johnuniq (talk) 11:00, 27 August 2020 (UTC)[reply]
One error in that list: Lua error: Book <bm/introduction> not found in Standard Works.. --Gonnym (talk) 11:09, 27 August 2020 (UTC)[reply]
You could try this search. It's currently not returning any results. Certes (talk) 11:12, 27 August 2020 (UTC)[reply]
The problem with using assert() to catch user input errors is that it makes it look like the module is broken so editors are going to shy away from such glaring error messaging; and if they do click that message they are presented with the drop-down that is helpful to the developer but not so helpful to the common editor. Take the time to create error messaging that is useful to the common editor; categorize the errors; provide help text and a link in the error message to that help text. Save assert() and error() for truly broken module code.
Of course, it is common for editors to blithely ignore error messages; they do it all the time with cs1|2 ... Still, no reason to shout at them.
Trappist the monk (talk) 11:53, 27 August 2020 (UTC)[reply]
Many many thanks for all the quick replies, that is all extremely helpful. @Johnuniq: the link you provided is pretty much exactly what I was looking for! And to all the good points made above, I'm torn between shouting at users so that they (and now I) can more easily recognize errors vs handling them more gracefully and inevitably letting errors go unseen and uncorrected for a long while. I will try to get at the best of both worlds. Also, I do plan to move the template to the same name as the module, but I both wasn't sure yet how to do that and wanted to make sure there was consensus to do so too since it looks like renaming/moving it was considered (long ago) and rejected. Anyway, thanks to you all again! ― biggins (talk) 12:56, 27 August 2020 (UTC)[reply]
I've fixed the pages named in that link except Yaroslavsky suburban railway line. No error message appears on the page, and I can't see any obvious faults. Can anyone solve the problem? Certes (talk) 13:19, 27 August 2020 (UTC)[reply]
You can find the error message in the html source:
{{rcr|MZD|Yaroslavsky}}Lua error: expandTemplate: template "MZD color" does not exist.
Trappist the monk (talk) 13:32, 27 August 2020 (UTC)[reply]
Errors in station articles (such as Yaroslavsky suburban railway line) pop up regularly and I have given up trying to solve them. Instead, I use "related changes" to find, for example, that Module:Adjacent stations/MZD (moved to Module:Adjacent stations/Moscow Metro and then to Module:Adjacent stations/Nizhny Novgorod Metro) was changed by AJP426 a week ago, then I alert them and they fix it. One more point: the error category can be weeks behind a change. Generally, if you edit a module and it breaks something, the error category will show a dozen or a few hundred errors within a few hours. However, after they are fixed, a trickle of other problems might appear in the category weeks later because it is only updated when pages are rendered. Johnuniq (talk) 23:44, 27 August 2020 (UTC)[reply]
This link may help.If you click on the error message in RED itself a cryptic Lua error summary can be viewed. Apologize if I have repeated some of the information found above. I also try to find if some change occurred on the page that may have initiated the error. -- Matroc (talk) 06:27, 28 August 2020 (UTC)[reply]