mic_none

Wikipedia:Lua requests Source: en.wikipedia.org/wiki/Wikipedia:Lua_requests

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)[reply]

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)[reply]
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)[reply]

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.orghttps://demo.azizisearch.com/lite/wikipedia/page/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.orghttps://demo.azizisearch.com/lite/wikipedia/page/Module:The_Color_Printer_tone and https://en.wikisource.orghttps://demo.azizisearch.com/lite/wikipedia/page/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)[reply]

Sounds interesting and feasible. Might be a good use of wikifunctions too? — Martin (MSGJ · talk) 09:20, 4 June 2025 (UTC)[reply]
Already put in a request : f:Wikifunctions:Suggest a function#Subtractive color mix_(Pigment_style) ShakespeareFan00 (talk) 08:21, 5 June 2025 (UTC)[reply]

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)[reply]

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)[reply]
(edit conflict)
I think that it works for me. When I write =string.gsub ("t t", ' ', '%%20') in the debug console, I get t%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)[reply]
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)[reply]

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)[reply]

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:
  1. 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.
  2. 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.
  3. Add whitespace around math symbols and after commas please ;_;.
  4. Consistent capitalization of function names at least.
Izno (talk) 05:41, 13 June 2025 (UTC)[reply]
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)[reply]

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)[reply]

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)[reply]
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?
If I need to clarify something, please feel free to let me know. Thank you! Rotideypoc41352 (talk · contribs) 02:23, 17 June 2025 (UTC)[reply]
I'll change as little as possible and see how it goes. Rotideypoc41352 (talk · contribs) 22:47, 24 June 2025 (UTC)[reply]