Wikipedia:Lua/Requests/Archive 3
![]() | This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current main page. |
Archive 1 | Archive 2 | Archive 3 | Archive 4 | Archive 5 |
Module localisation
Hi, ar:Template:Coord uses same parameters as in enWP, but cardinal direction N, S, E and W must be rendered in Arabic as ش, ج, ق, and ب respectively. How ar:Module:Coordinates (sandbox/testcases) should be modified to do so? --Zack (talk) 20:15, 3 September 2013 (UTC)
- You could put the necessary messages in the MediaWiki namespace and then load them using Scribunto's mw.message library. Or you could place the necessary messages in a Lua table (in the module or in a submodule of some sort) and use them from there. Anomie⚔ 11:15, 4 September 2013 (UTC)
- I don't think it's that complicated. You just need to replace each of the letters with the characters. But you may also need to replace all the obsolete string.XXXX functions with mw.ustring.XXXX to get the characters handled properly, assuming they're Unicode. (for example, you need mw.ustring.format to replace many of those string.format commands) See [1]. Beyond that, there could be some complications with displaying the text right-to-left versus left-to-right, but I have no idea what it's supposed to look like in typical Arabic usage. Wnt (talk) 06:38, 7 September 2013 (UTC)
- Actually, mw.ustring.format is identical to string.format. Most of the other mw.ustring library functions have been altered from the corresponding string library functions to use unicode structures, however. — Mr. Stradivarius ♪ talk ♪ 07:09, 7 September 2013 (UTC)
- The problem with doing that is it makes it harder for updates made on one site to be copied to the other. Anomie⚔ 12:04, 7 September 2013 (UTC)
- Well, so far as I understand the MediaWiki namespace remains off-limits to all but admins, so this is a feature I will never use, or even be able to play with enough to understand how it works. Can you point to an example of the use of mw.message that shows what advantage can be had from it beyond consulting mw.message.getDefaultLanguage and using that result in a switch in your own code? Wnt (talk) 17:17, 7 September 2013 (UTC)
- I don't think it's that complicated. You just need to replace each of the letters with the characters. But you may also need to replace all the obsolete string.XXXX functions with mw.ustring.XXXX to get the characters handled properly, assuming they're Unicode. (for example, you need mw.ustring.format to replace many of those string.format commands) See [1]. Beyond that, there could be some complications with displaying the text right-to-left versus left-to-right, but I have no idea what it's supposed to look like in typical Arabic usage. Wnt (talk) 06:38, 7 September 2013 (UTC)
help with wlm coordinates
![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
could somebody more knowledgabe than me help with migrating ghana monument row for wiki loves monuments to lua? somehow the coordinates template seems changed, and Ghana’s material cultural heritage displays an additional text besides the coordinates now linking to an indonesian google map page (at least in my browser). --ThurnerRupert (talk) 20:13, 24 August 2013 (UTC)
- Fixed; not a lua issue. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 21:44, 24 August 2013 (UTC)
- many thanks! what is the reason the "{{Coord|" does not show up in the included templates? --ThurnerRupert (talk) 10:31, 25 August 2013 (UTC)
- Sorry, I'm not sure what you mean. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 20:55, 25 August 2013 (UTC)
- if you press edit on the ghana monument row, should it not display that it includes the coord template? or am i reading the text wrong? --ThurnerRupert (talk) 01:54, 26 August 2013 (UTC)
- many thanks! what is the reason the "{{Coord|" does not show up in the included templates? --ThurnerRupert (talk) 10:31, 25 August 2013 (UTC)
help with wlm tables, migrate to lua
could somebody more knowledgabe than me help with migrating ghana monument row for wiki loves monuments to lua, or this does not make any sense? --ThurnerRupert (talk) 07:23, 25 August 2013 (UTC)
- That template only has one transclusion in an article - is it being used on another wiki somewhere? If not, it might just be easier to hard-code the wikitable instead of writing it in Lua. — Mr. Stradivarius ♪ talk ♪ 09:00, 25 August 2013 (UTC)
- could you give somehow comparable examples for what you are saying? i.e. one where it makes a lot of sense, and one to what you mean by "hardcode"? --ThurnerRupert (talk) 10:29, 25 August 2013 (UTC)
- What I mean is, if the template is only being used in one place, then there's no need to have a template at all. You can just add a table to the article instead. If you look at Special:WhatLinksHere/Template:Ghana Monument row, you can see that {{Ghana Monument row}} is only being used on {{Ghana Monument header}} and Ghana’s material cultural heritage. So I don't really think there's a need for a template at all - you could just add a table to the Ghana’s material cultural heritage article. That is, unless {{Ghana Monument row}} is also being used on another wiki as well as on the English Wikipedia. — Mr. Stradivarius ♪ talk ♪ 11:55, 25 August 2013 (UTC)
- The template is used multiple times on that article. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 20:55, 25 August 2013 (UTC)
- could you give somehow comparable examples for what you are saying? i.e. one where it makes a lot of sense, and one to what you mean by "hardcode"? --ThurnerRupert (talk) 10:29, 25 August 2013 (UTC)
- both templates are used multiple times, even though it's on the same page, so it does make sense to use templates. i do not see good reason to use lua - the template syntax seems to be adequate for what it is used here. however, there seem to be a mistake here (this is in Template:Ghana_Monument_row):
|- class="vcard {{#If:{{{image|}}}|with_image|without_image}}; text-align: center" | {{#if:{{{id|}}}|{{{id|}}}}}
- the first line seems to mix "class" and "style" attributes, and i think what is meant here is:
|- class="vcard {{#If:{{{image|}}}|with_image|without_image}}" style = "text-align: center"
- the second line is not a mistake, but it seems pretty odd. i think what is really meant is:
| {{{id|}}}
- the header template also seems to confuse its metaphors - in several places it says
class="width: 5%"
- i daresay it really means to use "style" and not "class" in those places. - peace - קיפודנחש (aka kipod) (talk) 02:14, 26 August 2013 (UTC)
- the header template also seems to confuse its metaphors - in several places it says
- thanks for the hints, updated. how would you write this template in lua? and why "coord" does not show up as included when one presses edit? --ThurnerRupert (talk) 04:48, 26 August 2013 (UTC)
- Q: how would you write this template in lua?
- A: i would not. as indicated above, for what this template does, i think wikicode is just fine. as to the "coord" question: i do not know the answer, and i did not fully understand the question, either. also, i am not sure this is the best place to ask....
- peace - קיפודנחש (aka kipod) (talk) 17:58, 26 August 2013 (UTC)
- Q: why "coord" does not show up as included when one presses edit?
- A: Because {{coord}} is only included when
|lat=
has a value, and there is no transclusion on the template page itself (the "default" rendering or the documentation) where this parameter is given a value. Anomie⚔ 10:20, 27 August 2013 (UTC)
- thanks for the hints, updated. how would you write this template in lua? and why "coord" does not show up as included when one presses edit? --ThurnerRupert (talk) 04:48, 26 August 2013 (UTC)
- Why the heck are there templates Template:Kenya Monument row, Template:Botswana Monument row, Template:Nepal Monument row... there's got to be a way to fix this. It's not even obvious why a nation parameter would be needed. Plus, the header should be implemented as part of the row template with a parameter |header=yes to keep things a little more object oriented, I think. Wnt (talk) 21:20, 9 September 2013 (UTC)
Performance testing?
I've written my first Lua module. It's a simple StringBuilder, kinda like in Java. I don't know if Wikipedia will actually have use for it, it's more like a test for myself to get into the Lua language (no prior Lua experience). Anyway, how would I best go about testing the performance of the module? It would be rather silly for it to be slower than normal concatenation, so I just want to check, lol. Also, I've defined some method aliases near the bottom. Is there a better way to do this? I was thinking, maybe a custom __index function might be better? - TiiJ7 (talk) 16:37, 11 September 2013 (UTC)
- You can check the Lua run time and memory usage in the html source code together with the template limit data - see Wikipedia:Template limits for instructions. You can create a page that runs your script, say, 100 times, and another one that does the same thing with regular concatenation 100 times, and see which one is faster. Maybe User:Dragons flight has some more specific advice, as I know he has done some similar testing before. Having said that, you shouldn't worry all that much about the performance of Lua modules unless you're doing something really inefficient, both because Lua is so much faster than wikicode templates and because of the reasons set out in WP:PERFORMANCE. — Mr. Stradivarius ♪ talk ♪ 04:00, 23 September 2013 (UTC)
- Also, I'm not aware of a better way to do the module aliases, and I'm not sure it would be worth making a custom __index function for. But maybe someone with more coding experience than me could comment on that (I only started in about April). — Mr. Stradivarius ♪ talk ♪ 04:12, 23 September 2013 (UTC)
In module space pages: lua code vs wikitext
In module space, there are code and doc pages. They accept different text/code for input. For example: Module:RailGauge (lua code) and Module:RailGauge/doc (wikicode). My question is: both clearly being in module space, then what is the switch? -DePiep (talk) 21:41, 22 September 2013 (UTC)
- I think it is that the page is a) a subpage, and b) the subpage name is "doc" in lower case. I just tried a few tests, and I couldn't find any wikitext pages in module space that didn't follow this rule. I'm not sure where the code that sets it is kept though. — Mr. Stradivarius ♪ talk ♪ 03:48, 23 September 2013 (UTC)
- Doc subpages in module space are defined at MediaWiki:Scribunto-doc-page-name. Wikitext is set on pages that follow the pattern of this MediaWiki message. --Vriullop (talk) 07:29, 23 September 2013 (UTC)
- Thanks. Can be a deeper subpage too: Module:RailGauge/data/doc. -DePiep (talk) 10:13, 23 September 2013 (UTC)
- Doc subpages in module space are defined at MediaWiki:Scribunto-doc-page-name. Wikitext is set on pages that follow the pattern of this MediaWiki message. --Vriullop (talk) 07:29, 23 September 2013 (UTC)
- new question: is there an option to prevent the top messagebox "This is .." from appearing? ~(e.g. Module:Convert/doc) -DePiep (talk) 09:35, 3 October 2013 (UTC)
- No option currently, but it would only require editing MediaWiki:Scribunto-doc-page-header to add one. The code in that page is transcluded at the top of every module documentation page. — Mr. Stradivarius ♪ talk ♪ 09:47, 3 October 2013 (UTC)
Pagename and three special characters
Hi, we have a lot of false positives in Category:Commons category with local link different than on Wikidata because of mw:Manual:PAGENAMEE_encoding#PAGENAME. This category is added by {{Commons category}}. Maybe someone can help implement parts of all of it in lua? Multichill (talk) 20:17, 25 September 2013 (UTC)
- i tried something (in Module:StringReplace), but it seems that when i return from the module something like
"
, as soon as the editor saves the page, this is converted back to the corresponding ascii. we could, of course, return"
instead, but i am not sure if this will actually serve the purpose. any idea? (plese note that i injected invisible direction chars into the codes above - this is for display reasons only, to prevent translating them to their appropriate ascii). peace - קיפודנחש (aka kipod) (talk) 18:22, 26 September 2013 (UTC)- It works for the purpose. I tried it in Template:Commons category/sandbox and it works fine in Category:Ben & Jerry's. --Vriullop (talk) 18:53, 26 September 2013 (UTC)
- so if i understand correctly, everyone is happy, right? peace - קיפודנחש (aka kipod) (talk) 21:21, 26 September 2013 (UTC)
- Some suggestions to make it perfect: add also replacing of underscore, trimming and ucfirst. --Vriullop (talk) 08:41, 27 September 2013 (UTC)
- can you be more explicit? could you please define exactly what are the desired manipulation? trimming can be handled by the template (and usually is), though it would be trivial to add it to the lua function also. however, i do not know what is the desired behavior wrt spaces/underscores and casing. peace - קיפודנחש (aka kipod) (talk) 14:59, 27 September 2013 (UTC)
- You are right, trimming is currently handled by the template. Underscores appear sometimes when copypasting the pagename from url to a parameter, like Category:Ben_&_Jerry's. MediaWiki converts them to spaces, but it fails when trying matches in a template. The same occurs with case of first letter, although it can be handled easily with template syntax. So, converting underscores to spaces with Lua would be helpful. Trimming and case is not any problem. --Vriullop (talk) 20:35, 27 September 2013 (UTC)
- so i added trimming and replacing underscore with space: "Hey jude don't make it bad". peace - קיפודנחש (aka kipod) (talk) 03:43, 28 September 2013 (UTC)
- Thanks for the help. Much appreciated. Works like a charm. Multichill (talk) 15:10, 12 October 2013 (UTC)
- so i added trimming and replacing underscore with space: "Hey jude don't make it bad". peace - קיפודנחש (aka kipod) (talk) 03:43, 28 September 2013 (UTC)
- You are right, trimming is currently handled by the template. Underscores appear sometimes when copypasting the pagename from url to a parameter, like Category:Ben_&_Jerry's. MediaWiki converts them to spaces, but it fails when trying matches in a template. The same occurs with case of first letter, although it can be handled easily with template syntax. So, converting underscores to spaces with Lua would be helpful. Trimming and case is not any problem. --Vriullop (talk) 20:35, 27 September 2013 (UTC)
- can you be more explicit? could you please define exactly what are the desired manipulation? trimming can be handled by the template (and usually is), though it would be trivial to add it to the lua function also. however, i do not know what is the desired behavior wrt spaces/underscores and casing. peace - קיפודנחש (aka kipod) (talk) 14:59, 27 September 2013 (UTC)
- Some suggestions to make it perfect: add also replacing of underscore, trimming and ucfirst. --Vriullop (talk) 08:41, 27 September 2013 (UTC)
- so if i understand correctly, everyone is happy, right? peace - קיפודנחש (aka kipod) (talk) 21:21, 26 September 2013 (UTC)
- It works for the purpose. I tried it in Template:Commons category/sandbox and it works fine in Category:Ben & Jerry's. --Vriullop (talk) 18:53, 26 September 2013 (UTC)
Compare two coordinates
Hi lua wizards, I want to compare two coordinates, see d:Wikidata:Coordinates tracking. Let's take Royal Palace of Amsterdam as an example. Here on Wikipedia it's:
- latitude = 52.373
- longitude = 4.891
- type = landmark
- latitude = 52.37306
- longitude = 4.89139
- precision = 0.0001
(I left out altitude and globe)
What I would like to have is a LUA library to compare these and figure out if these are the same point or not. Multichill (talk) 15:27, 12 October 2013 (UTC)
- Don't want to disturb the request, but I it reminds me of an old need: how about calculating the global distance between two points (think airports)? Bonus effect: if it's zero, they are the same spot! -DePiep (talk) 16:04, 12 October 2013 (UTC)
- The distance must be lower or equal to the given precision. Float numbers are difficult to compare with equality. Alternatively longitude and latitude can be compared separately. Paweł Ziemian (talk) 16:22, 12 October 2013 (UTC)
- It would be a two step approach:
- Calculate the distance between two points (see for example How do I calculate distance between two latitude-longitude points? on stackoverflow)
- Determining thresholds for each precision. That would just be a static list with maybe soft and hard thresholds
- Multichill (talk) 17:40, 12 October 2013 (UTC)
- clue: Haversine formula. peace - קיפודנחש (aka kipod) (talk) 17:57, 12 October 2013 (UTC)
- I had math in high school so that's not really the problem, but I didn't have lua there :-( Multichill (talk) 19:42, 12 October 2013 (UTC)
- the clue was meant to assist someone who *can* write lua code, and is interested in investing the time - working the formulas for great circle distance based on planetary coordinates is not always entirely trivial, even for someone with full high school education. peace - קיפודנחש (aka kipod) (talk) 21:37, 12 October 2013 (UTC)
- I had math in high school so that's not really the problem, but I didn't have lua there :-( Multichill (talk) 19:42, 12 October 2013 (UTC)
- clue: Haversine formula. peace - קיפודנחש (aka kipod) (talk) 17:57, 12 October 2013 (UTC)
- It would be a two step approach:
- The distance must be lower or equal to the given precision. Float numbers are difficult to compare with equality. Alternatively longitude and latitude can be compared separately. Paweł Ziemian (talk) 16:22, 12 October 2013 (UTC)
- There are some tests with wikidata in Polish wiki, where template for location map performs some very stupid comparisons on coordinates to detect whether the data in wikidata are the same or different than the passed to the template. The article is assigned to category depending on the result:
- pl:Kategoria:Wikidata P625: nowe - if there are data in the wikidata only
- pl:Kategoria:Wikidata P625: puste - if there ara no data in wikidata, but are passed to the template in the article
- pl:Kategoria:Wikidata P625: ok - if both data are the same (using the rough comparing method)
- pl:Kategoria:Wikidata P625: różne - the data in the article are different than the data in wikidata (using the rough metod)
- Although I do not recommend that solution for this case, analysing of the two last categories might be interesting. Paweł Ziemian (talk) 21:56, 12 October 2013 (UTC)
- Here's a simple haversine implementation: 0.027303410832868. — HELLKNOWZ ▎TALK 09:47, 13 October 2013 (UTC)
- Hellknowz, please take a look at this. module:Sandbox/Hellknowz/CoordDistance
- 0.027303410832868 (input from the example)
- 0.043872539685125 swapped lat and lon, so now lon1=52.373 (expected: same outcome)
- Also, simple calcuation (see below) suggests that the distance is ~43m, not 27 m. -DePiep (talk) 11:42, 13 October 2013 (UTC)
- I punched the numbers at [2] and it gave me the same results - ~27 m for example and ~44 m for swapped. Are you sure we can swap lat/lon like that? I don't know sphere maths that well and I copy-pasted the math code. — HELLKNOWZ ▎TALK 13:06, 13 October 2013 (UTC)
- I'm wrong, indeed lat and lon cannot be swapped like this. As קיפודנחש explained below. -DePiep (talk) 13:51, 13 October 2013 (UTC)
- I punched the numbers at [2] and it gave me the same results - ~27 m for example and ~44 m for swapped. Are you sure we can swap lat/lon like that? I don't know sphere maths that well and I copy-pasted the math code. — HELLKNOWZ ▎TALK 13:06, 13 October 2013 (UTC)
- For the original question: are they the same? we can turn to flat plane calculation. The delta is: 0.00006 deg and 0.00039 deg → 0.000394588 deg (pythagoras). With average earth radius being ~6367.4445 km, 1 deg = 111.13287 km (on the great circle). This way the delta is 0.000394588 × 111.13287 = 0.04380 km.
- First, the number differs too much with the haversine calculation by Hellknowz (0.0273 km). There must be an error. (The major delta is 0.00039 deg, so it should be ~43 m right?)
- Second, the original question must have a precision remark: "are they the same within a precision of x m?". This precision then needs to be reworked into flat plane calculation (arc versus chord). -DePiep (talk) 11:02, 13 October 2013 (UTC)
- i think your "back of the envelope" calculation is wrong: the longitude distance is 110Km/deg only on the equator - the closer you get to the poles, the closer the longitude lines get to each other. i believe that even for the "naive" (or "flat plane") calculation you want to multiply the longitude diff by cos(lat). (or, for the previous comment: no, you can't swap lat and long: the distance between lat lines is constant anywhere on the globe, while the distance between long lines changes with lat). peace - קיפודנחש (aka kipod) (talk) 13:36, 13 October 2013 (UTC)
- Headslap. You are right. The latitude circle through Amserdam (at 52 deg N) has a different radius, it is not a great circle. So E-W distances are not 111 km per deg. -DePiep (talk) 13:51, 13 October 2013 (UTC)
- i think your "back of the envelope" calculation is wrong: the longitude distance is 110Km/deg only on the equator - the closer you get to the poles, the closer the longitude lines get to each other. i believe that even for the "naive" (or "flat plane") calculation you want to multiply the longitude diff by cos(lat). (or, for the previous comment: no, you can't swap lat and long: the distance between lat lines is constant anywhere on the globe, while the distance between long lines changes with lat). peace - קיפודנחש (aka kipod) (talk) 13:36, 13 October 2013 (UTC)
- I have not found Wikidata to be worth pursuing, but as for the calculation, I did this by converting to xyz spatial coordinates and measuring the straight-line distance at Module:User:Wnt/Sandbox and came up with a figure of 27.33m. Wnt (talk) 06:25, 21 October 2013 (UTC)
Need help creating 2 dimensional for loop
Hello, I have started creating a Module for the Video game multiple console reviews template -- Module:Video game multiple platforms reviews, the example is running on the talk page. I have run into the problem with extracting the args to then sort and output the results into the table, have spent hours over days trying to fix this I have it working for the most part at http://codepad.org/plYhHtTd. I have created the overall code it just needs fine tuning from someone that knows how to code in lua. I have tried my best since I know more then a thing or two in PHP, however I do not know all of the syntax for lua. Cky2250 (talk) 18:03, 13 October 2013 (UTC)
- Lua's for loop expressions are evaluated once at the start. So "for q=1, k do" where "k=1" will always run once, because it doesn't matter what you do to k inside the loop.
local loopCount = 0;
local maximum = 3
for i=1, maximum do
loopCount = loopCount + 1
maximum = 5
end
return loopCount .. ", " .. maximum -- returns 3, 5
— HELLKNOWZ ▎TALK 19:04, 13 October 2013 (UTC)
- @Cky2250: If there is still a problem, please spell it out in terms of what you want to do and what fails. I don't want to examine both the module and the codepad page. Can we ignore the latter? If you say what the module fails to do, I might get a chance to edit it. Johnuniq (talk) 03:20, 14 October 2013 (UTC)
- Thanks both of you. I will have to start again on friday, I will try a while loop or something else to get the same results. I was just thinking it was done right since it works on codepad.Cky2250 (talk) 14:34, 14 October 2013 (UTC)
- Ok the code is all set and all works, it just needs a smarter system.Cky2250 (talk) 16:50, 19 October 2013 (UTC)
- Looking over this for the first time, I see that the module above was moved to Module:Video game multiple platforms reviews. The template Template:Video game multiple platforms reviews has been hollowed out (139k of template code deleted!) and now consists solely of a call to the reviewbox function of this module (with its parameters being accessed as frame:getParent arguments) and is presently in use in a number of articles. It is clear that the Template:intricate needs to be replaced with
some kind of message to indicate the use of Lua instead, which might need to be written up from scratch.Template:Lua (I couldn't resist the temptation to tamper with that, adding "type = style" to give it a yellow border like Template:Intricate, which seems conceptually related) Wnt (talk) 16:36, 21 October 2013 (UTC)
- Also, I see that the documentation still mentions a section with flags to "turn on platform", but you already are beginning to count up flags as you parse out the half args. I'm not sure what your final goal is there, but what I'd suggest is that you make it unnecessary to have any platform=true at all, but leave in the functionality to allow platform=true to work so people can create empty columns (e.g. to continue a table from a previous section) and also allow platform=false to override the display of a column (so if someone decides a particular platform isn't being covered much, they can cut out that column without having to take out the specific data about it, so that if more is added later someone can turn it back on again, rather than occasional tidbits being added and taken out in a futile cycle) Wnt (talk) 17:02, 21 October 2013 (UTC)
- The half args is so that it does not go through arg 1 find that it contains a pub e.g. IGN then arg 2 has IGN and it would print the same information as many times as the publishers are in the list I originally was trying to have a smarter system but it wasnt going well. It was going to be a 2/3 dimensional array
{{IGN, {XBOX, PS3, WII}}, {Edge, {PS3, WII}}}
- true/false is implemented for platforms being shown or not. I was also thinking about what you said with the code seeing if the system code is being used (e.g. IGN_XBOX, Edge_XBOX, etc.) and just printing out without checking for XBOX = trueCky2250 (talk) 18:25, 21 October 2013 (UTC)
Edit Notice - Script error: No such module
Hi. I'm trying to test WP:Editnotices on the ee-flow prototype, but I'm running into "Script error: No such module." when I edit this disambiguation page.
We've got Lua installed (Special:Version), and I've imported these Modules and these Template:Editnotice... items, but I'm not sure what else is needed? Please advise! Thanks. –Quiddity (talk) 21:59, 23 October 2013 (UTC)
- Usually the "no such module" error tells you which module is missing. Is there a module name included in the error message? — Mr. Stradivarius on tour ♪ talk ♪ 22:50, 23 October 2013 (UTC)
- It popped up a box that just said "Script error: No such module." however it seems to be fixed now, per below. –Quiddity (WMF) (talk) 23:01, 25 October 2013 (UTC)
- I'm having some trouble figuring out how you got to the error. I don't see any edit notice when I try to edit that page. Using Template:Editnotice pagename gets me Template:Editnotices/Pages/Max, which doesn't exist. Your edit to the page is listed in the history as no change [3]. Your edit history from just before you asked here contains various edits to other arcane editnotice pages [4] but those are all "current". Hmmm, maybe the page responsible was deleted, or the module has since been added to suppress the message? Can you confirm you're still seeing the error? Wnt (talk) 22:22, 25 October 2013 (UTC)
- Aha! The editnotice (Template:Disambig editintro) is now showing up correctly. I'm not sure what fixed it, possibly the devs just needed to bounce memcache, as that's fixed other things previously. Sorry for the confusion, and thanks for your time. :) –Quiddity (WMF) (talk) 23:01, 25 October 2013 (UTC)
![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
Getting actual wiki markup in module's parameters
I've tried unsuccessfully to retrieve the actual wiki markup from a template's parameter value. In essence, I want to do {{#invoke:MyModule|{{{1}}}}}
where {{{1}}}
is the parameter passed to the template. Unfortunately, MediaWiki internal parsing processes the input before I get the chance to see the original markup in the module. I've tried "cheating" by adding {{#tag:nowiki|{{{1}}}}}
around the input, but it is being processed before even that. Does anyone have any ideas if there is any way I could get the untouched markup? Is my only choice working with strip markers and expanded wikitext? — HELLKNOWZ ▎TALK 09:50, 4 October 2013 (UTC)
- Note that if there were a way to get the actual wikitext from a template parameter value, there's a good chance
{{#invoke:MyModule|{{{1}}}}}
would give you "{{{1}}}".{{#tag:nowiki|{{{1}}}}}
is likely seeing the same thing that your module is seeing from the similar #invoke. Anomie⚔ 11:15, 4 October 2013 (UTC) - You can't get the wikitext of the parameters unless you grab the wikitext of the whole page and parse that to find the #invoke code. And that means basically reimplementing the MediaWiki parser in Lua, which is Non-Trivial. What are you trying to accomplish by finding the parameter wikitext? There might be an easier way to do whatever it is you're trying to do. — Mr. Stradivarius ♪ talk ♪ 11:33, 4 October 2013 (UTC)
- I'm trying to parse input dates for Module:Sandbox/Hellknowz/Test (Module:Infobox date field metadata), User:Hellknowz/Sandbox6; see bottom of Module_talk:Sandbox/Hellknowz/Test/testcases. Many cases involve the original value having a reference, comments, flag icons, nowrap template, etc. I cannot reliably search just for the date string, but I can safely ignore certain cases. — HELLKNOWZ ▎TALK 12:25, 4 October 2013 (UTC)
- That's a hard problem, and it looks like you are most of the way there already. So I don't think there's really any answer I can give you other than this can't really be done. If you don't have the appetite to grab the whole page code and try parsing that (and personally, I wouldn't), then there isn't any other way to access the data. You could try filing a feature request in bugzilla, but I don't know how successful that would be. — Mr. Stradivarius ♪ talk ♪ 13:13, 4 October 2013 (UTC)
- Grabbing the whole page isn't hard, and processing it isn't hard (just search for your invoke string, ignore the rest). The use of resources is a bit out there but people do worse. The real issue is that whenever you process a page from itself, the result is spacey. You change parameter x to y and it prints out as x, then you edit it and you see y. My guess is that the problem is that your source page isn't saved until after the final page output is calculated, so you get the original page content whenever you're processing a page, not your edited version. That seems like a bug, except... if you saved it first, the preview wouldn't match the output, which would be worse. They'd have to set up a way for you to save a sandboxed version of the source each time you hit preview, get the output, then make that the permanent version at the same time as the output is stored. Until then, when you self-process a page, people will usually end up throwing things at you. Wnt (talk) 16:35, 30 October 2013 (UTC)
- Can I grab the page that called the template that invoked the module? In practice, articles don't invoke modules, templates do. I don't need the invoke call itself, it will just have
{{#invoke:MyModule|{{{1}}}}}
, like Anomie says. I'm also not quite sure what you mean by change paramater x to y, how can I change anything if the module is already being invoked? Surely, the page content is just a copy at the time it was invoked, just like all the parameter values? Even if I change anything, that's just an unprocessed text string, independent of any actual markup. — HELLKNOWZ ▎TALK 20:37, 30 October 2013 (UTC)- There isn't any way to detect the page that called the template, or any way to detect the template, as far as I know. You can only access it if you already know what page it is. — Mr. Stradivarius ♪ talk ♪ 22:01, 30 October 2013 (UTC)
- Can I grab the page that called the template that invoked the module? In practice, articles don't invoke modules, templates do. I don't need the invoke call itself, it will just have
- Grabbing the whole page isn't hard, and processing it isn't hard (just search for your invoke string, ignore the rest). The use of resources is a bit out there but people do worse. The real issue is that whenever you process a page from itself, the result is spacey. You change parameter x to y and it prints out as x, then you edit it and you see y. My guess is that the problem is that your source page isn't saved until after the final page output is calculated, so you get the original page content whenever you're processing a page, not your edited version. That seems like a bug, except... if you saved it first, the preview wouldn't match the output, which would be worse. They'd have to set up a way for you to save a sandboxed version of the source each time you hit preview, get the output, then make that the permanent version at the same time as the output is stored. Until then, when you self-process a page, people will usually end up throwing things at you. Wnt (talk) 16:35, 30 October 2013 (UTC)
- That's a hard problem, and it looks like you are most of the way there already. So I don't think there's really any answer I can give you other than this can't really be done. If you don't have the appetite to grab the whole page code and try parsing that (and personally, I wouldn't), then there isn't any other way to access the data. You could try filing a feature request in bugzilla, but I don't know how successful that would be. — Mr. Stradivarius ♪ talk ♪ 13:13, 4 October 2013 (UTC)
- I'm trying to parse input dates for Module:Sandbox/Hellknowz/Test (Module:Infobox date field metadata), User:Hellknowz/Sandbox6; see bottom of Module_talk:Sandbox/Hellknowz/Test/testcases. Many cases involve the original value having a reference, comments, flag icons, nowrap template, etc. I cannot reliably search just for the date string, but I can safely ignore certain cases. — HELLKNOWZ ▎TALK 12:25, 4 October 2013 (UTC)
Use tabs instead of four spaces?
I've started up a new discussion about this at Wikipedia talk:Lua style guide#CodeEditor switched to tabs. Please comment over there if you're interested. — Mr. Stradivarius ♪ talk ♪ 01:14, 29 October 2013 (UTC)
Randomize ArbCom election guides
It was suggested by Rschen7754 (talk · contribs) that we try to use LUA to create a randomized election guide template for the upcoming ArbCom elections. Last year we used {{ACE2012/Guides}} to randomly show election guides in the {{ACE2012}} template. Nominations for ArbCom will start on 10 November and guides will show up soon after. Does anybody want to try to tackle this in the next week? 64.40.54.186 (talk) 04:56, 2 November 2013 (UTC)
- I'll see if I can get something working tonight. — Mr. Stradivarius ♪ talk ♪ 12:06, 2 November 2013 (UTC)
- Guides are already around, and I've created {{ACE2013}} along with the sub templates for the guides for the time being. LUA code is beyond my level of expertise, if you can get it to work in a way that is easier to add guides, great, and feel free to G6 any of the redundant pages if you do. One possibility is to just pull all the guides listed in Category:Wikipedia Arbitration Committee Elections 2013 voter guides. One of the struggles with the template wikicode was having the guides shuffle order and not just rotating in the same order, so if you can get that with LUA it would be even better. Monty845 16:26, 2 November 2013 (UTC)
- I've now created Module:Arbcom election banner. It displays the guides in random order - see {{ACE2013}} for an example. I have run into a problem, though - the order doesn't change when you purge the page, only if you add a new guide. Does anyone know of a good way to fix this? If not, Monty845, feel free to revert to the old version while we work this out. — Mr. Stradivarius ♪ talk ♪ 18:18, 2 November 2013 (UTC)
- Actually, I've figured it out - It was just a matter of setting math.randomseed to {{NUMBEROFEDITS}}. It should all be working now (although the documentation will have to wait a while, I'm afraid). — Mr. Stradivarius ♪ talk ♪ 18:35, 2 November 2013 (UTC)
- Wow, that's great. Thank you very kindly, Strad. 64.40.54.185 (talk) 22:05, 2 November 2013 (UTC)
- Actually, I've figured it out - It was just a matter of setting math.randomseed to {{NUMBEROFEDITS}}. It should all be working now (although the documentation will have to wait a while, I'm afraid). — Mr. Stradivarius ♪ talk ♪ 18:35, 2 November 2013 (UTC)
- I've now created Module:Arbcom election banner. It displays the guides in random order - see {{ACE2013}} for an example. I have run into a problem, though - the order doesn't change when you purge the page, only if you add a new guide. Does anyone know of a good way to fix this? If not, Monty845, feel free to revert to the old version while we work this out. — Mr. Stradivarius ♪ talk ♪ 18:18, 2 November 2013 (UTC)
- Guides are already around, and I've created {{ACE2013}} along with the sub templates for the guides for the time being. LUA code is beyond my level of expertise, if you can get it to work in a way that is easier to add guides, great, and feel free to G6 any of the redundant pages if you do. One possibility is to just pull all the guides listed in Category:Wikipedia Arbitration Committee Elections 2013 voter guides. One of the struggles with the template wikicode was having the guides shuffle order and not just rotating in the same order, so if you can get that with LUA it would be even better. Monty845 16:26, 2 November 2013 (UTC)
Extracting description field optionally in a given language from the File description page
Featured picture is a common thing on most wikipedias. Maintaining this features requires lot of manual effort. If a file can be quoted with automated extraction of its Description field in its page, this can be simplied a lot, as identifying a picture for a given day/week will be sufficient as the caption is automatically filled. It also makes adding images to articles easier.
Previous discussion of this topic is available. --Arjunaraoc (talk) 06:23, 2 November 2013 (UTC)
- The description shall be translated to many local languages. This might be a good topic for Wikidata, as it provides label and description for item, which might be a reference to the image on commons. However to make it usable in that way T49930 have to be resolved first. Paweł Ziemian (talk) 22:59, 2 November 2013 (UTC)
Nil value for frame object from #invoke
Hello everyone. I'm getting a curious script error here - I'm calling a frame object in Module:User:Mr. Stradivarius/sandbox4 and getting the error "attempt to index local 'frame' (a nil value)". I say it is curious because I'm getting the error from #invoke, but it works fine in the debug console; and also because I am getting the frame object explicitly with local frame = mw.getCurrentFrame()
. Can anyone see what the problem is? — Mr. Stradivarius ♪ talk ♪ 16:39, 10 November 2013 (UTC)
- I don't know, but line 28 is executed before the "return p" at the end of the module, so I wonder if getCurrentFrame actually is nil at that point. Do you need to store your own fields in the title object? I'm wondering if instead you should just change _main to call getProtectionLevel rather than index title. Johnuniq (talk) 22:15, 10 November 2013 (UTC)
- You're right - it worked fine after I put everything in a function and called that function from p._main. Thanks. :) As for storing my own fields in the title object, the idea is that I'll probably be accessing these fields a lot as the module gets fleshed out. I thought that it would be better to run getProtectionLevel once and then store the results somewhere rather than running it many times over. I suppose that place doesn't have to be the title object, but it is quite convenient and it makes sense semantically. — Mr. Stradivarius ♪ talk ♪ 01:17, 11 November 2013 (UTC)
- I know nothing about {{pp-meta}}, but if you will usually need all those fields, then leave the code as is. However, if it's likely that only one of the protection fields would be needed, you could replace
obj
withlocal obj = { tobj = mw.title.getCurrentTitle() }
and thenreturn setmetatable(obj, xxx)
wherexxx
is quite a simple table with an__index
function to calculate the protection levels on demand. If you wanted to see that but haven't usedsetmetatable
I could hack your sandbox for a quick demo. Johnuniq (talk) 02:42, 11 November 2013 (UTC)- Good point, that. I think I may actually need them all, but it's early days yet - if it turns out that I don't, I'll follow your suggestion. And I've dealt with metatables before, so demos won't be necessary. :) — Mr. Stradivarius ♪ talk ♪ 03:01, 11 November 2013 (UTC)
- I know nothing about {{pp-meta}}, but if you will usually need all those fields, then leave the code as is. However, if it's likely that only one of the protection fields would be needed, you could replace
- You're right - it worked fine after I put everything in a function and called that function from p._main. Thanks. :) As for storing my own fields in the title object, the idea is that I'll probably be accessing these fields a lot as the module gets fleshed out. I thought that it would be better to run getProtectionLevel once and then store the results somewhere rather than running it many times over. I suppose that place doesn't have to be the title object, but it is quite convenient and it makes sense semantically. — Mr. Stradivarius ♪ talk ♪ 01:17, 11 November 2013 (UTC)
Access wikidata from sandbox
Hello, I'm working on a datalist (like infobox or facts-section) based on wikidata. Working in a sandbox I have to activate my module from a page elsewhere to have som data avilable (mw.wikibase.getEntity() only grants data on the page itself). I could use a subpage on my own profile, but that page doesn't exist in wikidata (and shouldn't). Or I could use a real page (as suggested in Run preview), but here the admins detects my test-invoke as irellevant to the public and revokes it. Do I really need to save my changes in the lua-sandbox each time and preview the effects on a real page? Poul G (talk) 19:45, 10 November 2013 (UTC)
- After a few nights sleep, the only alternative I've come up with is to 1) serialize the itemdata by running some Lua code from a preview of the items article; 2) copy the serialized data and 3) paste it into the test-mode-elements of the module. For wikidata we don't need to consider the more nifty things about serializing functions or arrays as keys. Poul G (talk) 20:20, 13 November 2013 (UTC)
An anachronism
![](http://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Gnome-utilities-terminal.svg/48px-Gnome-utilities-terminal.svg.png)
About template {{Lua}}, that is used in converted templates' documentation.
The computer screen image is quite not supporting the improvement it announces. It is a tube model 1983, it shows a DOS-prompt (on the lower line? Someone has put a book on the enter-key?), and it is monochrome. This was in a time when scripts were written in Hollywood for full-color and graphic images (how futuristic they were for what you are looking at right now). Could we find a more to the point image for our Lua script? Thanks. (note: Lua-wiki-colors are described here). -DePiep (talk) 11:54, 11 November 2013 (UTC)
- it's no more "anachronism" than using this
for "work in progress". peace - קיפודנחש (aka kipod) (talk) 14:20, 11 November 2013 (UTC)
- You propose to change that then. Otherstuffexists. -DePiep (talk) 16:35, 11 November 2013 (UTC)
- no, i just pointed out that sometimes icons and symbols develop "a life of their own". other things come to mind: e.g., several wikipedias, most notable dewiki, use the cross character (†) to denote death, even for people who are not Christians, such as Muslims, Buddhists, or Jews, for whom it may seem inappropriate. the cross symbol is used as a shortcut for "grave", just as a shovel is used as shortcut for "work", even though small fraction of humanity ever use a shovel as part of their work - it can be argued that shovels are used for hobby (mostly gardenning) more than they are used for real work. similarly, the old CRT with the Lua prompt ">" is used to denote a script - i do not see a problem with this. peace - קיפודנחש (aka kipod) (talk) 16:51, 11 November 2013 (UTC)
- The commandline screen is not iconic for WP, internet or scripting. WP is from 2001, internet is graphic since 1990's, and we can script since 2013. I doubt it ever was. We are not backend operators. I do can associate the shovel with work, it does not mean something else. When did the prompt ever became associated with a wiki website? For the rest: otherstuff exists is not an argument. -DePiep (talk) 17:54, 11 November 2013 (UTC)
- You propose to change that then. Otherstuffexists. -DePiep (talk) 16:35, 11 November 2013 (UTC)
- it's no more "anachronism" than using this
- If I click on the "Lua (command line)" application that is part of Lua for Windows, what I get is a window
> _
- But there's not enough room for the copyright notice, and it seems out of keeping with Wikipedia style . :) Wnt (talk) 14:42, 11 November 2013 (UTC)
- I didn't say it doesn't work. Anyone writing in Scribunto from a commandline? -DePiep (talk) 16:31, 11 November 2013 (UTC)
- i wouldn't say "writing in scribunto from the command line", but i did most of the development in some of the modules i created using the command-line lua. specifically, Module:Chart and Module:Chessboard (i did the earlier work on this one, under a different module name. current module is prolly more than 50% the fruit of other people's work). peace - קיפודנחש (aka kipod) (talk) 16:41, 11 November 2013 (UTC)
- Actually, making new templates I start working this way (the squares are essential). But I would not claim or suggest it is a representative image. -DePiep (talk) 00:56, 12 November 2013 (UTC)
- i wouldn't say "writing in scribunto from the command line", but i did most of the development in some of the modules i created using the command-line lua. specifically, Module:Chart and Module:Chessboard (i did the earlier work on this one, under a different module name. current module is prolly more than 50% the fruit of other people's work). peace - קיפודנחש (aka kipod) (talk) 16:41, 11 November 2013 (UTC)
- I didn't say it doesn't work. Anyone writing in Scribunto from a commandline? -DePiep (talk) 16:31, 11 November 2013 (UTC)
Module:Pagetype
I've created Module:Pagetype, a replacement for {{pagetype}}, and I am thinking of updating the template to the Lua version later on this week. The Lua version has some differences from the current template, so I would like to get others' comments before making the switch. Please let me know your thoughts over at Template talk:Pagetype#Module:Pagetype. — Mr. Stradivarius ♪ talk ♪ 14:11, 4 November 2013 (UTC)
- I haven't looked at this very closely and there are good odds I'm wrong, but it seems like the existing template uses a magic word NAMESPACE to get the namespace in a non-expensive way. The replacement module goes to Module:Namespace detect and seems to dig for the mw.title object pretty quickly (though I don't know how often "demospace" is true, or even what it is). Is there a risk that this is a more expensive replacement really, or that other templates call it so many times that they would break from the expensive function count? Wnt (talk) 04:16, 5 November 2013 (UTC)
- You're right, the new module will create a new mw.title object for each page being called. Module:Pagetype doesn't use the demospace parameter of Module:Namespace detect because pages in the same namespace can have different pagetypes depending on their redirect status. If the expensive function count is exceeded it won't create script errors, though - it will default to the text "page", or to args.other if it is set. — Mr. Stradivarius ♪ talk ♪ 04:49, 5 November 2013 (UTC)
- Barring redirects, the namespace of a page can be looked up in v1.15 using the NAMESPACE parser function: {{NAMESPACE:Module:Pagetype}} -> Module. Conceivably you could look up redirects from the Wikipedia:Database reports/Cross-namespace redirects, but that seems a cure worse than the disease. I can't see any indication Template:Pagetype looks up the type of a page on its own at all. Wnt (talk) 20:03, 5 November 2013 (UTC)
- You say "disease", but I'm not sure what the problem is. Is there really a page out there that uses {{pagetype}} for hundreds of different pages? In my experience it's usually for the same page, even if it is called multiple times. That would only count as one expensive parser function (and zero if it is for the current page). — Mr. Stradivarius ♪ talk ♪ 21:50, 5 November 2013 (UTC)
- Well, it claims to be transcluded on >5 million pages.[5] If someone writes up a tool to figure out if any of these uses it many times, they might prove it isn't, but otherwise, it seems safest to assume so. Wnt (talk) 00:05, 6 November 2013 (UTC)
- We could add a tracking category that checks whether the page has exceeded the expensive parser function count, or we could just keep an eye on Category:Pages with too many expensive parser function calls when we make the switch. Or we could add a tracking category to the template now to find out which pages use the
|page=
parameter, and then check all of those pages. I doubt it will be a problem on many (or any) pages, though, as I've never seen {{pagetype}} being used in this way. — Mr. Stradivarius ♪ talk ♪ 01:18, 6 November 2013 (UTC)- It's not a bad idea, and that category is useful. While looking it over, I noticed that one article Red Coat Trail exceeds the count. There are error messages on the navboxes at the end of the article (though oddly, it doesn't seem otherwise to harm them) because Module:Navbox goes for mw.title.new -- even though Template:Navbox, which it says it implements in Lua, doesn't have any expensive calls I could see. Now those are only one per navbox, I think, and I think that most of the expensive calls are buried somewhere in the jct code above, even though I didn't find it on the first try. Still... it does sort of illustrate that as more and more stuff gets Luad, either we're going to have to come up with better ways of accounting for every expensive call, or else relax the scheme, because every time someone does a project like this another few seem to creep in somehow, and sweating them out of the code is not going to be easy. Wnt (talk) 17:26, 8 November 2013 (UTC)
- Funnily enough, I was looking at the same page, and I had a look through the {{jct}} code to see where the problems were coming from. It turns out that the expensive parser function calls are coming from #ifexist calls to the shield image pages (although there might also be others that I didn't find). I'm guessing that these expensive function calls would disappear if {{jct}} was converted to Lua, as you could just store all the image names in a data module to be loaded with mw.loadData. There wouldn't be any need to check that the file existed, as if the filename appears in the data module you can be reasonably sure that it exists. (This is the current situation with Module:Portal, if you're interested.) So just converting to Lua doesn't necessarily mean adding expensive parser functions. Anyway, I think the thing to do is to make the switch and keep an eye on the expensive parser function category. If there are a load of new pages that appear there, we can revert, and if there are just a few, then we can try and fix them. Does that sound like a good plan? — Mr. Stradivarius ♪ talk ♪ 03:02, 9 November 2013 (UTC)
- Well, I'm not going to tell you you can't - you've been putting a lot of effort into this, and it's your call.
- By the way, is there a way to see the number of expensive functions called by a certain point in a template that is more straightforward than the roundabout way I've used at [6]? Wnt (talk) 04:38, 9 November 2013 (UTC)
- Funnily enough, I was looking at the same page, and I had a look through the {{jct}} code to see where the problems were coming from. It turns out that the expensive parser function calls are coming from #ifexist calls to the shield image pages (although there might also be others that I didn't find). I'm guessing that these expensive function calls would disappear if {{jct}} was converted to Lua, as you could just store all the image names in a data module to be loaded with mw.loadData. There wouldn't be any need to check that the file existed, as if the filename appears in the data module you can be reasonably sure that it exists. (This is the current situation with Module:Portal, if you're interested.) So just converting to Lua doesn't necessarily mean adding expensive parser functions. Anyway, I think the thing to do is to make the switch and keep an eye on the expensive parser function category. If there are a load of new pages that appear there, we can revert, and if there are just a few, then we can try and fix them. Does that sound like a good plan? — Mr. Stradivarius ♪ talk ♪ 03:02, 9 November 2013 (UTC)
- It's not a bad idea, and that category is useful. While looking it over, I noticed that one article Red Coat Trail exceeds the count. There are error messages on the navboxes at the end of the article (though oddly, it doesn't seem otherwise to harm them) because Module:Navbox goes for mw.title.new -- even though Template:Navbox, which it says it implements in Lua, doesn't have any expensive calls I could see. Now those are only one per navbox, I think, and I think that most of the expensive calls are buried somewhere in the jct code above, even though I didn't find it on the first try. Still... it does sort of illustrate that as more and more stuff gets Luad, either we're going to have to come up with better ways of accounting for every expensive call, or else relax the scheme, because every time someone does a project like this another few seem to creep in somehow, and sweating them out of the code is not going to be easy. Wnt (talk) 17:26, 8 November 2013 (UTC)
- We could add a tracking category that checks whether the page has exceeded the expensive parser function count, or we could just keep an eye on Category:Pages with too many expensive parser function calls when we make the switch. Or we could add a tracking category to the template now to find out which pages use the
Don't think so - I always just look at the comments in the html source, but that won't tell you the number at any given point. That's a nice idea of yours, by the way. You should make that a proper module somewhere. As for Module:Pagetype, I'll go and make the switch now. Here are the pages currently in Category:Pages with too many expensive parser function calls:
I'll check back in a little while to see if there are any new pages on the list. — Mr. Stradivarius ♪ talk ♪ 05:10, 9 November 2013 (UTC)
- Ok, I've made the switch. No extra pages in Category:Pages with too many expensive parser function calls as yet. (It has 34 pages in at the moment, if you want to make a quick check.) — Mr. Stradivarius ♪ talk ♪ 07:48, 9 November 2013 (UTC)
- Note that you no longer have to look in the html source on preview pages to get this information, it shows up at the bottom of the preview screen under "Parser profiling data". This also works with TemplateSandbox. Scribunto's timing and memory usage information information isn't there yet, but is (I hope) coming soon. Anomie⚔ 13:15, 9 November 2013 (UTC)
- As suggested above I've copied my sandbox script to Module:Preview expense. Wnt (talk) 18:19, 15 November 2013 (UTC)
Filling the RELC page using Lua
See this Wikipedia:Village_pump_(technical)#Help_needed_tracking_recent_changes_to_medical_content VPT topic. A bot used to fill a dedicated WP:MED subpage with links to MED-pages (as set on their talkpage). The bot is defunkt. Instead of setting up another bot, I guess this can be done through Lua.
- Step 1: Read all pages listed in Category:WikiProject Medicine articles and its subcats. (intermediate save is optional)
- Step 2: Turn each page into a wikilink.
- Step 3: Write result on dedicated WP:RELC page Wikipedia:WikiProject Medicine/Recent changes (currently misnamed).
- Step 4: done.
- Notes:
- - Possible options: split over pages, or exclude: per namespace, with/wout talkpage, add page formatting for a reader.
- - Dedicated page name preferred (for all projects).
- - AFAIK a module cannot be scheduled for automated start.
- - Would there be some bot-rules applicable?
- - Good to know: this module would take the bot action in-site. We'd become independent of a bothandler. -DePiep (talk) 08:57, 5 November 2013 (UTC)
- - Adding: outside of mainspace, pages can have subpages that are not categorised (many templates have, for example). There could be an option to include these irrespective of their project categorisation. -DePiep (talk) 10:45, 5 November 2013 (UTC)
- This can't be done purely in Lua, as Lua can't detect which pages are in a category. You would need to update the list of links either by bot or by hand, and doing it by hand is obviously not ideal. If we could get a bot to automatically update a data module to be used with mw.loadData, though, we could use Lua to implement all your cool suggested features. :) How many pages are we talking about, roughly? — Mr. Stradivarius on tour ♪ talk ♪ 14:21, 5 November 2013 (UTC)
- Working on a manual solution right now; more on this later. -DePiep (talk) 14:34, 5 November 2013 (UTC)
- 31,000 pages -- WOSlinker (talk) 15:09, 5 November 2013 (UTC)
- I had 28391. (AWB, drilling the category:MED articles by importance, 4 deep. Mainspace pages only). Never mind.
- One time manual solution now available , see WT:MED. Talks going for future updates at the WP:BOTREQ page. I am building templates around it (make it generic for all projects). Given that we must use a bot, I suggest we stop thinking about specific Lua code (that would make a stack of programs to be managed, right). The template stuff is not that tough, can do it old style. So I suggest closing this thread. Thanks for thinking. -DePiep (talk) 17:40, 5 November 2013 (UTC)
- 31,000 pages -- WOSlinker (talk) 15:09, 5 November 2013 (UTC)
- Working on a manual solution right now; more on this later. -DePiep (talk) 14:34, 5 November 2013 (UTC)
- This can't be done purely in Lua, as Lua can't detect which pages are in a category. You would need to update the list of links either by bot or by hand, and doing it by hand is obviously not ideal. If we could get a bot to automatically update a data module to be used with mw.loadData, though, we could use Lua to implement all your cool suggested features. :) How many pages are we talking about, roughly? — Mr. Stradivarius on tour ♪ talk ♪ 14:21, 5 November 2013 (UTC)
- I was just looking into this on my own. It is definitely possible to put {{REVISIONTIMESTAMP}} on a page (for example, in a template, flanked by includeonly tags) and to access it using frame:expandTemplate [7]. However, it is a serious pain in the ass that REVISIONTIMESTAMP:Some_page doesn't work. So far I have not managed to figure out a Lua function to work with it either, even without parameters. There are a LOT of variations there, though, and I may not have tested the right one at all. Can someone confirm if it's impossible? Even as it is -- we could tag all the relevant articles on the article page with a template that contains REVISIONTIMESTAMP, and read them all in, and sort it out using some delimiter that marks the template. It would just be really ugly coding. Wnt (talk) 20:10, 5 November 2013 (UTC)
{{REVISIONTIMESTAMP:Some_page}}
is T8092, which interestingly enough was just fixed a day or two ago. The change should be live here with 1.23wmf3, which is scheduled for deployment here on November 14. Anomie⚔ 02:03, 6 November 2013 (UTC)- Cool! What I propose (and will try to code then if I get the chance) is a simple Template:Linked revisions with a Lua innard, that takes a page name, date, and search template (usually a namespace) as parameters. It runs the full text of the named page through a simple filter that pulls out everything between a pair of double brackets, tries to interpret that as a page name, checks whether it fits the search template (i.e. does it match, say, "Talk:") if one is provided, looks up the REVISIONTIMESTAMP for it if so, and if that revisiontimestamp is after the date specified, appends the pagename, REVISIONUSER, and date last edited to the output if so. The result is that you can look at "all edits to any article linked from Bob Dole in the past two weeks, and who made them". (Admittedly, I suspect good and evil will benefit almost equally from this tool, but let's hope the angels edge forward by a nose) Wnt (talk) 05:31, 6 November 2013 (UTC)
- Err, Special:RecentChangesLinked/Bob Dole already does basically this, and won't run into the expensive parser function limit. Why do we need a replacement in Lua? Anomie⚔ 11:17, 6 November 2013 (UTC)
- Heh. A) because I forgot that feature existed, or at least, thought it was something I'd once seen on the toolserver, B) because the Lua feature can be programmed to process the output all sorts of different ways (and though I'm not sure, but I think the limit can be evaded by using the magic word for the lookups). For example, I think I should add an ending date, so that I can get a list of articles linked from a parent (say, Cassini probe) that haven't been touched in over a year. Wnt (talk) 15:30, 6 November 2013 (UTC)
- I don not exactly understand this, but some notes. 1. Over at template talk:RELC list I am cooperating with a bot programmer to make this working for all projects (generic), and even wider (like tracking multipage templates). The bot will list all project pages (through the project talkpage template). Templates make the special page available for the user. 3. And the Request template (similar task as the archivebot-template) can have multiple options (eg exclude/include certain pages). This is to inform you, and maybe prevent double works. -DePiep (talk) 16:57, 7 November 2013 (UTC)
- This should be complementary. The template will allow a module to sniff out the appropriate article list (like Wikipedia:WikiProject Medicine/List of pages/Articles). The Lua module should read in that list (just one mw.title access). Then I go fish - get the REVISIONTIMESTAMP for each link on that page. There's nothing in the Lua reference manual indicating that frame:expandTemplate() is expensive (though perchance it may be by the time I finish abusing it) so I picture just running a template containing the magic word and its parameter. (There's still a chance that there's some other function that will let me do the magic word directly without making it a template, and I won't know if anything really works until I see it happen) After that I can start adorning the module with features to screen down the output (another few ideas: screen out edits from a list of known patrollers; list only edits by IPs). Wnt (talk) 23:23, 7 November 2013 (UTC)
- OK, {{REVISIONTIMESTAMP:Lua}} is producing 20240812040924, which is a good sign... Wnt (talk) 20:25, 14 November 2013 (UTC)
- I've posted Module:Related changes as a start; I still need to write a way to read in a bunch of anonymous parameters and interpret them as filter options, track down where the expensive calls come in, etc., but it's already potentially useful. Wnt (talk) 07:31, 15 November 2013 (UTC)
- Don't know if there is an overlap, but over at Page reports a botmaster could be walking in this field too. -DePiep (talk) 10:01, 15 November 2013 (UTC)
- This should be complementary. The template will allow a module to sniff out the appropriate article list (like Wikipedia:WikiProject Medicine/List of pages/Articles). The Lua module should read in that list (just one mw.title access). Then I go fish - get the REVISIONTIMESTAMP for each link on that page. There's nothing in the Lua reference manual indicating that frame:expandTemplate() is expensive (though perchance it may be by the time I finish abusing it) so I picture just running a template containing the magic word and its parameter. (There's still a chance that there's some other function that will let me do the magic word directly without making it a template, and I won't know if anything really works until I see it happen) After that I can start adorning the module with features to screen down the output (another few ideas: screen out edits from a list of known patrollers; list only edits by IPs). Wnt (talk) 23:23, 7 November 2013 (UTC)
- I don not exactly understand this, but some notes. 1. Over at template talk:RELC list I am cooperating with a bot programmer to make this working for all projects (generic), and even wider (like tracking multipage templates). The bot will list all project pages (through the project talkpage template). Templates make the special page available for the user. 3. And the Request template (similar task as the archivebot-template) can have multiple options (eg exclude/include certain pages). This is to inform you, and maybe prevent double works. -DePiep (talk) 16:57, 7 November 2013 (UTC)
- Heh. A) because I forgot that feature existed, or at least, thought it was something I'd once seen on the toolserver, B) because the Lua feature can be programmed to process the output all sorts of different ways (and though I'm not sure, but I think the limit can be evaded by using the magic word for the lookups). For example, I think I should add an ending date, so that I can get a list of articles linked from a parent (say, Cassini probe) that haven't been touched in over a year. Wnt (talk) 15:30, 6 November 2013 (UTC)
- Err, Special:RecentChangesLinked/Bob Dole already does basically this, and won't run into the expensive parser function limit. Why do we need a replacement in Lua? Anomie⚔ 11:17, 6 November 2013 (UTC)
- Cool! What I propose (and will try to code then if I get the chance) is a simple Template:Linked revisions with a Lua innard, that takes a page name, date, and search template (usually a namespace) as parameters. It runs the full text of the named page through a simple filter that pulls out everything between a pair of double brackets, tries to interpret that as a page name, checks whether it fits the search template (i.e. does it match, say, "Talk:") if one is provided, looks up the REVISIONTIMESTAMP for it if so, and if that revisiontimestamp is after the date specified, appends the pagename, REVISIONUSER, and date last edited to the output if so. The result is that you can look at "all edits to any article linked from Bob Dole in the past two weeks, and who made them". (Admittedly, I suspect good and evil will benefit almost equally from this tool, but let's hope the angels edge forward by a nose) Wnt (talk) 05:31, 6 November 2013 (UTC)
- Unfortunately, it appears that every use of REVISIONUSER or REVISIONTIMESTAMP with a parameter is counted as an expensive call, so I think I should leave this one to the botmasters. It really isn't possible to patrol all the links from an article, let alone a project, with a limit of 500. Unless, that is, there's some way to connive at the function from Lua that avoids this whole infrastructure (I never have figured out all of those ways of calling parser functions from Lua, etc.) but I doubt it... Wnt (talk) 04:41, 17 November 2013 (UTC)
Request to Update
I have a question, I have made the edits to the Module:Authority control/sandbox to update it to get the NDL property on the wikidata page associated with wiki page, but for somereason it doesn't seem to work. Can someone take a look to see what is wrong? --Clarkcj12 (talk) 13:17, 17 November 2013 (UTC)
- The key here is to try to get testcases working. I started at Module:Authority control/sandbox/testcases - however, the only way I can think of to get the answers so that the test can be set to actually succeed would be to reverse engineer from the HMTL source. Substing the template module doesn't get the wikicode. (for my confusion, see the history of the talk page for that) Plus, I don't think I'm actually using the sandbox code. Apart from that, there's the specific situation: I have no idea what the NDL property is and what a successful call with it would look like (That is Clarkcj12's responsibility, I think). But in general we need a much clearer documentation of how to start up and use sandbox testing in the first place, if we want anyone but admins ever to touch protected templates. Wnt (talk) 20:28, 17 November 2013 (UTC)
- Wnt is correct that a set of proper testcases is needed. A quick look suggests the new code is fine, although the first step in editing a sandbox is to copy the existing main module (several things in the main module are not in the sandbox). What doesn't work? Bear in mind that people like me have only the vaguest idea about the topic—what wikitext posted where fails to produce the expected output, and what is the expected output? By the way,
pairs( conf )
is used twice, whereas it's likely thatipairs( conf )
is wanted (the latter will consistently iterate the table in the order it is defined as the table has only numbered elements). Johnuniq (talk) 01:26, 18 November 2013 (UTC)
@Wnt: Special:ExpandTemplates can be used to capture the output of {{Authority control}}. I have fiddled with a test program I wrote as an alternative. It is for testing Module:Convert and has some problems when applied more generally, but I've put a few tests at User:Johnuniq/sandbox4. The table on that page is very wide—if you sroll to the right you can see "Pass" next to each test. Johnuniq (talk) 03:50, 18 November 2013 (UTC)
I had another look and have fixed the problem, I think. The new code in Module:Authority control/sandbox had a typo (function ndlLInk
had an uppercase "I
"), so I fixed that. First, I copied Module:Authority control to the sandbox, then I'm afraid I severely munged it to do two things: fix the whitespace for the new system of using tabs for indents; and insert "local
" where desirable (which meant the functions then had to be re-ordered so they were defined in the correct order). Finally, I put the new NDL code into the sandbox. Here is a test (using the sandbox template which calls the sandbox module):
{{Authority control/sandbox|NDL=01013687}}
The next step would be test the code and decide if any other changes should be made. Then have the editors who maintain the template/module consider the changes. Johnuniq (talk) 05:22, 18 November 2013 (UTC)
- Well, I've updated the sandbox/testcases. It works... my, it's an ugly process though. Even using the module filed away under Module:Convert/tester, the user then needs to manually copy and paste a section because subst doesn't work, and make null edits each time so the error/out of date output is removed from page self processing. I wish we had a more user friendly way, because I think more than half the users coming here, we tell them, or ought to tell them, please, give us testcases! Wnt (talk) 07:57, 18 November 2013 (UTC)
- Agreed, it's ugly. A better way to generate tests would be very helpful. By the way, rather than null edits, add
?action=purge
to the URL to purge the page. That can be automated using {{purge}}, as shown in the first line of Module talk:Convert/sandbox/testcases. Johnuniq (talk) 08:45, 18 November 2013 (UTC)- Hmmm, it's been a while since I toyed with that. I remember early on experimenting and feeling like going a literal null edit was 'more effective' than purging somehow, but it's been so long I don't remember what circumstances that is in. Wnt (talk) 08:50, 18 November 2013 (UTC)
- Agreed, it's ugly. A better way to generate tests would be very helpful. By the way, rather than null edits, add
Lua replacement of cite doi and pmid templates to allow passing of parameters
- Task
Lua replacement of {{cite doi}} and {{cite pmid}} templates to allow passing of optional parameters to the underlying {{cite journal}} template.
- Context
Currently the {{cite doi}} and {{cite pmid}} templates are hard wired to produce only one type of citation format (see caution at the top of each templates documentation page). To allow flexibility in the rendering of the displayed citations so that they conform to WP:CITEVAR, it would be desirable to allow passing of optional parameter. For background, see this discussion.
- Parameters
- mandatory parameter: PMID or digital object identifier (doi)
- list of one or more optional parameters to be passed to the underlying {{cite journal}} template
- Testcase
{{Cite pmid|12122621|authorformat = vanc | author-separator=, | author-name-separator = }}
Based on:
- Ozturan, O.; Miman, M. C.; Yiğit, B.; Cokkeser, Y.; Kizilay, A.; Aktaş, D. (2002). "Approaches to twisted noses and results of treatment". Kulak burun bogaz ihtisas dergisi : KBB = Journal of ear, nose, and throat. 9 (1): 21–29. PMID 12122621.
{{cite journal}}
: Cite has empty unknown parameters:|author-name-separator=
,|author-separator=
,|authorformat=
, and|displayauthors=
(help)
Generates:
{{Cite journal | pmid = 12122621 | year = 2002 | last1 = Ozturan | first1 = O. | last2 = Miman | first2 = M. C. | last3 = Yiğit | first3 = B. | last4 = Cokkeser | first4 = Y. | last5 = Kizilay | first5 = A. | last6 = Aktaş | first6 = D. | title = Approaches to twisted noses and results of treatment | volume = 9 | issue = 1 | pages = 21–29 | journal = Kulak burun bogaz ihtisas dergisi : KBB = Journal of ear, nose, and throat | authorformat = vanc | author-separator=, | author-name-separator = }}
which renders as:
- Ozturan, O.; Miman, M. C.; Yiğit, B.; Cokkeser, Y.; Kizilay, A.; Aktaş, D. (2002). "Approaches to twisted noses and results of treatment". Kulak burun bogaz ihtisas dergisi : KBB = Journal of ear, nose, and throat. 9 (1): 21–29. PMID 12122621.
{{cite journal}}
: Unknown parameter|author-name-separator=
ignored (help); Unknown parameter|author-separator=
ignored (help); Unknown parameter|authorformat=
ignored (help)
- Kommentar
If something similar has been done before, I would appreciate a link. With a good example, I may be able to code this myself. Thanks. Boghog (talk) 15:51, 23 November 2013 (UTC)
Looking for Lua mentors and tasks for Google Code-in
Hi, I'm one of the Wikimedia org admins at mw:Google Code-in. We are looking for Lua related tasks that can be completed by students e.g. rewrite a wikitext template in Lua or fix/extend current templates. We also need mentors for these tasks. You can start simple with one mentor proposing one task, or you can use this program to organize a taskforce of mentors with the objective of getting dozens of templates rewritten/fixed. You can check the current Wikimedia tasks here. The program started today, but there is still time to jump in. Give Google Code-in students a chance!--Qgil (talk) 01:13, 19 November 2013 (UTC)
- I think people should think carefully before getting involved in this or other "education" programs, because they stray from the Wikipedia ideal of universal knowledge. Specifically, the Google Code-In is only available to people from 13 to 17 who are enrolled in schools and submit their personal details to Google and sign the following agreement. We should be inspired to keep a better to-do list of coding tasks, and help people to do them, but those people should not be restricted to that portal. (Yes, I recognize that this education initiative is actually not as bad as other course-oriented programs that are only available to paying students at a particular college, but we should keep both at arm's length) Wnt (talk) 07:21, 19 November 2013 (UTC)
- By the way, if a 13-year-old can handle a task like this, including running the JavaScript unit tests, he's pretty fucking awesome. His next special assignment ought to be to come back to us and tell us how to do it. Wnt (talk) 07:37, 19 November 2013 (UTC)
- I will not try to convince you about the usefulness of these programs. :) Let me say though that we are not limiting participation to anybody. We do or best supporting any volunteers willing to work on technical tasks. We find these programs useful to reach out to new contributors, but we ask their participants to use our community channels just like anybody else: Bugzilla, Gerrit, etc. Some of those contributors stay around and become regular community members.
- On a more specific note, is there a list of wikitext modules waiting to be rewritten in Lua? Even if it's only one template, I would be willing to create a Google Code-in task for it and see what happens. Thank you for your help!--Qgil (talk) 20:56, 19 November 2013 (UTC)
- PS: That task you link to has been filed by Bartosz Dziewoński aka MatmaRex, who happens to be a former Google Code-in participants. Yes, 13-17 kids can be amazing. I'm old, but not as old as to forget what I was up to at that age. :) --Qgil (talk) 21:00, 19 November 2013 (UTC)
- I've started a project To-do list at Wikipedia:Lua/To do. There are only three templates listed there now, but there are a lot of templates that need converting. I'll try and expand the list some more later, but other editors should of course feel free to add to it as well. — Mr. Stradivarius ♪ talk ♪ 23:47, 19 November 2013 (UTC)
- Thank you Mr. Stradivarius! This is exactly what we need. Would you like to be the mentor of these tasks? I can help co-mentoring, but my Lua skills are very basic, and I'm not connected to the daily life of the Lua community here. I can also help creating a template for the tasks and applying it to the 5 tasks listed in the ToDo list. If you and anybody else is interested in becoming a GCI mentor, follow this link and mention this discussion in your request. Thank you! Since Monday, 9 tasks have been completed, and 10 are currently waiting for the review of a mentor. Let's get some new Lua templates in that list!--Qgil (talk) 16:31, 21 November 2013 (UTC)
- Yes Qgil, I'd be happy to mentor Lua-related stuff. Let me know what I need to do to get mentoring set up, and let's get started. :) — Mr. Stradivarius ♪ talk ♪ 22:02, 21 November 2013 (UTC)
- Mr. Stradivarius, please request the Wikimedia mentor role. You must be registered as a user first. More instructions for mentors can be found at mw:Google Code-in. PS: other Lua co-mentors are welcome as well. Just refer to this thread when requesting the mentor role.--Qgil (talk) 19:26, 22 November 2013 (UTC)
- Well, if the kids want to come here I and others will be happy to see if we can help, as for anyone else, no registration required. Wnt (talk) 03:18, 23 November 2013 (UTC)
- Sorry for the late reply, GCI is being intense. It would be good to have at least one mentor to bridge with the community here. I can take the risk of being the mentor myself as long as I can rely on you for quick revisions of the work submitted (within 24 hours, 36 max). What we are doing is create bug reports for GCIU tasks, CCing there community contributors with related skills, and we encourage the students to ask and report progress there, allowing anybody to help regardless of GCI involvement. We will requests students to create templates and modules under the Sandbox here. There you can watch the changes and help testing them. You really don't need any GCI registration to participate in any if these activities, but still I would appreciate one registered mentor in order to avoid the risk of me becoming the bottleneck. I still volunteer to create the tasks, which is probably the most boring part. :) Thank you for your understanding and your support. I hope it pays off, as it is paying off to other areas that are getting involved in GCI.--Qgil (talk) 02:19, 28 November 2013 (UTC)
- I have created two Google Code-in tasks to rewrite Template:Interval and Template:Countdown, based on the useful information provided at Wikipedia:Lua/To do. We are using Bugzilla reports to track progress on these tasks, and it would be great if you could CC yourselves to those reports to help the students with questions and reviews. Please consider creating new Bugzilla reports for tasks that could be taken by GCI students. Just CC me and I will create the GCI tasks. PS: Wnt, the GCI task you mentioned was completed with a Gerrit changeset that is now merged to MediaWiki core. Plus many more. I hope to get many Lua related task completed as well.--Qgil (talk) 00:50, 7 December 2013 (UTC)
- Module:Sandbox/Theopolisme (a module for Template:Interval) and Template:Interval/testcases are ready for review. It took just a bit more than 24h to have a first Lua related task completed by a GCI student! Please bring more.--Qgil (talk) 06:03, 8 December 2013 (UTC)
Module:Multiple image
There's a nice discussion about rewriting {{Multiple image}} template to Lua. It needs a good height solution and border parameter options. --Rezonansowy (talk • contribs) 19:06, 7 December 2013 (UTC)
- As was mentioned in the discussion, there is no mechanism for Lua to determine the image's height or aspect ratio at present, so a rewrite won't be able to help. isaacl (talk) 00:27, 8 December 2013 (UTC)
- Really? Is there any Lua programmer, who can confirm this or solve? --Rezonansowy (talk • contribs) 17:27, 8 December 2013 (UTC)
- Isaacl is correct that there isn't a way to get access to that data right now, but as pointed out in the discussion you linked, there has been work going on at bugzilla:41498 that might change that in the not-so-distant future. There was also another way around the issue that was pointed out, but I would prefer to see the outcome of the Bugzilla discussion before writing a module based on the workaround. We don't want to have to go to the effort of writing a module, only to have to rewrite it from scratch after we get a new feature. — Mr. Stradivarius ♪ talk ♪ 06:38, 10 December 2013 (UTC)
- Really? Is there any Lua programmer, who can confirm this or solve? --Rezonansowy (talk • contribs) 17:27, 8 December 2013 (UTC)
![](http://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/Saturn_eclipse.jpg/102px-Saturn_eclipse.jpg)
- I don't understand. According to Wikipedia:Extended image syntax you can set an image height directly using "xheightpx". Why are they talking about calculating according to the aspect ratio? Just set them all to be 100 px high or whatever. Wnt (talk) 08:16, 10 December 2013 (UTC)
- My understanding of the discussion is that the width of the enclosing box has to be set, but I haven't looked at the implementation. isaacl (talk) 09:10, 10 December 2013 (UTC)
- I don't understand. According to Wikipedia:Extended image syntax you can set an image height directly using "xheightpx". Why are they talking about calculating according to the aspect ratio? Just set them all to be 100 px high or whatever. Wnt (talk) 08:16, 10 December 2013 (UTC)
Announcing Module:Arguments
I have just finished writing Module:Arguments, a module that uses metatables to fetch arguments from the frame and parent frame objects. I made it because I was getting tired of copying and pasting the same argument-processing code into all of my modules, and also because I wanted a way to process arguments that didn't use the pairs
function by default. It can accept values from the frame and the parent frame at the same time, and there are quite a few configuration options. Test cases are at Module:Arguments/testcases (results). Have a look and see what you think, and let me know if you find any issues or want any new features. And of course, feel free to try it out on your own modules. :) — Mr. Stradivarius ♪ talk ♪ 06:48, 10 December 2013 (UTC)
- Thanks! I was going to suggest that after your work on Module:Redirect. Clearly it's good to have the code in one place and maximally updated.
- The key thing I don't understand is: why do you go straight for "if frame == mw.getCurrentFrame()"? You don't even use the getCurrentFrame for anything, and it's expensive to call. How do you end up having the module called with the "wrong" frame so that you don't want to use the arguments it provides?
- If there's a reason why you need to check the frame is the right one, I think you should handle the logic for type(frame) == 'table' [or nil?] first, and only go for the getCurrentFrame when you know you need to look at it. Wnt (talk) 08:05, 10 December 2013 (UTC)
- The reason I used mw.getCurrentFrame was to tell whether the module is being called from #invoke, or from the debug console or another Lua module. If we only check whether frame is a table, it would cause errors if frame is an argument table passed straight from Lua, as we might not have frame.args or frame.getParent. I suppose you're right, though - if we check that we have frame, frame.args, and frame.getParent, we can be reasonably sure that we are dealing with a frame object without using getCurrentFrame. On the other hand, if the function is being called from Lua, it will pretty much always be overkill to use Module:Arguments, so it is best to write modules that have a function specially for Lua (as recommended at Wikipedia:Lua style guide#Naming conventions). I'll put an alternative version in the sandbox, and wait to see what others have to say on the subject. — Mr. Stradivarius ♪ talk ♪ 08:52, 10 December 2013 (UTC)
- I've long disliked your use of
frame == mw.getCurrentFrame()
, as it makes it impossible to usemw.getCurrentFrame():newChild{}
to pass in an actual frame object for testing from the debug console. Anomie⚔ 16:46, 10 December 2013 (UTC)- Anomie, you should have said something! I'll never learn to fix my bad code if you don't tell me what's wrong with it. :) For my part, I simply copied the practice from the modules that were already present on Wikipedia - I think it might have been Toohool who came up with it first. But anyway, we now have a decision - mw.getCurrentFrame is out, and type checking is in. If you have any other implementation tips or things that you think could be improved, I'd love to hear them - this module will probably end up being used in a lot of other modules, after all. (I'm already thinking of using it in Module:Math, and Theopolisme has already used it in Module:Multiple issues.) — Mr. Stradivarius ♪ talk ♪ 21:48, 10 December 2013 (UTC)
- It never bothered me enough to track down who did it. But then you outed yourself ;) Anomie⚔ 22:18, 10 December 2013 (UTC)
- Code review:
- I'd raise an error if options isn't a table, instead of silently ignoring it. Same for frame. BTW, mw:Extension:Scribunto/Lua_reference_manual#libraryUtil.
- __newindex should also throw an error if it doesn't succeed, not silently fail.
- I wonder if you really need
mw.ustring.find( val, '%S' )
instead of string.find; in general, you're only going to see ASCII whitespace in blank arguments and string.find is going to be faster. For that matter,string.gsub( val, '^%s*(.-)%s*$', '%1' )
should be faster than mw.text.trim. - I'd like to see an explicit return value from tidyVal in all code paths.
- Memoizing nils from tidyVal could be useful. Stick
local nilArg = {}
at the top of the script and use that to indicate nil in metaArgs. Or just use false if you don't care about supporting false in luaArgs. - Instead of using argTables, I might just have options.frameOnly assign {} to pargs, options.parentOnly assign {} to fargs, and have options.parentFirst swap them (
fargs, pargs = pargs, fargs
). Then hard-code the search order in __index and mergeArgs. Although maybe that's going a bit overboard, the extra time for iterating over argTables is probably negligible. - On the topic of over-optimization, I might well choose one of four versions of tidyVal based on options, instead of checking the options on each call.
- HTH. Anomie⚔ 23:36, 10 December 2013 (UTC)
- Thanks for the tips! I've implemented all of them apart from the one about eliminating argTables. I did try it, but the only way to do it without introducing extra functions or if statements is to repeat the exact same code three times. And that applies to both the both __index and mergeArgs functions. It just looks too ugly to me, and reminds me of coding templates again. :) Also, I think LuaJIT might do some loop unrolling anyway? — Mr. Stradivarius ♪ talk ♪ 13:18, 11 December 2013 (UTC)
- I don't know if LuaJIT unrolls loops, but I do know that Scribunto doesn't use LuaJIT. It turns out that stock Lua is plenty fast for our needs. Anomie⚔ 13:53, 11 December 2013 (UTC)
- Ah, for some reason I thought it did. In that case, it looks like we have a choice between either fast code or sane-looking code. I have a slight preference for sane-looking code, but I'd like to hear what others think as well. — Mr. Stradivarius ♪ talk ♪ 14:38, 11 December 2013 (UTC)
- Unless there is a significant real-world performance problem, easier-to-maintain code is the way to go, for the sake of everyone who may have to understand the code in future (often including the code's author in six months :-). isaacl (talk) 16:25, 11 December 2013 (UTC)
- Quoting myself: "Although maybe that's going a bit overboard, the extra time for iterating over argTables is probably negligible." Go with the clear version here, IIRC I tested it and the difference was around 0.3 microseconds. Anomie⚔ 20:21, 11 December 2013 (UTC)
- Ah, for some reason I thought it did. In that case, it looks like we have a choice between either fast code or sane-looking code. I have a slight preference for sane-looking code, but I'd like to hear what others think as well. — Mr. Stradivarius ♪ talk ♪ 14:38, 11 December 2013 (UTC)
- I don't know if LuaJIT unrolls loops, but I do know that Scribunto doesn't use LuaJIT. It turns out that stock Lua is plenty fast for our needs. Anomie⚔ 13:53, 11 December 2013 (UTC)
- Thanks for the tips! I've implemented all of them apart from the one about eliminating argTables. I did try it, but the only way to do it without introducing extra functions or if statements is to repeat the exact same code three times. And that applies to both the both __index and mergeArgs functions. It just looks too ugly to me, and reminds me of coding templates again. :) Also, I think LuaJIT might do some loop unrolling anyway? — Mr. Stradivarius ♪ talk ♪ 13:18, 11 December 2013 (UTC)
- Anomie, you should have said something! I'll never learn to fix my bad code if you don't tell me what's wrong with it. :) For my part, I simply copied the practice from the modules that were already present on Wikipedia - I think it might have been Toohool who came up with it first. But anyway, we now have a decision - mw.getCurrentFrame is out, and type checking is in. If you have any other implementation tips or things that you think could be improved, I'd love to hear them - this module will probably end up being used in a lot of other modules, after all. (I'm already thinking of using it in Module:Math, and Theopolisme has already used it in Module:Multiple issues.) — Mr. Stradivarius ♪ talk ♪ 21:48, 10 December 2013 (UTC)
- I've long disliked your use of
- The reason I used mw.getCurrentFrame was to tell whether the module is being called from #invoke, or from the debug console or another Lua module. If we only check whether frame is a table, it would cause errors if frame is an argument table passed straight from Lua, as we might not have frame.args or frame.getParent. I suppose you're right, though - if we check that we have frame, frame.args, and frame.getParent, we can be reasonably sure that we are dealing with a frame object without using getCurrentFrame. On the other hand, if the function is being called from Lua, it will pretty much always be overkill to use Module:Arguments, so it is best to write modules that have a function specially for Lua (as recommended at Wikipedia:Lua style guide#Naming conventions). I'll put an alternative version in the sandbox, and wait to see what others have to say on the subject. — Mr. Stradivarius ♪ talk ♪ 08:52, 10 December 2013 (UTC)
GCD question
I'm working on Module:Math/sandbox at the moment, and I have a question about the greatest common divisor function. If you know about that kind of thing, I'd be grateful if you could comment over at Module talk:Math#Testcases. Thanks. :) — Mr. Stradivarius ♪ talk ♪ 03:43, 12 December 2013 (UTC)
math.random limited to 32-bit integers
So I've been working on a new feature at Module:Random to generate a random date. While doing so I've noticed that math.random seems to be limited to 32-bit integers. For example, these are the first few outputs for math.random(9999999999999999)
:
- 1874484855
- 1260195387
- 626812935
- 470599561
- 1048108424
- 456570891
- 628875670
- 1019583173
- 520927378
- 1472467616
- 656070341
- 485208199
- 1807948255
- 1610626572
- 283570239
I would expect higher numbers than that, and the cutoff point seems to be 2^32 / 2. And from poking around the Internet, this does seem to be a known issue.[8][9] Does anyone know any ways that this can be worked around, and should we file a bug about it? — Mr. Stradivarius ♪ talk ♪ 14:10, 25 November 2013 (UTC)
- A quick and dirty way is to just generate and concatenate individual random digits until hitting the given digit count. Then, wrap the number (take away the maximum/ceiling until it is below it) if it is larger than allowed. — HELLKNOWZ ▎TALK 14:58, 25 November 2013 (UTC)
- Hm, that will work well for positive integers, but I'm going to need negative integers as well. I essentially need to call
math.random(-someReallyBigNumber, otherReallyBigNumber)
. The long negative numbers occur when somebody wants to make a random date before about 1950 or so and it gets converted to a Unix timestamp. — Mr. Stradivarius ♪ talk ♪ 15:08, 25 November 2013 (UTC)- A very dirty way would be to calculate the relative difference of the floor/ceiling numbers (say, -300 to -100 is 3:1). Then choose which number (negative or positive) to generate based on that (75% vs 25%). (Only problem is if the ratio exceeds int32, so the random to choose which one would get botched up.)
- Another "simpler" way is to shift the floor to 0, generate the random number as before, then shift it back. — HELLKNOWZ ▎TALK 15:14, 25 November 2013 (UTC)
- Hm, that will work well for positive integers, but I'm going to need negative integers as well. I essentially need to call
- Also, if you multiply the random's result by how much larger the ceiling is than the random's int32 limitation, then add a random number up to random ceiling, it might work and give proper distribution (assuming you don't go above lua max int values, which is int64?). Say, for simplicity, max random allows is 1234, but you need up to 123456. It's 123456/1234~=100 time bigger. Multiply random roll by 100, then add 0..100 to it. So 536 * 100 + 78 = 53678. (This might have corner cases on the very highest roll...) — HELLKNOWZ ▎TALK 15:21, 25 November 2013 (UTC)
- The cutoff point is RAND_MAX, which on modern systems is typically 2^31-1. If you need numbers in a greater range, you could try something like this:
function myRandom( l, u )
local r = math.random() + math.random() / 2147483648
return math.floor( r * ( u - l + 1 ) ) + l
end
- Or if you don't want to assume RAND_MAX is 2^31-1, you could sum math.random( 0, N ) / ( N ^ x ) for x from 1 to ceiling( 53 / N ). If you're wanting a range (u - l + 1) larger than 2^53 with unit precision, you'll need more complicated math. The exponent of 53 comes from the fact that Lua uses 64-bit floating point internally, so it can represent all integers up to 2^53 but 2^53+1 == 2^53. HTH. Anomie⚔ 18:00, 25 November 2013 (UTC)
- Thank you Anomie, that worked magnificently. :) (You probably guessed that already from your barnstar though.) I have to admit, I didn't fully understand your example of "sum math.random( 0, N ) / ( N ^ x ) for x from 1 to ceiling( 53 / N )". What does N refer to in this instance? — Mr. Stradivarius ♪ talk ♪ 03:12, 28 November 2013 (UTC)
- It would help if I hadn't screwed up the formula. Should be "ceiling( 53 / log2(N) )". N is some number, ideally a power of 2 (so log2(N) is an integer). Anomie⚔ 03:20, 28 November 2013 (UTC)
- I'm not sure I understand why math.random()/2147483648 is being added to r; if I understand correctly, since math.random() is between 0 and 1, dividing it by 2147483648 is going to result in a negligibly small amount, and r is essentially just math.random().
- Mr. Stradivarius, note that with this approach, not every number within your specified range (if it spans a range greater than RAND_MAX) can be produced. As long as this is not an issue, then this method is fine. isaacl (talk) 05:41, 28 November 2013 (UTC)
- It would be nice to have all the numbers in the specified range available, but it's not of vital importance in the current implementation. It might become more important in the future depending on what people want to do with the module. I need to read up on the maths we're using here, because it's years since I studied this kind of thing and I fear that I have forgotten most of it. If anyone knows a good starting place, that would be helpful. :) Also, I coded up Anomie's algorithm in Module:User:Mr. Stradivarius/sandbox, but it seems to be returning numbers greater than 1 for small values of N. Is that just because I need to use big numbers, or is it another problem? Yours mathematically, — Mr. Stradivarius ♪ talk ♪ 07:48, 28 November 2013 (UTC)
- Not that I'm pushing my method, but if you only need up to int64 with all numbers included, then here's a simple(r) random as I mentioned above: Module:Sandbox/Hellknowz/Misc, giving stuff for max=21474836480000 like 1176639272617. — HELLKNOWZ ▎TALK 09:59, 28 November 2013 (UTC)
- @Isaacl: math.random() returns numbers between 0 and 1, but the number will always be a rational number i/2147483647 for some integer i. Lua can handle rational numbers in the range 0–1 with denominators up to 9007199254740992 (2^53). So math.random()/2147483648 isn't negligibly small. Although now that I look at it more carefully, that should be math.random()/2147483647 to be absolutely correct. Anomie⚔ 14:15, 28 November 2013 (UTC)
- @Mr. Stradivarius: Bah, I made another error. Use
math.random( 0, N - 1 )
, notmath.random( 0, N )
, since the range is inclusive when you specify arguments to math.random. Anomie⚔ 14:15, 28 November 2013 (UTC) - @Hellknowz: If you try out your method, I think you'll find that it never returns an odd number greater than 2^53, never a non-multiple of 4 over 2^54, and so on. Lua just can't represent those numbers exactly. Also, it blows up if you pass it a max greater than 4611686016279904512 (that's 2^62 - 2^31 + 2^8). Anomie⚔ 14:15, 28 November 2013 (UTC)
- To be honest that's more thought than I ever gave it this morning. I'm sure it breaks horribly somewhere before or at 2147483648*2147483648 because the ratio exceeds random's limit. I did mention this is only for up to around int64. It's not really meant to output anything so large, I'm just upping the lua's random by a power of 2 or whatever the limit and time variable size is before it goes all exponent-y. — HELLKNOWZ ▎TALK 14:43, 28 November 2013 (UTC)
However, it seems to me that an r between 0 and 1 is all that is needed, not an r that is the sum of one random value from 0 to 1 and another from 0 to 1/2147483648. By extending the distribution, the result can go beyond the desired upper limit (though just by a small fraction of the range; I said it was negligible not because Lua couldn't handle the precision, but because the frequency of seeing values above the desired limit would be relatively small).OK, I understand now: the first random number will never be 1, nor have a precision finer than 1/2147483648, so the second random number is filling in precision below 1/2147483648.- There is a bug, though, where the function could rarely give 1 due to rounding errors. So perhaps the best simple replacement function is
math.random( 0, 67108863 ) / 67108864 + math.random( 0, 134217727 ) / 9007199254740992
. Anomie⚔ 17:37, 28 November 2013 (UTC)
- There is a bug, though, where the function could rarely give 1 due to rounding errors. So perhaps the best simple replacement function is
- On another note for Mr. Stradivarius: not sure if a uniform distribution is required; adding two uniform distributions together results in a triangular distribution. isaacl (talk) 16:36, 28 November 2013 (UTC)
- I haven't quite worked through Anomie's second solution, so I'm not sure if the following proposal is the same: you can partition the desired range into sections < RAND_MAX, randomly choose a section, then randomly choose a number within that section. This will result in all values being possible with a uniform distribution. However, assuming each section is of size N, there will usually be one section left over at the end with a smaller size, and so the probability of choosing this section has to be weighted accordingly. If I get the chance, I'll try to create a demo. isaacl (talk) 16:43, 28 November 2013 (UTC)
- Your proposal appears to be equivalent. The general form of my (corrected) functions is , with and . Since the maximum value of the second term, , is less than the separation between values in the first term (), the first term is serving as your "partition the desired range into sections" and the second is serving as "choose a number within that section". Of course, this assumes that the "desired range" is expressable as [0,b1b2) for two integers b1 and b2. By taking the largest usable range (253 = 226227), dividing it down to [0,1), and multiplying it up to the desired range, the error in the distribution is probably going to be comparable to the error in the distribution of math.random() itself (which, here, is implemented as [10] and (probably) [11]). Anomie⚔ 17:37, 28 November 2013 (UTC)
- Not that I'm pushing my method, but if you only need up to int64 with all numbers included, then here's a simple(r) random as I mentioned above: Module:Sandbox/Hellknowz/Misc, giving stuff for max=21474836480000 like 1176639272617. — HELLKNOWZ ▎TALK 09:59, 28 November 2013 (UTC)
- It would be nice to have all the numbers in the specified range available, but it's not of vital importance in the current implementation. It might become more important in the future depending on what people want to do with the module. I need to read up on the maths we're using here, because it's years since I studied this kind of thing and I fear that I have forgotten most of it. If anyone knows a good starting place, that would be helpful. :) Also, I coded up Anomie's algorithm in Module:User:Mr. Stradivarius/sandbox, but it seems to be returning numbers greater than 1 for small values of N. Is that just because I need to use big numbers, or is it another problem? Yours mathematically, — Mr. Stradivarius ♪ talk ♪ 07:48, 28 November 2013 (UTC)
- Thank you Anomie, that worked magnificently. :) (You probably guessed that already from your barnstar though.) I have to admit, I didn't fully understand your example of "sum math.random( 0, N ) / ( N ^ x ) for x from 1 to ceiling( 53 / N )". What does N refer to in this instance? — Mr. Stradivarius ♪ talk ♪ 03:12, 28 November 2013 (UTC)
OK, here's my version: Module:Sandbox/isaacl/Probability (testcases) The algorithm is as follows:
- Let random() return a value in the range [0, 1), and random(N) return a value in the range [0, N).
- Given a range [0, M): divide it into T partitions, with T-1 partitions of size N, and the remaining partition covering the rest of the range. Thus T = ceiling(M/N).
- Partition 0 range: [0, N)
- Partition 1 range: [N, 2N)
- ...
- Partition (T-1) range: [(T-1)*N, M)
- Select a partition s = floor(random() * M / N)
- If s is in the range 0 to T-2: result = s*N + floor(random(N))
- If s is T-1: result = s*N + floor(random(M-(T-1)*N))
This approach results in a uniform distribution (assuming random() is uniform). isaacl (talk) 03:23, 29 November 2013 (UTC)
- I am not an expert of randomness. But I know that devising a good random generator is not easy. IMO, the reference source is Knuth's book The Art of Computer Programming, chap. 3, vol. 2, Random numbers. I believe that you could find there the answer to every question that you are looking for. D.Lazard (talk) 00:35, 18 December 2013 (UTC)
Language of native names
Many infobox templates have a |native_name_lang=
parameter, which is supposed to take an ISO 639-1 value such as "cs". As can be seen where I fixed this example, people sometimes enter instead text values, such as "Czech".
Could we have a module, please, to either i) throw an error message in such cases, and add a tracking category or ii) substitute the ISO value in the rendered HTML? If we go for the former, I'll then request a BOT to fix up existing instances. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 22:52, 6 December 2013 (UTC)
- @Pigsonthewing: I don't think substituting the ISO value is possible without creating a database of all known language codes and their various English names. (While finding a name from a language code is now easy thanks to the latest update to Scribunto's language library, I don't believe it is yet possible to find the language code from the name.) However, it is trivial to detect what is a valid language code and what isn't, so I chose to go with your option number one. Take a look at Template:Check ISO 639-1 and see if it does what you want. At the moment it is set to only accept language codes that are recognised by the MediaWiki software, but if that turns out to be too strict then we can relax that criterion without too much trouble. Let me know if it needs tweaking at all. — Mr. Stradivarius ♪ talk ♪ 06:32, 13 December 2013 (UTC)
- On the point of recognising language codes, it does recognise all of the codes listed in the ISO 639-1 language matrix -
see the test case results. — Mr. Stradivarius ♪ talk ♪ 09:53, 13 December 2013 (UTC)- I've removed that particular part from the test cases, as now the module just uses a local table, so you can see what codes are supported from the module page. — Mr. Stradivarius ♪ talk ♪ 15:47, 13 December 2013 (UTC)
- Note that Scribunto has been able to get the English name (or the name in many other languages) for a particular MediaWiki language code for a long time now using mw.language.fetchLanguageName. The recent addition allows for fetching the entire list of codes (and corresponding names). Anomie⚔ 14:04, 13 December 2013 (UTC)
- I'm obviously having a bad day... I'll need to investigate this further. Possibly the best thing would be to have a hybrid solution, where language names that are recognised are automatically converted to an ISO 639-1 language code. But that will have to wait for tomorrow. — Mr. Stradivarius ♪ talk ♪ 15:45, 13 December 2013 (UTC)
- I see that mw.language.fetchLanguageNames isn't deployed to the English Wikipedia yet, so we might have to wait a little while for a hybrid solution. It's working on test2wiki though, so I can start work on the coding at least - tomorrow. :) — Mr. Stradivarius ♪ talk ♪ 15:58, 13 December 2013 (UTC)
- Thank you for your efforts. Should I now hold off until you've done more? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 18:33, 13 December 2013 (UTC)
- That depends how much red error text you can put up with in articles. If you wait for the hybrid solution we should be able to convert most English language names to ISO 639-1 codes, but if you deploy now all of those will come up as errors. Also, I would appreciated someone double-checking the list of ISO 639-1 codes at Module:Check ISO 639-1 to see if I have missed any or made any mistakes. — Mr. Stradivarius ♪ talk ♪ 01:31, 14 December 2013 (UTC)
- The code is now working over at test2wiki:Module:Check ISO 639-1. All we need to do now is wait for mw.language.fetchLanguageNames to be made available on enwiki, and it should be ready to deploy. — Mr. Stradivarius ♪ talk ♪ 07:05, 14 December 2013 (UTC)
- Thank you again. There's no great rush; and I'm loathe to introduce red error messages unnecessarily. Do we have an ETA for mw.language.fetchLanguageNames? Is it weeks, months or years? Also, do we need (or have you already included) a tracking category? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 20:28, 14 December 2013 (UTC)
- Not sure about the schedule, but I suspect days or weeks rather than months, and definitely not years. And yes, I have included a tracking category: Category:Pages with invalid ISO 639-1 language codes. — Mr. Stradivarius ♪ talk ♪ 00:24, 15 December 2013 (UTC)
- The schedule is at mw:MediaWiki 1.23/Roadmap. Since the change was merged on Dec 10, it was included in 1.23wmf7 (which is why it's already on testwiki). Anomie⚔ 00:30, 15 December 2013 (UTC)
- Ok, so it should be on enwiki on Thursday 19th. Thanks Anomie. :) — Mr. Stradivarius ♪ talk ♪ 01:04, 15 December 2013 (UTC)
- The schedule is at mw:MediaWiki 1.23/Roadmap. Since the change was merged on Dec 10, it was included in 1.23wmf7 (which is why it's already on testwiki). Anomie⚔ 00:30, 15 December 2013 (UTC)
- Not sure about the schedule, but I suspect days or weeks rather than months, and definitely not years. And yes, I have included a tracking category: Category:Pages with invalid ISO 639-1 language codes. — Mr. Stradivarius ♪ talk ♪ 00:24, 15 December 2013 (UTC)
- Thank you again. There's no great rush; and I'm loathe to introduce red error messages unnecessarily. Do we have an ETA for mw.language.fetchLanguageNames? Is it weeks, months or years? Also, do we need (or have you already included) a tracking category? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 20:28, 14 December 2013 (UTC)
- The code is now working over at test2wiki:Module:Check ISO 639-1. All we need to do now is wait for mw.language.fetchLanguageNames to be made available on enwiki, and it should be ready to deploy. — Mr. Stradivarius ♪ talk ♪ 07:05, 14 December 2013 (UTC)
- That depends how much red error text you can put up with in articles. If you wait for the hybrid solution we should be able to convert most English language names to ISO 639-1 codes, but if you deploy now all of those will come up as errors. Also, I would appreciated someone double-checking the list of ISO 639-1 codes at Module:Check ISO 639-1 to see if I have missed any or made any mistakes. — Mr. Stradivarius ♪ talk ♪ 01:31, 14 December 2013 (UTC)
- I'm obviously having a bad day... I'll need to investigate this further. Possibly the best thing would be to have a hybrid solution, where language names that are recognised are automatically converted to an ISO 639-1 language code. But that will have to wait for tomorrow. — Mr. Stradivarius ♪ talk ♪ 15:45, 13 December 2013 (UTC)
- On the point of recognising language codes, it does recognise all of the codes listed in the ISO 639-1 language matrix -
@Pigsonthewing: {{Check ISO 639-1}} is now converting language names to ISO 639-1 codes, so feel free to roll it out to infoboxes. Merry Christmas. :) — Mr. Stradivarius ♪ talk ♪ 06:24, 25 December 2013 (UTC)
- And Merry Christmas to you, too. That looks great; thank you. It's now deployed in {{Infobox settlement}}. I wonder whether a template performing the reverse, (en -> English, de-> German) would also be useful? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 21:53, 26 December 2013 (UTC)
Announcing Module:TableTools
Hi everyone. Today I created Module:TableTools, which includes a few table-related functions that I noticed that I was writing over and over again. It includes functions for getting the union and intersection of n tables, functions for getting numbers of table keys, and functions for dealing with sparse arrays. Test cases are at Module:TableTools/testcases (run tests). Let me know if you can see any improvements that can be made or any new features you would like to be added. — Mr. Stradivarius ♪ talk ♪ 15:52, 15 December 2013 (UTC)
- Some comments:
- I wonder whether the general loop-over-args is better as you have it or as something like this:
function foo( ... )
for i = 1, select( '#', ... ) do
local t = select( i, ... )
-- Do stuff with t
end
end
- Why name the functions like "getUnion" rather than just "union"?
- Why do union and intersection sort?
- Also note that the sort is going to blow up if ret contains mixed types or incomparable types.
- getAffixNums should construct the pattern string outside the loop and store it in a local, instead of reconcatenating each time.
- Note your union and intersection functions will blow up if one of the arrays contains NaN ;)
- HTH Anomie⚔ 18:33, 15 December 2013 (UTC)
- Thank you as always for your very useful comments. :) I have put all of your suggestions to use. It is probably easiest to respond in order:
- I had forgotten about the select function, as I haven't actually used it in a module before. After reading the docs I was debating whether to handle nil values for union and intersect, but in the end I decided that it wasn't important.
- I have developed a habit of making all my function names verbs, but I agree that this isn't really necessary here.
- I actually put union and intersect in as a kind of afterthought. I added the sparse array functions first as I used those the most, and then thought that I should add union and intersection as they often appear in sets of table functions, and I had seen union used in Module:Infobox. So the table sort was also kind of an afterthought, but I can now see that it's not a good idea. People can always sort the tables later if they need to.
- Good catch. I had copied most of that function from a version I wrote before, and forgot to check for inefficiencies inside the loop.
- I've hacked union and intersect to not blow up on NaN. It uses a NaN proxy variable similar to the proxy variable for nils in Module:Arguments that you suggested above. Converting back to NaN is ugly, though - all the NaNs become 0/0. Basically I am assuming that it doesn't matter how a NaN is generated, only that it is a NaN, but I'm still a relative NaN noob so I might have this wrong.
- I'm thinking about also adding union and intersection functions for table key/value pairs. If anyone has a favourite template function that they would like to be included, then now is the time to ask - it will be easier to do it now than when the module is heavily transcluded. — Mr. Stradivarius ♪ talk ♪ 14:33, 16 December 2013 (UTC)
- Not sure if these are the type of utilities you had in mind, but a clone function and a display function would be useful (see Module:Sandbox/isaacl/ColourSpace/Tuple for sample implementations for the case where tables are being used as a 1-dimensional vector). isaacl (talk) 15:35, 16 December 2013 (UTC)
- We already have mw.clone and mw.logObject - are these the kind of thing that you were looking for? — Mr. Stradivarius ♪ talk ♪ 21:45, 16 December 2013 (UTC)
- For cloning, mw.clone should be fine; for display, I was looking for something more tailored for displaying vectors, with a configurable separator (as the function in my module does). isaacl (talk) 00:19, 17 December 2013 (UTC)
- Do you need something that will work over tables recursively? If not, table.concat and mw.text.listToText should do the job just fine. If we need something that works recursively with configurable separators then we can always try adapting the mw.logObject source code, but I'm not sure how much such a function would be used. — Mr. Stradivarius ♪ talk ♪ 01:50, 17 December 2013 (UTC)
- Module:Sandbox/isaacl/ColourSpace was designed to allow new colour format specifications to be defined in separate modules. The colour data is stored within a vector, so to avoid having each format re-implement a display function using table.concat, I made a common utility in Module:Sandbox/isaacl/ColourSpace/Tuple. Math-oriented applications could benefit from having a common display utility, but I agree that I don't know how much use this would get. isaacl (talk) 02:08, 17 December 2013 (UTC)
- Do you need something that will work over tables recursively? If not, table.concat and mw.text.listToText should do the job just fine. If we need something that works recursively with configurable separators then we can always try adapting the mw.logObject source code, but I'm not sure how much such a function would be used. — Mr. Stradivarius ♪ talk ♪ 01:50, 17 December 2013 (UTC)
- For cloning, mw.clone should be fine; for display, I was looking for something more tailored for displaying vectors, with a configurable separator (as the function in my module does). isaacl (talk) 00:19, 17 December 2013 (UTC)
- We already have mw.clone and mw.logObject - are these the kind of thing that you were looking for? — Mr. Stradivarius ♪ talk ♪ 21:45, 16 December 2013 (UTC)
- Not sure if these are the type of utilities you had in mind, but a clone function and a display function would be useful (see Module:Sandbox/isaacl/ColourSpace/Tuple for sample implementations for the case where tables are being used as a 1-dimensional vector). isaacl (talk) 15:35, 16 December 2013 (UTC)
- Thank you as always for your very useful comments. :) I have put all of your suggestions to use. It is probably easiest to respond in order:
- Don't know it is in your scope for this, but here are two.
- Could the module provide a 2D textual table, and by extension a 2D table in wiki/HTML table format? There is
table.concat
that producestable[i] .. sep .. table[i+1] .. sep .. table[j]
as a stream (string), and one separator in all.
- Usefulness? A bare 2D textual (like with
/n :
after each pair, or asepEndOfPair
option) I would surely use in development time, checking a status. A wikitable may be too simple for mainspace too (e.g., one wants headers & colheaders from day 1).- (Fixed layout: this was meant to be idea #1 for MR Strad). -DePiep (talk) 14:30, 24 December 2013 (UTC)
- Sorry, missed this one. In TableTools, I'd like to avoid anything that generates wikitext, as I see it as being limited to pure Lua table operations. Outputting a Lua table as a wikitable sounds like it might be useful, but it is probably best left for a different module. Maybe Module:Wikitable? As for outputting a Lua table to text, I have got by fine up to now with table.concat, mw.text.listToText, mw.logObject, and Module:User:Anomie/deepToString. I can't really think of any generalised application that isn't covered by those, but if there is one then maybe we could add it. (Maybe in a separate module?) — Mr. Stradivarius ♪ talk ♪ 14:41, 24 December 2013 (UTC)
- Thanx. Clear. -DePiep (talk) 16:58, 24 December 2013 (UTC)
- Sorry, missed this one. In TableTools, I'd like to avoid anything that generates wikitext, as I see it as being limited to pure Lua table operations. Outputting a Lua table as a wikitable sounds like it might be useful, but it is probably best left for a different module. Maybe Module:Wikitable? As for outputting a Lua table to text, I have got by fine up to now with table.concat, mw.text.listToText, mw.logObject, and Module:User:Anomie/deepToString. I can't really think of any generalised application that isn't covered by those, but if there is one then maybe we could add it. (Maybe in a separate module?) — Mr. Stradivarius ♪ talk ♪ 14:41, 24 December 2013 (UTC)
- (Fixed layout: this was meant to be idea #1 for MR Strad). -DePiep (talk) 14:30, 24 December 2013 (UTC)
- How does the TableTool work with deeper tables? (3D, table-in-table values, ...)? I have plans to become a novice in this (yes), so don't spend your time explaining to me before I do some homework ;-). Just to drop the idea. -DePiep (talk) 09:52, 20 December 2013 (UTC)
- At the moment, none of the functions in TableTools work with nested tables. It's intended to be for fairly simple, commonly used operations on tables that would be a pain to rewrite every time. Operations on nested tables often need to be customised to the application in question, so it would be hard to write something general enough. As for displaying nested tables for development purposes, that already exists: see mw.logObject. We also have Module:User:Anomie/deepToString if you ever want something that displays outside of the debug console. — Mr. Stradivarius ♪ talk ♪ 14:21, 24 December 2013 (UTC)
- Adding a third suggestion: provide a procedure from wikitable to Lua data page. This could circumvent needing an off-wiki (off-line) script to transform a wikitable into a Lua /data page. (Currently done for module:convert/data). It could work like this:
- 1. I have made a sound wikitable in my userspace. 2. I copy-paste that table code into a module subpage (that will look bad, posing as Lua code). 3. Proposed TableTools function wikitableToDatapage reads that datapage as input (a single long string?). It parses the text, and returns a correct Lua data page (Lua data table). 4. One invokes that function in say userspace, and the result page showing can be copied into the true module:x/data page.
- It could work, and imo serves a need. But it would make very few people proud & happy I guess.-DePiep (talk) 07:32, 24 December 2013 (UTC)
- That could be useful, yes. I think it would work best as a JavaScript tool rather than a Lua module, however. If it was in JavaScript you wouldn't have to worry about having to save the page to convert the text - you could do it right in the edit window. Also, you would be able to use it on pages other than module pages (maybe on documentation pages). With Lua it would only be possible to input the data directly on a module page, due having to escape pipes and equals signs etc. in MediaWiki template syntax. — Mr. Stradivarius ♪ talk ♪ 14:21, 24 December 2013 (UTC)
- Could the module provide a 2D textual table, and by extension a 2D table in wiki/HTML table format? There is
- I'd made some blundering efforts at Module:DisplayLuaTableContents, and again just now; the less said of these the better, but my general intent is: we should have some robust functions keys(table) -> list of all table keys, values(table) -> list of all table values, flat(table) -> some limited-depth digest of everything in the table that can be used to generate a tostring(table) -> showing "everything" in it. These are complicated by the possibility of having looped tables and complicated situations like a = {1, 2}; a[1] = a, etc. But I think that practically, as a debugging tool, from absolute beginner to whatever level of knowledge I have now, the age-old question of whatinhell is really IN that table seems to rank always at the top of the list. Wnt (talk) 22:44, 20 December 2013 (UTC)
- What you're describing here sounds an awful lot like mw.logObject - mw.logObject can't display just keys or just values, but it does a very good job of displaying all the content in a table. Have you tested mw.logObject out, and does it do what you want? — Mr. Stradivarius ♪ talk ♪ 14:21, 24 December 2013 (UTC)
- A good suggestion. I haven't explored the logging features as much as I ought. Wnt (talk) 18:08, 30 December 2013 (UTC)
Module:FindFeatures
I've knocked together Module:FindFeatures (and Module:FindFeatures/displayDatabase to produce the data files for it to use) to list adjacent features to those on various celestial bodies. A sample usage is at Addams (crater), which links to the sandbox version of a template (which links to the sandbox version of another) that calls it. Anyway, it wasn't inspired programming, and it would affect at least hundreds of articles when active, which I'm starting to think about doing, so I thought I should see if anyone is interested in looking it over. Thanks! Wnt (talk) 17:51, 30 December 2013 (UTC)
Calendar function(s)
Talk:List of Hindu festivals#2014 dates
Please see the above. -- 签名 sig at 09:51, 31 December 2013 (UTC)
- Category:Fixed holidays (on non-Gregorian calendars) includes most holidays and observances based on calendars other than the Gregorian. These could benefit from some sort of a calendar function. Some basic calendar stuff is currently done in Template:Infobox holiday/date. -- 签名 sig at 10:58, 1 January 2014 (UTC)
I must be overlooking something simple
I guess I am missing a very simple point here. About {{convert}}. {{hands/sandbox}} invokes module:convert/sandbox. When there are 3 unnamed parameter inputs, it produces a range output (from-to-to, ok). When there is only one input parameter (the number), unnamed parameter #2 should simply pass on "hands" (a length unit) in the invoke. But I can't get it working. Anyone?
See testcases. Edit {{hands/sandbox}} if you like. -DePiep (talk) 06:08, 29 December 2013 (UTC)
- @DePiep: I think the problem is that Module:Convert takes configuration parameters from the invoking template, and convert parameters from the values passed to the invoking template. Currently, {{hands/sandbox}} is using "#invoke" to directly call the sandbox module, and that means the numbered parameters that it defines are ignored. The fix would be to call the template {{Convert/sandbox}} rather than the module. Johnuniq (talk) 00:57, 30 December 2013 (UTC)
- Tanks, too busy IRL to explore this. -DePiep (talk) 11:18, 3 January 2014 (UTC)
- Still don't get it. I don´t see why the sandboxes should behave fundamentally different from the live pages (module and template).
- {{convert}} has no named params set by itself, and #invokes module:convert.
- {{convert/sandbox}} today has two named params set by itself, and #invokes module:convert-sandbox. It passed on parameters as expected (named and unnnamed params in the calling template). DePiep (talk) 14:38, 9 January 2014 (UTC)
- Is this issue a module:convert only thing, or standard module behaviour?
- Module:Convert is using this capability in a way that most other modules don't, but it is a feature available to all modules, yes. I've written an explanation of this issue at Module:Arguments#Frames and parent frames which might prove useful. It's mostly geared towards explaining how frames and parent frames are used in that particular module, but the general concept extends to other modules as well. Let me know if it helps. — Mr. Stradivarius ♪ talk ♪ 15:29, 9 January 2014 (UTC)
- Will have to study this. Mind that it should answer my question: how or why do #invokes of module:sandbox and module:convert/sandbox behave differently in this parameter handling (I can not simply replace them for invoking). -DePiep (talk) 15:42, 9 January 2014 (UTC)
- Module:Convert is using this capability in a way that most other modules don't, but it is a feature available to all modules, yes. I've written an explanation of this issue at Module:Arguments#Frames and parent frames which might prove useful. It's mostly geared towards explaining how frames and parent frames are used in that particular module, but the general concept extends to other modules as well. Let me know if it helps. — Mr. Stradivarius ♪ talk ♪ 15:29, 9 January 2014 (UTC)
- Tanks, too busy IRL to explore this. -DePiep (talk) 11:18, 3 January 2014 (UTC)
- @DePiep: Consider a hypothetical Module:M and Template:T. Suppose Template:T has {#invoke:M|main|warnings=2} and someone puts {T|text=hello} in an article.
- The main function in Module:M will be run, and that function has access to two completely different sets of arguments. The article provides the "parent" frame which has arguments "text=hello", while the template provides a frame with arguments "warnings=2".
- The module can do whatever it wants with each set of arguments. Convert uses the template arguments as configuration options that apply site-wide, while the article arguments provide the details for the particular conversion.
- Other modules may have no need for configuration options, and may merge arguments from both sources, then operate on the result. For example, if the module adds numbers, using {#invoke:M|main|11|22|33} might result in 66, and using {T|11|22|33} might do exactly the same. For that to occur, the module has to merge the frame's arguments and the parent frame's arguments (and decide what to do if different arguments are provided by each). Johnuniq (talk) 21:25, 9 January 2014 (UTC)
Debugging help
Can anyone work out what is causing the script error at Template:Orphan/sandbox? I get the following traceback:
Traceback
|
---|
Lua error in Module:HtmlBuilder at line 41: attempt to concatenate field 'val' (a nil value). Backtrace: Module:HtmlBuilder:41: ? (tail call): ? Module:HtmlBuilder:54: ? (tail call): ? Module:HtmlBuilder:25: ? [C]: in function "tostring" Module:Message_box/sandbox:539: ? (tail call): ? (tail call): ? mw.lua:558: ? [C]: in function "getExpandedArgument" mw.lua:264: ? Module:Unsubst:13: in function "chunk" mw.lua:558: ? |
I've worked out what causes that particular error in HtmlBuilder: it's when you pass a table to .cssText, as I have done in my module sandbox here. I've also worked out that args.style on line 207 of Module:Message box/sandbox is an empty table, when it should be nil. This makes me suspect that it is a nasty bug in Module:Arguments, as I used empty tables to memoize nil values in it. However, I can't seem to reproduce the issue. Can anyone see what I'm missing? — Mr. Stradivarius ♪ talk ♪ 19:48, 12 January 2014 (UTC)
- The bug is in Module:Arguments's __pairs and __ipairs: you can't just iterate over metaArgs, because it contains these table-for-nil entries. This should fix it. Anomie⚔ 21:00, 12 January 2014 (UTC)
- D'oh, I had a feeling it was something like that. Thanks for the fix. :) — Mr. Stradivarius ♪ talk ♪ 05:18, 13 January 2014 (UTC)
The ultimate rewrite target: Editnotice load
I was just reading WP:Editnotice and realized that on every single page we are running Template:Editnotice load and perhaps many of its bastard progeny.
Source markup
|
---|
{{#invoke:FormatTemplate|format|page=Template:Editnotice load}}
{{#invoke:FormatTemplate|format|page=Template:Editnotice load/core}}
{{#invoke:FormatTemplate|format|page=Template:ns has subpages}}
{{#invoke:FormatTemplate|format|page=Template:Groupnotice}}
{{#invoke:FormatTemplate|format|page=Template:Editnotice load}} |
I understand though that converting template to module doesn't guarantee speed improvement because there's an overhead, and there are many other technical considerations regarding parser functions/magic words/etc. Should we discuss, though, whether it is possible to shave some time off all our page loads this way? — Preceding unsigned comment added by Wnt (talk • contribs) 17:06, 19 January 2014 (UTC)
- Note that it's loaded on the edit pages themselves, not parses or page views. Anomie⚔ 17:30, 19 January 2014 (UTC)
- My understanding from WP:Editnotice is that editnotices can be loaded on page view, as on MediaWiki:Common.css, but are turned off by an explicit test "{{#ifeq: {{{notice action|}}} | view | ... | ...}}". Which means that the template itself is loaded on all page views, doesn't it? Wnt (talk) 17:51, 19 January 2014 (UTC)
- Interesting, I didn't know people did that. But no, it's not all page views, just ones that include MediaWiki:Clearyourcache (and there there's a test to only show it in the MediaWiki namespace), which is only CSS and JS pages. Anomie⚔ 18:43, 19 January 2014 (UTC)
- Thanks! That makes it less disturbing, though I suppose Wikid77 would care even if it's only for edits :) I'm afraid I said something to the contrary under this misunderstanding at WT:Drafts lately, where they're looking for a pagenotice for the entire Draft namespace. If you have any ideas to help them out (and correct my misinformation) I'm sure they'd be grateful. ;) Wnt (talk) 19:14, 19 January 2014 (UTC)
- I don't think there is any decent way to auto-add a banner to pages. Your best bet would probably be to get whoever set up the hack for allowing anon page creation in the draft namespace to add a hack that uses the BeforePageDisplay hook to prepend some message to all pages in that namespace. Anomie⚔ 20:21, 19 January 2014 (UTC)
- Thanks! That makes it less disturbing, though I suppose Wikid77 would care even if it's only for edits :) I'm afraid I said something to the contrary under this misunderstanding at WT:Drafts lately, where they're looking for a pagenotice for the entire Draft namespace. If you have any ideas to help them out (and correct my misinformation) I'm sure they'd be grateful. ;) Wnt (talk) 19:14, 19 January 2014 (UTC)
- Interesting, I didn't know people did that. But no, it's not all page views, just ones that include MediaWiki:Clearyourcache (and there there's a test to only show it in the MediaWiki namespace), which is only CSS and JS pages. Anomie⚔ 18:43, 19 January 2014 (UTC)
- My understanding from WP:Editnotice is that editnotices can be loaded on page view, as on MediaWiki:Common.css, but are turned off by an explicit test "{{#ifeq: {{{notice action|}}} | view | ... | ...}}". Which means that the template itself is loaded on all page views, doesn't it? Wnt (talk) 17:51, 19 January 2014 (UTC)
Template:Demography seems like a good candidate to Lua-ise; it currently relies on 1000+ #if statements to check for every year 1500–2100, which I think could be shortened and simplified easily with Lua. ~HueSatLum 22:54, 17 January 2014 (UTC)
- Now that's how we wrote template code in the good old days. ;) This template is such a good example of how needlessly complicated template code can get that I took a screenshot for posterity. I imagine we could make that many times smaller and many times faster with Lua. — Mr. Stradivarius ♪ talk ♪ 04:17, 18 January 2014 (UTC)
- I do not understand the purpose of the template as writing simple table is much easier than any template or Lua code for that task. Wouldn't be better to use bot that convert all places where the template is used to simple table? Lua is very useful if the number of arguments may vary, and there are some additional aggregated results provided from the template. See for example pl:Module:Demografia I wrote some time ago on Polish Wikipedia. Paweł Ziemian (talk) 15:28, 18 January 2014 (UTC)
- You might be right about that. But nevertheless, I've created an initial version at Module:Demography. It still needs to be made compatible with HTML 5, and it needs some documentation and test cases, but the basics are there. — Mr. Stradivarius ♪ talk ♪ 13:43, 19 January 2014 (UTC)
- Also, at the moment it is 3,401 bytes compared to Template:Demography's 44,350. And when I compared the speeds in my sandbox with 100 template invocations, the total page load time with Template:Demography was 34.903 seconds, while with Module:Demography it was 1.157 seconds. — Mr. Stradivarius ♪ talk ♪ 13:55, 19 January 2014 (UTC)
- Wow, much improved! Thank you! ~HueSatLum 15:54, 19 January 2014 (UTC)
- It's now HTML-5-ified and being used live in articles. — Mr. Stradivarius ♪ talk ♪ 03:36, 20 January 2014 (UTC)
- It looks good, but I'm disappointed - where's the HTML5? I see tr, td, th ... I'm still waiting on that inline SVG.
Also, looking at the result for Tirana it seems like some lines are missing ... there's no really obvious reason in the code popping out at me, and it's variable - I move it up and down and the bottom line appears and disappears while I scroll! I get separate cells for 1955 1985 and 2001 if I delete the 1703 cell. It's not somehow scaled so that they're less than a full pixel - looks like a 1px border - on inspection the cells seem slightly overlapping, but one of them should get a border... it's mysterious. Wnt (talk) 05:51, 20 January 2014 (UTC)doh, sorry, I had the browser zoomed out by a step! And apparently it doesn't handle it very predictably. Wnt (talk) 19:05, 20 January 2014 (UTC)- By "HTML-5-ified", I mean "doesn't fail HTML 5 validation". If you want to go crazy with inline SVGs, be my guest. :) — Mr. Stradivarius ♪ talk ♪ 21:42, 20 January 2014 (UTC)
- Well, the problem is: 1 <canvas> 2 <audio> 3 <video> ... 5 <embed> 6 <track> 7 <datalist> 8 <keygen> 9 <output> 10 <article> 11 <aside> 12 <bdi> 13 <command> 14 <details> 15 <dialog> 16 <summary> 17 <figure> 18 <figcaption> 19 <footer> 20 <header> 22 <meter> 23 <nav> 24 <progress> .. 29 <time> 30 <wbr> - that's 23/24 of the first 24 HTML5 elements that aren't recognized (list from [12]). Another is <syntaxhighlight lang=""> which is a wiki tag interpreted in a way that has nothing to do with its widely recognized use in HTML5. However, the last part of the list is looking a little more promising. The mark tag seems to work ... I haven't looked into how 25 works and I'm not sure if they are just being taken out or if they're being interpreted. Ditto in "time" tags. But xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxwbr:
xxxxxxxxxxxxxcontrol<control>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx breaks for me at the wbr, so that must be enabled. And definitely the 28 <section> tag can foul up a preview, it appears. Still, the vast majority are not available, though ... I haven't tried every which way to try to hack unauthorized HTML tags through Lua yet. 😈 Wnt (talk) 23:40, 20 January 2014 (UTC)
- Well, the problem is: 1 <canvas> 2 <audio> 3 <video> ... 5 <embed> 6 <track> 7 <datalist> 8 <keygen> 9 <output> 10 <article> 11 <aside> 12 <bdi> 13 <command> 14 <details> 15 <dialog> 16 <summary> 17 <figure> 18 <figcaption> 19 <footer> 20 <header> 22 <meter> 23 <nav> 24 <progress> .. 29 <time> 30 <wbr> - that's 23/24 of the first 24 HTML5 elements that aren't recognized (list from [12]). Another is <syntaxhighlight lang=""> which is a wiki tag interpreted in a way that has nothing to do with its widely recognized use in HTML5. However, the last part of the list is looking a little more promising. The mark tag seems to work ... I haven't looked into how 25 works and I'm not sure if they are just being taken out or if they're being interpreted. Ditto in "time" tags. But xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxwbr:
- By "HTML-5-ified", I mean "doesn't fail HTML 5 validation". If you want to go crazy with inline SVGs, be my guest. :) — Mr. Stradivarius ♪ talk ♪ 21:42, 20 January 2014 (UTC)
- It looks good, but I'm disappointed - where's the HTML5? I see tr, td, th ... I'm still waiting on that inline SVG.
- It's now HTML-5-ified and being used live in articles. — Mr. Stradivarius ♪ talk ♪ 03:36, 20 January 2014 (UTC)
- Wow, much improved! Thank you! ~HueSatLum 15:54, 19 January 2014 (UTC)
- Also, at the moment it is 3,401 bytes compared to Template:Demography's 44,350. And when I compared the speeds in my sandbox with 100 template invocations, the total page load time with Template:Demography was 34.903 seconds, while with Module:Demography it was 1.157 seconds. — Mr. Stradivarius ♪ talk ♪ 13:55, 19 January 2014 (UTC)
- You might be right about that. But nevertheless, I've created an initial version at Module:Demography. It still needs to be made compatible with HTML 5, and it needs some documentation and test cases, but the basics are there. — Mr. Stradivarius ♪ talk ♪ 13:43, 19 January 2014 (UTC)
- I do not understand the purpose of the template as writing simple table is much easier than any template or Lua code for that task. Wouldn't be better to use bot that convert all places where the template is used to simple table? Lua is very useful if the number of arguments may vary, and there are some additional aggregated results provided from the template. See for example pl:Module:Demografia I wrote some time ago on Polish Wikipedia. Paweł Ziemian (talk) 15:28, 18 January 2014 (UTC)
Redirect categorisation
It seems like most of the redirect category templates are able to be guessed quite easily with a high degree of reliability. I've done a quick example at User:John Vandenberg/Sandboxs using User:John Vandenberg/AutoCategoriseRedirect to add {{r from plural}}. It won't be perfect, but as most people (myself included) do not use 'R from *' templates religiously, automated redirect categorisation would be a net benefit - redirect categorisation errors are hidden from readers anyway. With Lua it should be quite efficient to do, and could easily be rolled out to the majority of our redirects. If it works well and is added to most redirects, it would then be easy to modify existing checks and add new checks to the routine to re-categorised redirects automatically as needs change. However, we have four million redirects..? I'm wondering how the the software will handle a module change that affects so many pages. I see Module:Infobox has 1.9 million odd uses. Does it handle updates sanely? Anyway, even if it needs to be subst'd, I think it become more common to categorise redirects if there was one template without params that automatically did most of the thinking - it could be copied from help pages, etc. John Vandenberg (chat) 15:09, 20 January 2014 (UTC)
- My first thought is that this would be a task better suited for a bot than for a module. With a module you would have to go through all four million redirects and add a new template to them, or appropriate the {{redr}} template, which might draw opposition. Redirects that have multiple 'R from *' template would need to be changed to use just one template, as from Lua we can't easily detect if there are other redirect templates on the page. Even if you did manage to convert {{redr}} to use this new scheme, there are still many redirects (a majority, I would guess) that don't have it, so you still have the problem of converting all of those ones to use a compatible template. That work would probably be done by bot, so why not just make the bot add the redirect categories directly? Some redirect categories can be easily worked out by a bot, such as {{R to project}}; others, such as {{R from alternative name}}, surely won't be possible. Your proposed {{R from plural}} automation could be difficult - there are bound to be some false positives, although I couldn't think of any when I tried. Pluralisation rules in English can be quite complex - just ponder the difference between maple leaves and Maple Leafs. :) Anyway, I suggest bringing this up at WP:BOTR and seeing what people say. — Mr. Stradivarius ♪ talk ♪ 05:43, 22 January 2014 (UTC)
Retrieving N latest category members
I could only find mw.title thingie and a Lua thingie to retrieve number of pages in a category. Is there a way to, either with existing Lua functionality or by expanding it, to retrieve fresh category members using Lua? I'm thinking of doing it by fetching data from api URLs even. (In my understanding, if such Lua module is invoked from a template, its content is not refreshed until a contributor clicks 'purge'; so, while expensive, such function would be called rarely.) --Gryllida 04:35, 22 January 2014 (UTC)
- No, it's not currently possible to retrieve any information about individual category members using Lua. This would have to be implemented as a new feature in Scribunto. Also, I don't think it's possible to directly get information about recent category members with the API, only total category members, although there are plenty of bots that monitor categories over time and deduce which pages are new. (Better get someone who knows the API better than me to confirm that.) As for updating categories that are transcluded from a template, purge won't do it - you need a null edit to the categorised page or the equivalent API call. — Mr. Stradivarius ♪ talk ♪ 05:23, 22 January 2014 (UTC)
- maybe not as such, but you can get "timestamp" property with the "categorymembers" API, where the timestamp mark when this page was added to the cat, so you can get "all", and filter the "fresh" yourself. would be more efficient to ask for "fresh" directly (btw: why?), but since you can get up to 500 members in a call, in most cases you'll get it with a single call, or small number of "continue"s. see [13]. peace - קיפודנחש (aka kipod) (talk) 06:22, 22 January 2014 (UTC)
- actually, looking at it more carefully, you can probably ask for "fresh" also, through "cmstart" parameter...[14]. peace - קיפודנחש (aka kipod) (talk) 06:24, 22 January 2014 (UTC)
- With Lua it seems that it is possible with mw:Extension:DynamicPageListEngine but it is not installed on Wikipedias. --Vriullop (talk) 10:49, 22 January 2014 (UTC)
- Socket in Lua module doesn't appear to work, with the usual generic error message. --Gryllida 23:34, 23 January 2014 (UTC) The API can do this, but can you help get URL contents using Lua?
- For reference, I'm including current version of the module and the invoke call here.
- Module:
- -- loads the HTTP module and any libraries it requires
- local http = require("socket.http")
- local p = {}
- function p.main(frame)
- r, e = http.request("http://wrong.host/")
- return e
- end
- return p
- Invoke:
- {{#invoke:Foo|main}}
- --Gryllida 23:54, 23 January 2014 (UTC)
- actually, looking at it more carefully, you can probably ask for "fresh" also, through "cmstart" parameter...[14]. peace - קיפודנחש (aka kipod) (talk) 06:24, 22 January 2014 (UTC)
- maybe not as such, but you can get "timestamp" property with the "categorymembers" API, where the timestamp mark when this page was added to the cat, so you can get "all", and filter the "fresh" yourself. would be more efficient to ask for "fresh" directly (btw: why?), but since you can get up to 500 members in a call, in most cases you'll get it with a single call, or small number of "continue"s. see [13]. peace - קיפודנחש (aka kipod) (talk) 06:22, 22 January 2014 (UTC)
- Gryllida: ttbomk, the lua "socket.http" module is not available on wikimedia wikis. if you maintain your own wiki (with scribunto installed), i would not recommend installing/enabling it (and i wouldn't be able to advise how to do such a thing), unless you have very strict control over who can create modules. peace - קיפודנחש (aka kipod) (talk) 00:48, 24 January 2014 (UTC)
- Gryllida 01:00, 24 January 2014 (UTC) Thanks. A safer workaround you could suggest?
- Gryllida: ttbomk, the lua "socket.http" module is not available on wikimedia wikis. if you maintain your own wiki (with scribunto installed), i would not recommend installing/enabling it (and i wouldn't be able to advise how to do such a thing), unless you have very strict control over who can create modules. peace - קיפודנחש (aka kipod) (talk) 00:48, 24 January 2014 (UTC)
- Access to MW API discussion, which links to a mailing list discussion; frame:preprocess (used in Module:Subpages) may be of interest, as well as Bug 60386, which I just filed. I expect it to be a formal step to record interest in such feature, with pending feedback from the relevant people. --Gryllida 00:59, 24 January 2014 (UTC)
Thanks all. This route appears to be unsafe in its current shape, with Lua modules being writable and invokable by quite all contributors, but gadgets — the existing way to talk to API visible to all contributors — being writable only by sysops (and user scripts being limited in scope to one contributor only). --Gryllida 02:02, 24 January 2014 (UTC)
Break 1: User rights
With Scribunto, can a separate namespace (or other measure) be applied to some Lua modules, so they...
- ... are editable by sysops (or other user rights group members) only, and...
- (Similar to how JS (it can query API or URLs) on page load for all users is though gadgets, which only sysops edit. --Gryllida 01:59, 24 January 2014 (UTC))
- ...have nice things such as access to sockets and/or API?
--Gryllida 01:54, 24 January 2014 (UTC)
- I think that we should be careful about moving in this direction. There are a whole lot of ways that trusted developers can introduce new features in any project. I think the noble goal of Scribunto is to put powerful scripting tools into the hands of users, so that a wide range of creative ideas are obtained, and a larger number of people pick up coding skills. The introduction of powerful libraries into Scribunto has helped make that happen, and I wouldn't want to see that good work slacken as people decide it's easier just to make the functions available with less caution to a smaller group. Wnt (talk) 06:08, 24 January 2014 (UTC)
- This is not going to fly. I'm hoping that mw.api will be developed to make more data available for modules, but it has to be done in a manner that is compatible with the purpose of the servers that render pages—that purpose is to provide encyclopedic content without undue delay or expense. Tools to do lengthy calculations with categories or to access data from a network need to be run on dedicated servers, such as WP:LABS. Johnuniq (talk) 06:33, 24 January 2014 (UTC)