Wikipedia talk:Lua
  (Redirected from Wikipedia:Lua requests)
Module:Message box
It would be great if we could somehow make {{tmbox}} have an opt-in collapsible nature to it. I tried playing around with the lua of the message box for a few hours now, but I can't seem to do it myself. For clarity, I am talking about a situation where we could input:
Extended content
{{tmbox|type=speedy|collapse=yes|headerstyle=font-size: larger;|headertext=Before requesting any edits to this protected article, please familiarise yourself with [[WP:Reliable sources|reliable sourcing]] requirements.|image=[[Image:Stop_hand.svg|40px|]]|text=Before posting an edit request on this talk page, please read the '''[[WP:Reliable sources|reliable sourcing]]''' and '''[[WP:Original research|original research]]''' policies. These policies require that information in Wikipedia articles be supported by citations from reliable independent sources, and disallow your personal views, observations, interpretations, analyses, or anecdotes from being used. <div style="clear:both;"></div> Only content verified by subject experts and other reliable sources may be included, and uncited material may be removed without notice. If your complaint is about an assertion made in the article, check first to see if your proposed change is supported by reliable sources. '''''If it is not, it is highly unlikely that your request will be granted.''''' Checking the archives for previous discussions may provide more information. Requests which do not provide citations from reliable sources, or rely on unreliable sources, may be subject to closure without any other response.}}
To get this. –MJLTalk 04:45, 14 February 2021 (UTC)
Mobile does something very similar today. This is something that should get on the pile for making message box 2.0 (i.e., div-based rather than table-based). For now you should add your own collapsible element if there is some component that you don't think should display by default. In general, I would prefer very much not to add an 'opt-in'. --Izno (talk) 05:31, 14 February 2021 (UTC)
@Izno: the only way for me to add a collapsible is to replace {{tmbox}} with the <table>...</table> tags. –MJLTalk 16:24, 14 February 2021 (UTC)
How so? Just don't attempt to collapse the top element. Add some divs with the appropriate classes internal to the element in question. In general, as I said, I think this is a bad idea right now, and it might be more of a "never a good idea" too. --Izno (talk) 18:25, 14 February 2021 (UTC)
Newbie question
So I am teaching myself Lua by jumping right in and creating modules. One thing that I'm failing to understand is when you can pass an arg to the function via #invoke, how do you do that from another module?
I'll just show you. I wrote Module:Road data/size with the intention that it could be used by multiple modules. Its purpose is to tell other modules what size images called by it should be through the style argument. It works great by invoking it:
{{#invoke:Road data/size|size}} → 20px
{{#invoke:Road data/size|banner|style=infobox}}Script error: The function "banner" does not exist.
How do I call that size function with the style argument from another module? I have variables set up for the two functions in the module:
local sizeModule = require " Module:Road data/size"local shieldSize = sizeModule​.​size​(​style​)​local bannerSize = sizeModule​.​banner​(​style​)
I figured out that you have to put style in brackets otherwise it thinks you're trying to pass the whole function and not the result. I feel like I'm close, but I need a hand. –Fredddie 09:35, 14 February 2021 (UTC)
One way is to split the functions so, for example, this:
function p.banner(frame) local args = getArgs(frame) return p._main(args)end
function p._banner(args) return p​.​_main​(​args​)​end​function p.banner(frame) local args = getArgs(frame) return p._banner (args)end
The other module builds an args{} table before it calls p._banner(args).
You might want to get in the habit of adding
require('Module:No globals')
to your modules. Is it really necessary to tostring() the strings that p._main() returns? Is p._main() an exported function? If not, then
local function _main(args)
is better.
Trappist the monk (talk) 12:22, 14 February 2021 (UTC)
Since you are already using the arguments module, just do exactly what it tells you at Module:Arguments/doc#Recommended practice (and some more that I have added that hopefully makes it easier). --Izno (talk) 18:37, 14 February 2021 (UTC)
Hi all, I've just finished writing Module:Repr, a module for generating string representations of Lua object. The repr function works a lot like mw.dumpObject, except that you can customise the whitespace and indentation, and the output is meant to be mostly valid Lua if you copied and pasted it back into a module. It takes its inspiration from Python's repr function, and is based on https://github.com/Ozzypig/repr (with heavy modification and test cases). Also there is an invocationRepr function for generating string representations of function invocations. If you think the module would be helpful for you, please give it a try, and let me know what you think. — Mr. Stradivarius ♪ talk ♪ 10:50, 27 February 2021 (UTC)
Is this not Module:Dump? --Izno (talk) 20:04, 27 February 2021 (UTC)
It's similar to Module:Dump's _dump function, but with some extra features: the option to choose whether or not to pretty-print tables, some extra formatting options, and the ability to generate string representations of function invocations. And it doesn't come with the "variable = " part at the start. On the other hand, it is not meant for being output on wiki pages directly, so it doesn't contain features for formatting the result in a <pre>...</pre> block etc. — Mr. Stradivarius ♪ talk ♪ 00:47, 28 February 2021 (UTC)
property used more than once on a Wikidata item
I have a module Module:Wdtablerow/listed buildings which pulls data from WD including property P87 (lines 89-100). Now I've discovered that at least one of the Wikidata items e.g. Old Mining Building (Q26262664) I am pulling this property from has two instances of P87. The module only pulls the first use of P87. How do I call all the uses of P87? Nthep (talk) 14:19, 28 February 2021 (UTC)
I presume that you mean P84? Because you are using Module:Wd to interface to Wikidata, isn't your question best asked at Module talk:Wd?
Trappist the monk (talk) 14:53, 28 February 2021 (UTC)
I did and I will. Nthep (talk) 16:10, 28 February 2021 (UTC)
I recently updated bs.wiki's version of Module:Infobox to Module:Infobox with some argument mapping, and I noticed some strange behavior when embedding infoboxes. See Korisnik:Srđan/ugraditest and User:Srđan/test1. There seem to be two extra empty HTML rows between the fields "Instrumenti" and "Rođenje" (analogous to "Instruments" and "Born") whereas on en.wiki it looks like something (perhaps lines 1562?) is applying  style="display:none"  to one of them, but I can't for the life of me figure out why it isn't doing that on bs.wiki. Could someone take a look, please? – Srđan (talk) 17:35, 7 March 2021 (UTC)
Infobox styling
Infobox of mni.wikipedia is align on left as in ꯏꯝꯐꯥꯜ can anyone help to align it(infobox) on right side of a page as in other wikis.ꯂꯨꯋꯥꯡ (ꯆꯥ) 16:12, 15 March 2021 (UTC)
@Luwanglinux: Your Common.css does not have any content. --Izno (talk) 16:31, 15 March 2021 (UTC)
(edit conflict)
Not likely a Lua problem. I think that at en.wiki, this bit of css (particularly line 343) is what renders infoboxes at the right side of the displayed page. There is an equivalent page at mni.wiki but it is empty: mni:MediaWiki:Common.css​.
Trappist the monk (talk) 16:33, 15 March 2021 (UTC)
Can you pliz help with this interface problemꯂꯨꯋꯥꯡ (ꯆꯥ) 16:41, 15 March 2021 (UTC)
I don't have the necessary permission to edit interface pages at mni.wiki so you will have to find someone who does. The simple test is to copy or import en:MediaWiki:Common.css to mni:MediaWiki:Common.css​.
Trappist the monk (talk) 16:48, 15 March 2021 (UTC)
Template error
Hi guys here I am again seeking for a solution ..there seems to be a bug in speciesbox or taxobox in mni.wikipedia,showing annoying ";" template which can't be created either like this mni:ꯀꯕꯣꯀꯩ and this mni:ꯅꯣꯡꯁꯥꯂꯨꯋꯥꯡ (ꯆꯥ) 13:37, 25 March 2021 (UTC)
You will probably want to ask at that module talk page, since I know those modules are generally well-watched. Izno (talk) 18:41, 25 March 2021 (UTC)
Izno's advice is good. Meanwhile, the mess at the top of the infobox includes "solid red; error:colour" and the article is in categories mni:Category:Taxoboxes with the error color and mni:Category:Taxobox articles possibly missing a taxonbar which needs investigation. I put a simplified infobox in User:Johnuniq/sandbox (permalink). It shows what should be at the top of the infobox. Very weirdly, it uses a template called ; which cannot be viewed but which can be edited (see links in sandbox). When I tried that trick to edit the semicolon template at mni, I seemed to get the main page. Johnuniq (talk) 00:25, 26 March 2021 (UTC)
Template:; is really weird! I'm tempted to nominate it for deletion just to prevent future headaches, but based on the history it probably has been functional at some point. I'm currently running a quarry to see how many transclusions it has, since what links here is broken, but the template links table is notoriously slow. --Trialpears (talk) 01:29, 26 March 2021 (UTC)
I was able to Special:WhatLinksHere to work by visiting https://en.wikipedia.org/w/index.php?title=Special%3AWhatLinksHere&target=Template%3A%3B&namespace=​. Unfortunately, it has 434,035 transclusions. For context, the page is inaccessible due to phab:T238285 * Pppery * it has begun... 01:32, 26 March 2021 (UTC)
Looks like deletion isn't the answer then. Perhaps moving it to Template:Semicolon would be a good solution to mitigate the problem until it's properly solved. --Trialpears (talk) 01:43, 26 March 2021 (UTC)
As noted, edirect Template:Semicolon exists and works as a method to display Template:;. Apparently it's a method to avoid a semicolon at the beginning of a line which would be markup. But how many times is a semicolon at the beginning of a line wanted!? It appears to be due to the very mysterious {{Taxobox}}. Johnuniq (talk) 02:20, 26 March 2021 (UTC)
I'm too irritated by the limitations of "what links here" to track down how {{;}} is used but I'll record an item I found. Template:Wd/doc displays ;_ with an abbreviation thingamy that shows "semicolon space" (it looks like that page uses an underscore to show a visible space); wikitext: {{dfn|;_|title=semicolon space}}. I tried previewing a plain semicolon and it breaks so {{;}} or equivalent is needed there. Johnuniq (talk) 02:34, 26 March 2021 (UTC)
The template can be viewed here. Cirrus search suggests only 16 direct uses, including transclusions, but it may be wrong. Petscan thinks there are 417397 transclusions, including indirect ones. Perhaps {{;}} is used once in a widely-used template, which would explain why it is protected. Certes (talk) 10:47, 26 March 2021 (UTC)
My count gives 13,244 direct uses which is slightly more. I'm very tempted just to move it as the current title is very broken and I can't imagine people thinking it isn't an improvement. --Trialpears (talk) 13:04, 26 March 2021 (UTC)
I suspect 99% of uses could be subst'd. The documentation says it's used to avoid confusion with a <dt> tag, by which I think they mean the wikitext for a description list, but that's only a problem at the start of a line. Of course, many templates containing {{;}} might be used at the start of a line, either now or in future. Certes (talk) 13:13, 26 March 2021 (UTC)
13k indeed. We should probably subst its use in any templates. Probably in most talk pages it's a typo for {{;)}}.
The particular template is similar to another one I shipped to TFD recently which I would guess has since been kept. It had similar "accessibility" issues (in the non-technical sense). Izno (talk) 20:45, 26 March 2021 (UTC)
89 possible uses in template/module space. Izno (talk) 20:47, 26 March 2021 (UTC)
Date formatting outside citations
Following up from this VPT thread, I've come across several instances where dates have been used in templates (like {{Spoken Wikipedia}}) and I've wanted to format those dates appropriately according to whether an article is tagged with {{use mdy dates}} or {{use dmy dates}}. To do this, The Earwig mentioned that some of the code in the CS1 module would have to be moved. Would anyone who's familiar with module coding be willing to help? {{u|Sdkb}}talk 05:39, 31 March 2021 (UTC)
That would require great care to avoid stupendously high overhead when previewing or publishing an edit. I would need to remind myself to be sure but ISTR that the CS1 module loads the wikitext of the current page then parses the wikitext to decide whether to use dmy or mdy dates. If (that's if) that is a good idea, it should be done once only per page, not once for every template where someone thinks it would be nice to have auto-formatting dates. My hunch is that this should be done with some software enhancement. I have occasionally wondered whether Scribunto (Lua) could allow a per-page global table that could be written and read using mw calls. That is the sort of thing that would make the idea of automatic dmy/mdy format choice feasible. Johnuniq (talk) 06:53, 31 March 2021 (UTC)
Hmm, good to know. I'm not quite sure what makes it possible to do for references but so expensive to do outside of them; I guess there's something? {{u|Sdkb}}talk 10:04, 31 March 2021 (UTC)
I'm saying that if a reference reads and parses the whole page to get the date format, that information should be available to other modules/templates so they do not have to also read and parse the whole page. There is a way that could be arranged that would involve writing a single module to read and parse the whole page and return a table of what it finds, including the date format. The reference module would then need to use that central module by using mw.loadData which loads the table once per page no matter how many time the central module is loaded. Then another template could (via a module) also mw.loadData the table. Only the first load would involve reading and parsing the whole page. That is how references work now, but the information is part of the reference system and (I imagine, I haven't looked) is not readily available for another template. I think the first step might be a central discussion about the desirability of the scheme if it is technically feasible. For example, your link to the VPT thread did not show much enthusiasm and a comment said "automatic date formatting was abolished". Johnuniq (talk) 02:50, 1 April 2021 (UTC)
Johnuniq, ah, got it, thanks for the explanation. Redrose64, do you have a link to that discussion by any chance? And is what you're referring to the same thing I'm talking about here, or was it the kind of thing where users could set date format preferences? {{u|Sdkb}}talk 03:04, 1 April 2021 (UTC)
this is a clever idea, but i do not think it's a good one. currently, the doc page mentions mw.ext.cattools (which is not yet available on wikimedia wikis), which supposedly will allow asking if current page belongs to some category. it should be straightforward to teach these templates (e.g., {{use mdy dates}}) some known category, that any module will be able to test for. it is not a good practice to read content pages from scribuntu.
(offtopic disclosure: i do it myself, not for content pages but for template pages, because "templatedata" team and "scribuntu" team do not speak with each other. reading templatedata is something that modules want to do often, but unfortunately mw.templatedata scribuntu extension was not yet written. see phab:T107119).
peace - קיפודנחש (aka kipod) (talk) 00:46, 8 April 2021 (UTC)
Get User info through Lua
I'm trying to make a template that takes a username, checks how many edits it has made, and outputs it. I couldn't do that using normal templates and I am wondering whether there's a way of doing this through Lua. --Aknell4 (talk) 19:18, 11 April 2021 (UTC)
In theory you could parse the wikitext of Wikipedia:List of Wikipedians by number of edits (which could be done either in Lua directly or in Wikitext using Module:Page and Module:String), but otherwise this isn't possible with Lua either. * Pppery * it has begun... 21:42, 11 April 2021 (UTC)
Fetching info for a diff ID
I'm trying to get the author username and date from a diff ID number for use in a template. Is there some Lua module or API that could achieve this? If not, is there some way I could fetch a revision of a page and do some string parsing on it to extract this information? Srey Srostalk 01:56, 5 May 2021 (UTC)
I'm pretty sure Lua cannot do this but the API can. The API would require JavaScript which is not callable from a template. In other words, I don't think you can get a template to do this. If no further comments occur here, you might try WP:VPT. Johnuniq (talk) 03:58, 5 May 2021 (UTC)
Return to the project page "Lua".
Last edited on 12 May 2021, at 06:04
Content is available under CC BY-SA 3.0 unless otherwise noted.
Privacy policy
Terms of Use
HomeRandomNearbyLog inSettingsDonateAbout WikipediaDisclaimers