Wikipedia talk:Lua
![]() | To help centralize discussions and keep related topics together, all Wikipedia:Lua subpages' talk pages and Help talk:Lua redirect here. |
![]() | The contents of Wikipedia:Lua/Requests was merged into Wikipedia talk:Lua on 5 February 2016. The former page's history now serves to provide attribution for that content in the latter page, and it must not be deleted as long as the latter page exists. |
![]() | Wikipedia:Lua/To do was nominated for deletion on 21 May 2015. The result of the discussion was keep. |
This page has archives. Sections older than 90 days may be automatically archived by ClueBot III when more than 1 section is present. |
Module:wD
[edit]I can use a query like this <ul style="list-style-type: none;">{{wikidata|properties|qualifier|qualifier|qualifier|qualifier|Q114068180|P54|p580|p582|p1350 |p1351|sep%q= _:_ |format= <li> %p[%s] [%q]</li>}}</ul>
to a list like this:
- Huddersfield Giants, 2013 : 2014 : 1 : 2
- Queanbeyan Kangaroos, 2015 : 2016
- Doncaster RLFC, 2017 : 2018 : 28 : 220
- Keighley Cougars, 2019 : 2023 : 68 : 700
- Newcastle Thunder, 2023 : 2023 : 21 : 52
- Keighley Cougars, 2024 : 2025 : 34 : 227
- Rochdale Hornets 2025
I'd like to use the output to populate a table but it doesn't appear I can't use "|" "||" as a separator, nor can I work out how to write a module that would be the equivalent of a for ... each loop
on a specific property in this case P54. Any pointers gratefully received Nthep (talk) 15:21, 27 March 2025 (UTC)
- Did you try
|
→ '|' and||
→ '||'? What about{{!}}
and{{!!}}
? - —Trappist the monk (talk) 15:44, 27 March 2025 (UTC)
- You might also want to look at Module:Wikidata table — Martin (MSGJ · talk) 15:51, 27 March 2025 (UTC)
- Thanks both. Nthep (talk) 15:58, 27 March 2025 (UTC)
Accessing and extracting data from Wikimedia Commons .tab files
[edit]Hi everyone, quick question: is it possible for a Lua module to access and extract data from a Wikimedia Commons .tab file, such as this one?
I ask because there is a series of values that I see on several pages and that are unsourced and most likely completely wrong. I have a way to get more accurate data from Wikidata, but it would be most useful to be able to use a .tab file.
More concretely, I am talking about European parties' number of representatives in lower and upper houses in EU member states (e.g. infobox of the EPP. I can find the list of national member parties and makes a .tab file that would have, for each row: a national party, its European party of affiliation, its qID, its country, and the name and qID of the relevant lower and upper houses.
If a Lua module could access those files, I could easily make a "for" loop for all lines relating to a given European party to sum the number of representatives in the lower or upper houses.
Does this seem like something that is feasible? Thanks! Julius Schwarz (talk) 19:39, 28 March 2025 (UTC)
- Yes. For just the data portion of that .tab file, try this in a debug console:
=mw.dumpObject (mw.ext.data.get ('Evolution of public funding of European political parties.tab').data
- That snippet returns a sequence of sequences that contain the data.
- —Trappist the monk (talk) 19:51, 28 March 2025 (UTC)
- I am actually not sure what to with that :) Debug console? Julius Schwarz (talk) 21:28, 28 March 2025 (UTC)
- Debug console is at the bottom of every module edit page, here at EUPP_seats/sandbox for example. It's a great way to test simple bits of code; I use it a lot when writing patterns for string.match(), string.gsub(), etc.
- In the example above, the debug console shows the structure of the .tab file as Scributo sees it. From that you could write and test a function or three to fetch yearly allocated/received funding.
- Here is a crude example of what you might be thinking of: Module:Sandbox/trappist_the_monk/tab:
- Edit that page
- scroll down to the debug console
- copy this:
=p.maximum_allocated_get ('2020')
and paste it into the debug console window - Enter; you should get the result: 41834942
- do the same for
amount_received_get()
- Handy tool that debug console (and yeah, I used it when writing this example).
- —Trappist the monk (talk) 22:21, 28 March 2025 (UTC)
- I am actually not sure what to with that :) Debug console? Julius Schwarz (talk) 21:28, 28 March 2025 (UTC)
- There is Module:Tabular data if you want to study the code — Martin (MSGJ · talk) 20:42, 28 March 2025 (UTC)
- Thanks @MSGJ, that looks like something I could work with! Julius Schwarz (talk) 21:28, 28 March 2025 (UTC)
- Module:NUMBEROF is an example which reads data from several Commons pages. It has some rather tricky code which might be mysterious, but the basics of reading data are there. Johnuniq (talk) 06:38, 29 March 2025 (UTC)
- Thanks @MSGJ, that looks like something I could work with! Julius Schwarz (talk) 21:28, 28 March 2025 (UTC)
The purpose of Module talk pages
[edit]Wikipedia:Lua#Unit testing says, "By convention, unit tests for a module like Module:Example are placed in Module:Example/testcases, and are executed on Module talk:Example/testcases." Where was this convention established, and how come it was agreed that it's OK to repurpose a talk page that is supposed to be a place to discuss a corresponding page? —Anomalocaris (talk) 19:31, 25 April 2025 (UTC)
- It is convenient not to make yet another page, and ostensibly, you don't need to discuss the test cases particularly. And even where you do, you always have the main module (or template's!) talk page to do so. That is just the same as documentation pages, which today are bot redirected to the main page. Izno (talk) 01:24, 26 April 2025 (UTC)
- Also, many module talk pages redirect to the corresponding template talk page because almost all queries relate to what the template does. That is for when a template is implemented by a module. It is awkward and inefficient to have two active talk pages because inevitably discussions split and items relevant for a particular discussion are on the other talk page. At any rate, the quoted text is accurate: module writers have followed the convention from the start. There are some exceptions where technical discussion of module details has occurred (so the module talk page is not a redirect). Johnuniq (talk) 03:48, 26 April 2025 (UTC)
Module Request: Implement the MIT licensed Spectral.js approach to subtractive color mixing in Module:colormix ?
[edit]I'm moving this from a declined Phab ticket (T395879) , given that phabricator focuses on changes in Mediawiki as opposed to User side Scribunto modules, which it is clear this would be implemented as:-
"Feature summary (what you would like to be able to do and where):
Mix two colors based on their XYZ or RGB values, using a subtractive model such as (Kubelka-Munk theory), generating a result which can be supplied as a color in situations where a CSS color would typically be provided.
Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
The specfic use case is at: https://en.wikisource.org/wiki/Page:The_color_printer_(1892).djvu/29 where the 'mixed' inks are based on a 'parts' mix of 2 or more defined base inks.
The current approach https://en.wikisource.org/wiki/Module:The_Color_Printer_tone and https://en.wikisource.org/wiki/Module:The_Color_Printer_tone/data uses as weighted blend as an interim measure ( this is understood to be an additive approach and thus may not reflect the behaviour intended in the original printed work.)
Benefits (why should this be implemented?):
Being able to mix color subtractively would assist in being able to potentially more accurately determine and transcribe diagramatic colors in older works. The desire for an algorithmic approach, would reduce the need to manually determine mixes, and allow for colors to be adjusted en-masse in a single location, if the 'base' inks were 'corrected' to account for efforts to 'defade' them.
A MIT Licensed library Spectral.JS exists. (https://github.com/rvanwijnen/spectral.js) which if adapted into a set of functions in a Module:Colormix that could be called from the above mentioned module, would meet the use case quite well.
Beyond the specfic use case provided, being able to support a 'subtractive' (albiet approximated model) more directly would assist various color theory topics on other Wikimedia projects."
I've asked here because I felt a module like this might have wider applicability. ShakespeareFan00 (talk) 06:43, 4 June 2025 (UTC)
- Sounds interesting and feasible. Might be a good use of wikifunctions too? — Martin (MSGJ · talk) 09:20, 4 June 2025 (UTC)
- Already put in a request : f:Wikifunctions:Suggest a function#Subtractive color mix_(Pigment_style) ShakespeareFan00 (talk) 08:21, 5 June 2025 (UTC)
Using string.gsub to substitute %20
[edit]I am trying to use string.gsub to replace space characters with %20
to make a URL work correctly. However gsub sees the %2 and treats it as a capture. I've tried escaping things like %%20
and %%%20
. Any suggestions please? — Martin (MSGJ · talk) 13:48, 12 June 2025 (UTC)
- Are you sure
%%20
didn't solve the issue? Make sure you replace capturing terms on both the matching string and the replacement string, since both can use capture group references. If it still doesn't work, could you point to the code where this happens? Aidan9382 (talk) 14:37, 12 June 2025 (UTC) - (edit conflict)
- I think that it works for me. When I write
=string.gsub ("t t", ' ', '%%20')
in the debug console, I gett%20t
. That's what you want, right? Also, if you don't need to know how many space characters were replaced: mw:Extension:Scribunto/Lua reference manual#mw.uri.encode:=mw.uri.encode ('t t', 'PATH')
→t%20t
- —Trappist the monk (talk) 14:41, 12 June 2025 (UTC)
- Yes thanks both, that is working now. I had another gsub in the next line of the code so I have put this one after both. — Martin (MSGJ · talk) 14:45, 12 June 2025 (UTC)
Use on other language wikis
[edit]I recently rewrote {{OSM Location map}} in Lua (vastly improved performance along with extra features). I have now been asked on the talk page if it might be available via commons to allow other language wikis to use it. Is that an option? and is it desirable? The template has a small amount of embeded bits of text, grouped together to make at least superficial translation possible. For that, plus the documentation, a pasted and customised language specific versions seem to me to make more sense. (A full-blown translation of all parameters etc would be a major piece of work, though).
Having looked at a couple of the 49 versions already on other language wikis, these appear to still be the old template version (or in some cases the 'graph' based broken version of 3 years ago). Is there any mechanism for these to update to the lua module in some way? or alerting someone at the relevant wikis? Thanks for any insights on these issues. RobinLeicester (talk) 22:57, 12 June 2025 (UTC)
- Cross-wiki transclusion is not possible, so putting it on Commons is not helpful. (You can scroll through the children of phab:T121470 for an hour or two if you want for all the wishing.)
- Supporting translation of output text is trivial and I try to do it with every module I work on (a prior piece of presently unused work might be illustrative). Supporting true translation of parameters (i.e. supporting both English and local language versions) is a bit more difficult but I don't think so difficult as major piece of work, per se. You can look through how Module:Citation/CS1 does things if you want, which is the only module locally I know that does it the full way. (There is a foreign module on a few wikis called I18n lying around that I guess makes these things somewhat easier...? It only seems to clog up our local transclusion lists whenever it gets recreated here since we're one of the wikis that can take care of ourselves on the point.)
- Something to review is potentially mw:Synchronizer if you don't mind supporting other wiki use cases, which I guess somewhat answers your 'update to the Lua module'. Note that while this template may exist elsewhere, it may not do the exact same things elsewhere, even ignoring differences of parameter names. Otherwise you're essentially on the hook to alert the other wikis yourself. Putting comments at the relevant talk pages would be step 1, then at local equivalents of WP:VPT or WP:AN possibly (since protection may be a concern to deal with), and then probably step 3 of doing it yourself is to do it yourself.
- Some minor code suggestions since you are here:
- If I have the choice, I try to initialize tables with the relevant values directly rather than appending new values many times in a row, as this module currently does through the first couple dozen lines. This is generally faster in non-interpreted languages so I'd guess that extends to here also.
- Consider where possible using TemplateStyles rather than inline CSS. It's just nicer to edit and I assume it's nicer for browsers to consume at the end of the day, etc.
- Add whitespace around math symbols and after commas please ;_;.
- Consistent capitalization of function names at least.
- Izno (talk) 05:41, 13 June 2025 (UTC)
- Izno has good ideas and I would add that consistent indentation (using tabs) would be nice. I can do that in the sandbox if you like but it would generate an ugly diff. Please investigate
colorCap
which is an undefined global used once. Johnuniq (talk) 09:26, 13 June 2025 (UTC)
- Izno has good ideas and I would add that consistent indentation (using tabs) would be nice. I can do that in the sandbox if you like but it would generate an ugly diff. Please investigate
Rewrite backend of Template:Afd-merged-from
[edit]Thanks to Tule-hog's work at Template talk:Copied#Backend rewrite, the backend of {{Afd-merged-from}} can be rewritten to invoke Module:Copied, much like the rewrite at Template talk:Merged-from#Backend rewrite. Because I have zero experience in such matters: is this a bad idea? If potentially controversial, would I ask VPT or some other venue? FWIW, consensus for rewriting {{merged-from}} was assessed at Wikipedia:Templates for discussion/Log/2025 March 12#Template:Merged-from (no consensus against rewriting the backend of the merged-from template, so long as it doesn't affect functionality
). Thanks in advanced! Rotideypoc41352 (talk · contribs) 19:02, 16 June 2025 (UTC)
- What do you think would make it potentially a bad idea? There's no issue with using one module for multiple templates, which is the only concern I can conceive someone potentially having. Izno (talk) 19:11, 16 June 2025 (UTC)
- Less concept- and more implementation-wise: I just don't know how much Module:Copied would need to be changed, and if adding to the module to minimize changes to Afd-merged-from is a good idea.
- When I copied merged-from's code to Template:Afd-merged-from/sandbox and changed it, the results at Template:Afd-merged-from/testcases (unsurprisingly) look like {{merged-from|...|afd=...}}. This brought up three questions:
- Should I also change Module:Copied to keep the original wording of Afd-merged-from, especially
The discussion was closed on {{{3}}}
missing from the merged-from lookalikes? - Invoking the module allows the template to fail more gracefully.
- At the moment, omitting the AfD page name from
{{Afd-merged-from/sandbox}}
documents a normal merge unrelated to a deletion discussion. Should it instead assume the AfD page name and the merge source are the same? That is, adding{{{1}}}}
to form|afd1={{{afd|{{{afd1|{{{2|{{{1}}}}}}}}}}}}
? - Or should it instead not fail gracefully if that parameter is missing?
- At the moment, omitting the AfD page name from
- Should I also change Module:Copied to keep the original wording of Afd-merged-from, especially
- If I need to clarify something, please feel free to let me know. Thank you! Rotideypoc41352 (talk · contribs) 02:23, 17 June 2025 (UTC)