This page uses content from Wikipedia and is licensed under CC BY-SA.

Wikipedia:Lua/Requests/Archive 5

Eclipse dates

Could a module be written to take a list of dates, link them, and indicate the next coming date? This would be useful for templates like Template:Lunar eclipses which need to be constantly updated by editors. Thanks — Martin (MSGJ · talk) 12:36, 25 March 2015 (UTC)

@MSGJ: Is there a formula that the dates can be calculated from? I assume there must be something, but I'm a complete beginner regarding such calcuations. — Mr. Stradivarius ♪ talk ♪ 14:50, 25 March 2015 (UTC)
I guess there is a formula somewhere, but I'm not asking for that. Just to put a marker (like ) next to the next occurrence. — Martin (MSGJ · talk) 14:54, 25 March 2015 (UTC)
The request is that a module be used to implement Template:Lunar eclipses. There would be a data page somewhere that contains the items to be displayed. The module would output exactly what the template does now, except that it would highlight, in each of two lists, the date that is the first after today + 1 (I would add 1 or even 2 or 3 so the highlight does not move until a couple of days have passed). The current template feeds a bunch of stuff into {{Navbox}}, and the module would do essentially the same. That would all be do-able but unless the functionality is needed in several other places as well, it looks a lot easier to me to just edit the template which needs five minutes of editing in the next two years, whereas the module would need a lot more than that! Johnuniq (talk) 01:01, 26 March 2015 (UTC)
Actually, we don't need to bother with the navbox part, or with making data modules for all the different templates. I've just finished making {{highlighted date list}}, which takes parameters like |item1= and |date1=, sorts them by date, adds a highlighter and outputs them as an unordered list. MSGJ: will that do the job? — Mr. Stradivarius ♪ talk ♪ 04:52, 26 March 2015 (UTC)
Amazing, well done! Johnuniq (talk) 05:39, 26 March 2015 (UTC)
Thank you very much! I've started using it already. — Martin (MSGJ · talk) 09:32, 26 March 2015 (UTC)

Module:Message box: sidebox option

See Template:Convert, especially the documentation as it shows.

It has a big "Translate this template into Swahili" messagebox in top. But the editors who visit this page are not translators. So I'd like to have this box miniaturized into a side-box (just like the {{Lua}} box already in there). Upstream, it has the Ombox and module:Message box. Where to set which switch? (at the moment, I'm not in to learning that; so just do it please. I'll see). -DePiep (talk) 21:47, 25 March 2015 (UTC)

@DePiep: With this edit you can now pass |small=yes to {{transwiki guide}} to output a small template. — Mr. Stradivarius ♪ talk ♪ 06:43, 26 March 2015 (UTC)
Yes. -DePiep (talk) 11:02, 26 March 2015 (UTC)

Visualization modules

Hi, can anyone give me a quick greatest-hits of visualization modules that have been built on-wiki here? I'm aware of Module:Chart for starters. ResMar 20:47, 28 March 2015 (UTC)

Template:Chess diagram is using Module:Chessboard (i think). i believe this falls under "visualization". as a side, i'll mention that for a long time i't trying to entice someone to create a lua wrapper that will make working with mw:Extension:EasyTimeline easier, but so far, no takers. if you find something in some other wikipedia that does it, i'll be grateful to hear. peace - קיפודנחש (aka kipod) (talk) 15:46, 30 March 2015 (UTC)
Tut. ResMar 13:25, 31 March 2015 (UTC)

Help debuging

I wrote a module that one of it's functions returns text formatted using a template. When invoking the function the template doesn't get expanded.

What am I doing wrong?

Thanks, אלישיב ליפא (talk) 08:44, 31 March 2015 (UTC)

A few links:

A link to the module: [he.wikisource.org]

An example is (currently) in the sandbox of he.wikisource

The idea of a module is to eliminate templates, so the quick answer is that you cannot return a template as the result of a module. A slightly longer answer would explain some details that I'm not familiar with concerning the fact that MediaWiki invokes modules at a point where it is too late for templates to be processed. I believe you can workaround the issue with expandTemplate, but what should be done is to redesign the module. Preferably, the module should emulate the template and return the wikitext that the template would return. Next option would be to redesign the template to invoke a module to help with the work that the template wants done. Johnuniq (talk) 09:15, 31 March 2015 (UTC)
(edit conflict) @אלישיב ליפא: Output from Lua modules isn't preprocessed automatically, as that might lead to some things being preprocessed twice. (The arguments are preprocessed automatically when you access them from inside Lua.) To expand templates, parser functions and extension tags, you need to preprocess them yourself using one of the methods of the frame object. In your case, the best one to use would be frame:expandTemplate. — Mr. Stradivarius ♪ talk ♪ 09:17, 31 March 2015 (UTC)

lua module breaks lines.

Hi. I'm using a Lua module to create some functionality, and the call to the module seems to break lines. I have no Idea why this is happening, and I hope someone can help me.

The module: [he.wikisource.org]

Example for a break: [he.wikisource.org]

אלישיב ליפא (talk) 20:18, 31 March 2015 (UTC)

Looking at the template source it looks like it may be the problem I was having here: Wikipedia talk:Lua/Archive 2#Odd problem with new template/module. Basically if you have a category at the end of a template it inserts a new line after it. Move the category anywhere else and it fixes it.--JohnBlackburnewordsdeeds 21:12, 31 March 2015 (UTC)

Move request (map)

I have a page User:Ahmetyal/sandbox/2 which I wan't to move from a template to a module, because I have reached the limit with locations. --Ahmetyal (talk) 09:28, 19 April 2015 (UTC)

@Ahmetyal: What would you like the name of the module to be? (By the way, this is actually a conversion request rather than a move request.) Jackmcbarn (talk) 02:02, 20 April 2015 (UTC)
Oh I see, sorry but I thought it was on this page. Lets call the page "Latest Turkish election results in South-Eastern Turkey". Which page is it you make a request then? --Ahmetyal (talk) 09:33, 20 April 2015 (UTC)
Just forget the last thing. Now I understand what you meant.. --Ahmetyal (talk) 11:28, 20 April 2015 (UTC)
Would it not just be easier just to create a graphic? The map is SVG so just add the points as SVG to a copy of it. The load on the server and on users machines would be much lighter and there are no limits. The SVG is easily edited and updated by you or other editors as information is added, and gives you more control over the presentation if you need it.--JohnBlackburnewordsdeeds 11:40, 20 April 2015 (UTC)
@JohnBlackburne: I'm not so strong on this field - can you give me an example of a graphic? I just need a map that can take lots of locations, because I've reached the limit with the Template:Location map. --Ahmetyal (talk) 12:30, 20 April 2015 (UTC)
I just had a look for a graphic but could not see something exactly like what you are trying to do, mostly as the maps out there are either plain (like the one you are using) or far richer in what they contain. I would just open it up in Inkscape and try placing dots. Once I had a few I'd open it in a text editor (you can use 'view source' on the graphic in a web browser to get at it) and try automating the process from data, such as the data you are using on your sandbox page. You can also ask for help with creating graphics, such as at the Graphics Lab.--JohnBlackburnewordsdeeds 12:47, 20 April 2015 (UTC)
I think the module-style is less complicated for me. I know how to work with it (I have contributed to the Module:Syrian Civil War detailed map and the Iraqi one). But thanks for the tip. --Ahmetyal (talk) 13:01, 20 April 2015 (UTC)
Looking at Module:Syrian Civil War detailed map I think an image is the wrong way to go if you are trying to do something similar: the high frequency of edits would be problematic with an image both because of the extra effort editing images and the lack of normal editing tools (history, diffs, the ability to easily revert) that a page has. Something to consider for a largely static data set maybe.--JohnBlackburnewordsdeeds 13:20, 20 April 2015 (UTC)
@Ahmetyal:  Done Jackmcbarn (talk) 19:37, 21 April 2015 (UTC)

Archive list

Is it possible to add another Archive title here (line 92)? So, By default (without adding any prefix) module will show Archive title 1 or Archive title 2 or both If archive title exist. I need this option for bengali wikipedia because on bn.wiki some user use their archive title as 'User:name/Songkolon 1' & some user use their archive title as 'User:name/Songrohoshala 1'. Here i tried to do this. Feel free to edit or make any changes here or here. Please help, Thanks --Aftabuzzaman (talk) 00:16, 26 April 2015 (UTC)

I have not studied this module or how it is used so my reply might not be accurate. I think the problem is that at bnwiki some users would like one name for "Archive", while other users would like another. My guess is that handling that automatically, or handling both if both are used, would require a lot of mucking around that would not be worthwhile. It would be much better to get people organized so one user has all their archive pages named in a consistent manner. You can change line 92 to replace "Archive" with the one most commonly used name. Users who want to use another name can simply add |prefix=whatever when invoking the module (that replaces "Archive" with "whatever"). They would probably want to also use |prefixspace=yes which adds a space to the end of "whatever". If wanted, prefixspace can be omitted, and prefix can be set like this: |prefix=whatever . Johnuniq (talk) 11:27, 5 May 2015 (UTC)
Thank you for reply. --Aftabuzzaman (talk) 12:08, 5 May 2015 (UTC)

Need a template to make and show list of pages in a category

Hi, I am from Bhojpuri wikipedia (bhwiki). I am designing our community portal and I need a template which can enlist and show all the pages in a category on the page where it is inserted. is it possible to get somthing like this?--Satyam Mishra --talk-- 18:58, 25 May 2015 (UTC)

There is an extension which provides some assistance, see Help:Category#Displaying category trees and page counts. In general, there might be over a million pages in a category, so listing them all would not be useful, and may not be possible in a module. Johnuniq (talk) 01:30, 26 May 2015 (UTC)
@Johnuniq: I don't need all. Just some of the pages, say, maximum 20 to 50 at once. And thanks for the link. I think "[en.wikipedia.org]" will do this task but I don't know how to insert the result of this query on a page. Please help. It will be very kind of you if you write this program to populate my sandbox by 20 articles from the category:Geography (sort if possible by date to show recent most). Thanks !--Satyam Mishra --talk-- 04:19, 26 May 2015 (UTC)
Sorry, generating a list of pages in a category is outside my area. A quick look at the documentation at mw:Extension:CategoryTree indicates that the following would list up to a certain number of articles in Category:Geography, but the list is not in alphabetical order, and uses italics for some reason unknown to me, and you can't set the number. I'm confident that doing something like determining the date of last edit or of creation would be difficult and time consuming. That's the sort of thing which is best done by a bot.
{{#categorytree:Geography|hideroot|mode=pages|namespaces=0}}
Bear in mind also that the list would not be dynamic—it would not necessarily change when articles in the category change. That is because everything displayed is cached, and the page would need a WP:PURGE to update.
I think the proper procedure would be to use a bot if someone to write and maintain one were available, or more likely, use categorytree to display a list which a user can expand by clicking (I think they need Javascript enabled for that). The help page I linked earlier should lead to an example of that. Johnuniq (talk) 04:54, 26 May 2015 (UTC)
@सत्यम् मिश्र: One of the DynamicPageList extensions will do what you want, but you will need to ask for it to be enabled on your wiki before you can use it. It isn't possible to display the members of a category using only the standard version of Scribunto enabled on Wikimedia wikis. — Mr. Stradivarius ♪ talk ♪ 07:33, 26 May 2015 (UTC)
@Johnuniq and Mr. Stradivarius: Thanks a lot to both of you! I think for the time being my task can be done by "categorytree" (I tested) and I will try to get this extension on my wiki too. Thanks again for your kind help!--Satyam Mishra --talk-- 08:30, 26 May 2015 (UTC)

Replacement for Template:Val

See Template talk:Val § Behaviour on substitution. – Wbm1058 (talk) 15:12, 2 June 2015 (UTC)

There is an module in alpha stage at Module:Val. If you are willing to test it, then it will replace the wikicode sooner rather than later.--Snaevar (talk) 14:51, 10 June 2015 (UTC)

Wrap new Graph tag

in one of the recent software updates, we received a new extension: mw:Extension:Graph. this can and should replace everythig we do, for instance, in Module:Chart: it can do barbraphs, pie charts, and so much more.

the problem with this extension is somewhat similar to the problem with mw:Extension:Timeline, which was the previous charting tool (it still exists, but is obsolete): it does not use syntax which is familiar and convenient to wikipedia editors.

now, some time ago i wrote Module:Chart, which plots pie charts and bar graphs. the implementation is disgusting, if i say so myself, because of the very limited support vanilla html provides for charting: the bars are generated by "div" elements with absolute positioning, and the pie chart is based on some obscure features of the way html renders borders (the exploitation itself is ingenious, IMO, and is taken from Template:Pie chart).

i kinda like the syntax used by Module:Chart - i think it lets the editors provide the meaningful data, and hides from them all the mundane details. i asked on this page, several times, for suggestions to make the syntax even better, but there was not much response.

the request here is simple: create a module that will receive parameters in the same syntax used by Module:Chart, but instead of using obscure and perverse methods to draw the graph, will use then new Graph tag.

as a second round, we should use this extension to support more chart types: line chart, scatter chart, horizontal bar graph, and if someone will gets really ambitious, maybe 3-d bar chart.

as a side, i'll mention that the graph extension can do more than just charts - this should be left as an exercise for other modules.

i believe the extension supports all the charts that can be found here: here, but i cant guarantee this is the case.

peace - קיפודנחש (aka kipod) (talk) 17:00, 8 May 2015 (UTC)

I saw your work and was totally amazed at the brilliant result and excellent usability, but I haven't needed to use the module. The new graph extension is a typical triumph over common sense requiring mumbo-jumbo for the input, and this demo advises that external tools should be used. The first step in your idea of a module to generate the graph wikitext would be to do a simple test of what happens if a module outputs one of the demos—would it render as a graph, or is module processing too late for that? Johnuniq (talk) 23:23, 8 May 2015 (UTC)
You'll probably need to use frame:extensionTag to get the graph to render. Anomie 23:29, 8 May 2015 (UTC)
yes, i assumed as much... peace - קיפודנחש (aka kipod) (talk) 23:00, 11 May 2015 (UTC)
This is the biggest front-end development since Lua implementation, in my humble opinion. But, indeed—working with the tags directly is impossible. I don't think that's a bad thing necessarily, though: by going as verbose as possible the visualization engine is as extensible as possible, and once everything is neatly standardized and parametrized via templates, it'll be quite beautiful, I think. ResMar 03:20, 16 May 2015 (UTC)

Hi קיפודנחש (aka kipod), Anomie, Resident Mario, have a look at this by Mps:

Pong ball in flight.svg Atlasowa: Can't tell you how happy I am to see this; we need to port it over immediately. @DerHexer: you know anyone that would be willing to translate the documentation? ResMar 14:58, 12 June 2015 (UTC)
See also. ResMar 14:59, 12 June 2015 (UTC)
I went ahead and imported two bits: Module:Graph and Template:GraphChart. ResMar 18:04, 12 June 2015 (UTC)
absolutely awesome. now, we just have to wait for "someone" to add "pie" capability (the graph extension has it, but the module does not support it [yet?] ), and we can retire Module:Chart entirely. this is much better and more appealing. peace - קיפודנחש (aka kipod) (talk) 15:41, 16 June 2015 (UTC)
This week I made a module on it.wiki to duplicate the functionality of {{Pie chart}} (currently it's in alpha testing here it:Modulo:Sandbox/moroboshi/Chart with a test page here it:Template:Pie chart/test. Parameter name are in a configuration file it:Modulo:Sandbox/moroboshi/Chart/Configurazione for easy localization, some code of the html tag must be changed (some difference between the {{Legend}} template and the italian equivalent) but it's a simple fix. If you are intereste I could import it on en.wiki--Moroboshi (talk) 16:20, 5 July 2015 (UTC)
We need an interwiki transclusion bot to handle these templates until the WMF finally wakes up and introduces it as a MediaWiki feature. ResMar 05:17, 12 July 2015 (UTC)

String parsing and concatenating

I want to write a new template that will be invoked as follows:

{{SBN | IT\ICCU\MIL\0205279}}

It should display in the article as follows:

SBN IT\ICCU\MIL\0205279

IT\ICCU\MIL\0205279 should be a clickable external link coded as follows:

[http://opac.sbn.it/bid/MIL0205279 {{{1}}}]

My problem...I don't know how to parse the template's parameter to get "MIL" and "0205279", how to concatenate "MIL" and "0205279" to produce "MIL0205279", and how to stick "MIL0205279" into the middle of the external link's definition. I'm guessing Lua.

If you would please help me this first time, citing relevant Wiki pages along the way, I'll be able to handle it myself in the future. Thanks. Knife-in-the-drawer (talk) 16:13, 28 June 2015 (UTC)

This can be done in either Lua or template syntax (using the string manipulation templates). Lua will probably be a little bit more work to implement, but would certainly be easier to read. For the record, what is "{{{1}}}" above, is that meant to be "IT\ICCU\MIL\0205279" in the example? Dragons flight (talk) 16:47, 28 June 2015 (UTC)
Yes. Knife-in-the-drawer (talk) 18:14, 28 June 2015 (UTC)
Ok, I went a bit over-the-top and wrote two different templates for this. :P The first is at Module:Sbn (and Template:Sbn) and the second is at Template:Sbn/sandbox. The sandbox is the wikitext version - this uses Module:String#match to parse the template parameter. The module uses string.match for the parsing. (They do the same thing - Module:String#match is just a wikitext interface for string.match.) These both use Lua patterns, which you will need to understand to see how this works. The module also uses string.format to join the strings together, but you could just as easily use .., Lua's concatenation operator. ('ab' .. 'cd' will give you the string "abcd".) The sandbox is simpler, but it isn't as elegant if something goes wrong - try putting a bad code into both of them to see what I mean. And please ask if you have any questions about the code. — Mr. Stradivarius ♪ talk ♪ 00:45, 29 June 2015 (UTC)
(module:SBN) Christian75 (talk) 15:08, 29 June 2015 (UTC)

An Infobox feature request is ready for Lua encoding

I've made a feature request for module:Infobox here: Infobox, header-when-not-empty. Basically, it adds a parameter |headern-cond= that only shows when its section contains data (consider how it has to be encoded today).

There is some good support, it's 'only' needs to be encoded in Lua. Anyone interested? -DePiep (talk) 18:51, 28 June 2015 (UTC)

Nothing wrong with doing that, but it's not that hard to code this in template syntax. Just test for whatever parameter that fills data under the header is essential to that little section being there. Or test for all of the parameters in that section if they're all of equal weight, and the section and its heading need to be there for any of them but be absent if they're all empty. Template:Infobox cat breed takes the latter approach, and hides the breed standards section for landraces or traditional breeds with no published standards. I agree it's more efficient in Lua, though.  — SMcCandlish ¢ ≽ʌⱷ҅ʌ≼  14:45, 18 July 2015 (UTC)

String parsing: Extract number (with decimal, neg) from arbitrary text

I'm taking first baby steps in Lua. What I want to do I could do in minutes in perl with regular expressions, but even the online Lua help materials aren't much help, because Scribunto's requirements for how it does thing are so rigid. I've barely gotten it to return (sometimes) a valid result for the first part of this I'm testing (just numerals, and without need to <nowiki>...</nowiki> the input). I haven't figure out how to use boolean operators with Lua string manipulation, as in "look for this OR that".

All I really need right now is a tiny one-function module that can be invoked directly to do the following to one string of input:
  • Drop all characters other than -, . and numerals.

My immediate need for this is converting sloppy CSS-related input like -10px, 2.2em; or even style="font-size: 70% ;" to -10, 2.2, or 70, respectively, and return that number. My assumption is that I should be able to wrap the input in <nowiki>...</nowiki>, in case someone inputs something daft like |style=font-size: 70%, with a | symbol, but that's not essential. The #1 use would be conversion of percentile values in particular, like 70%, to bare numbers, like 70. Need a variant function that divides the result by two and rounds to two decimal places, but I'm sure I can add that myself after I see how the main part works.

A more advanced version that could be invoked directly or required by other modules, might do something like this:
  • For any arbitrary input, trim all leading material until it hits any of:
    • a numeral; or
    • a . followed by a numeral; or
    • a - or the proper negative/minus glyph followed by either of:
      • a numeral, or by
      • . followed by a numeral
  • then retain that character;
  • proceed to next character, and retain it if matches either:
  • a numeral, or
  • a ., unless one was matched earlier;
  • repeat until that fails (i.e. a second . is found, or any other non-numeral is found);
  • then trim everything after that;
  • and do all this for multiple values.
A later super-badass version could add:
  • recognize ^ or e, and x or × or * when found in a context that indicates an exponent (23.5x10^8), and a few other such cases (e.g. characters used to indicate a truncated long/endless decimal)
  • find multiple numbers per input string, and separate them by something (e.g. a space or a comma) depending on which function is invoked

Any help on the basic request at the top would be much appreciated, the rest is more of a "what if...?" proposition.  — SMcCandlish ¢ ≽ʌⱷ҅ʌ≼  22:33, 17 July 2015 (UTC)

I'm no Lua expert, so here is a starting point that could probably be done better:
function ExtractNumbers(str)
    local tResult = {}
    str:gsub( "%-?[%d%.]+", function(x) table.insert(tResult, x) end)
    return tResult
end
and call with
myvar = ExtractNumbers('style="font-size: 70% ;"')
The result is a table, so to get just the first value
myvar = ExtractNumbers('style="font-size: 70% ;"')[1]
Hope this helps. -- WOSlinker (talk) 23:04, 17 July 2015 (UTC)
@WOSlinker: Thanks. I didn't get your pattern to work (plugging it in threw errors), but after a nap, I figured out what I was trying to do, at Module:StripToNumbers, other than it needs more precise pattern matching. Its talk page outlines the remaining problem (short version: input like font-size: 10% will come out as -10%. Your use of a table is probably more robust, too; I just did enough to get the result I immediately needed for a specific application, conversion of "70%" to "70", and the ability to halve it. Anyone should feel free to tinker further.  — SMcCandlish ¢ ≽ʌⱷ҅ʌ≼  14:51, 18 July 2015 (UTC)
@SMcCandlish: Changing onlyNumber = (string.gsub(theString, "[^%d%.-]", "")) to onlyNumber = (string.match(theString, "%-?[%d%.]+")) would help with the problem with font-size: 10%. It would also just retun the first set of numbers rather than all numbers in theString. -- WOSlinker (talk) 16:36, 18 July 2015 (UTC)
[Genuflect] Very nice! Worked like a charm.  — SMcCandlish ¢ ≽ʌⱷ҅ʌ≼  16:54, 18 July 2015 (UTC)
@SMcCandlish: If you want to access data passed to Lua in nowiki tags, you can do so with mw.text.unstripNoWiki, like this. — Mr. Stradivarius ♪ talk ♪ 03:51, 19 July 2015 (UTC)
Nice. Thanks for fixing that in the template.  — SMcCandlish ¢ ≽ʌⱷ҅ʌ≼  18:55, 23 July 2015 (UTC)

Breadcrumb version of Module:Multi-section link

Please see Template talk:Multi-section link#Development request. Short version: Need variant that links each sectional name, not just the last one.  — SMcCandlish ¢ ≽ʌⱷ҅ʌ≼  18:55, 23 July 2015 (UTC)

Collaboration with wikia on module development and auto summation in tables

After going through these requests, I found and completed a recent one(here) that I've wanted to create since lua was announced in wikia:

Anyway, in wikia modules are listed [1] so feel free to import any modules you find useful (I've shamelessly imported many from here anyway :). Unlike mediawiki's scribunto, wikia has global modules that can be accessed from any other wikia, however they haven't really become popular yet (almost nobody adds modules to dev.wikia). So maybe those interested can import modules from there to here or here to there or even collaborate on some modules.

Wikia's scribunto doesn't have all libraries available in mediawiki though, so some scripts that work here may not work there.

Announcement,module and github merge:

Dessamator 197.218.89.127 (talk) 14:49, 15 August 2015 (UTC)

Re-write Template:World topic as a Lua module

The source code of this template is verbose, redundant, and difficult to read. It should be re-written as a Lua module so that it can be maintained more easily. Jarble (talk) 01:27, 19 June 2015 (UTC)

lua may make life easier a tad (though i actually doubt it), but there is no real need for lua in order to make this more manageable: the template is extremely repetitive, and lends itself easily to improvement by simple use of some helper template (say, one that will accept prefix, suffix, noredlinks and the actual country name, and will do the right thing). the main template then will look something like
{{helper| {{{prefix|}}} | {{{suffix|}}} | {{{noredlinks|}}} | Angola }}
{{helper| {{{prefix|}}} | {{{suffix|}}} | {{{noredlinks|}}} | Denmark }}
... (repeat for all countries)
this may still look a bit cumbersome, but it's a dramatic improvement over current state: all the #if and #ifexist are delegated to the helper template, and of course, the helper is not at all repetitive - it only does whatever it needs to do once.
as a side, i'll mention that #ifexist is in the list of "expensive parser functions" (using lua will make no difference here - calling an expensive function from lua is just as expensive...), and its usage in this template seems to me to be sailing very close to the wind (i did not count, but there's a*lot* of countries...).
peace - קיפודנחש (aka kipod) (talk) 16:00, 19 June 2015 (UTC)
I am taking this task, making an module instead of template:world topic.--Snaevar (talk) 15:06, 2 July 2015 (UTC)
@Snaevar: I've been working on a version of the new Module:World topic that loads the country data from a separate page (incomplete for testing purposes) to allow the main code to be reused for other region-topic templates (as described at the templates' entry in WP:Lua/To do). It includes most of the features of {{Europe topic}} et al. that the current code in Module:World topic doesn't have:
  • Support for multiple navbox groups (e.g. "sovereign states", "states with limited recognition", "dependencies");
  • Country-specific parameters to individually enable or remove entries, or change the link targets (e.g. |GE=Foo of Georgia);
  • Option for a switch to enable/disable multiple entries simultaneously, and to hide specific entries by default;
  • An |article= parameter to either enforce or prevent the definite article (using the current "prefix but no suffix" rule if unspecified);
  • No automatic space between prefix/suffix and country name if unnamed parameters are used, allowing constructions in which a non-space character directly precedes or follows the country name (e.g. Index of Peru-related articles).
It additionally removes the need to explicitly number the countries and manually change over a hundred numbers when adding or removing entries in the first part of the alphabet (like here). Though some more features will be needed to fully replace some continent-topic templates, e.g. sub-lists for England etc. in Europe topic, could this be useful for the Lua-based version of World topic? (I'll do some more extensive testing at Template:World topic/sandbox if so.) SiBr4 (talk) 21:31, 23 July 2015 (UTC)
I think it is not worth making an unified module for world topic, Euro topic, Asia topic etc. Instead I would like to see the country table in Module:World topic to be moved to an submodule that would be shared with another module that would cover Euro topic and Asia topic. Changing Module:World topic to use an country table from another module would be pretty trivial (in therms of difficulty) for me to do.
World topic does take an different approach than the Euro topic and Asia topic templates. I would not want to see the redlink check from World topic in euro topic - for the reasons kipod mentioned earlier. In a similar way, the features of Euro topic are not of much use to world topic.
Writing that though, I still think that the countries in the country table should not be numbered, as I am very much aware how much of an issue that would be to maintain.--Snaevar (talk) 16:31, 24 July 2015 (UTC)
I disagree that the features of the other topic templates could not be useful to World topic or vice versa. For example, country-specific parameters are necessary for individually correcting links and avoiding redirects if not all titles follow the exact same format or the linking names from the data page, and the article parameter is useful if the default rule for including the definite article (prefix and no suffix) gives false positives or negatives.
Automatically omitting non-existing articles would always be optional and opt-in, as it currently is in World topic; it could be easily explained in the template documentation that the feature is expensive and should not be used unless necessary. It would also be much less expensive in continent-topic templates than it is in World topic, since the former have fewer links (<60 as opposed to ±200), and thus fewer existence checks.
I'm not sure I understand your alternative proposal; I read it to be that a single country list is used by all region-topic templates, while a separate formatting module is made for the continents (or even for each continent separately). I don't know how easy a unified data page would be to implement, though, and per the above I think there should be a single module with the main code, if only for consistency. SiBr4 (talk) 22:41, 24 July 2015 (UTC)
I think you have addressed the conserns that I had over merging the topic templates. I am fine with merging those templates into one module. I am still going to watch World topic and if I come up with something that goes in the same direction as you are going with this, then I will suggest it.
The fact that I am fine with your proposal makes the following paragraph about my alternate proposal kind of pointless, but here it is non the less.
You did understand my alternate proposal correctly. As long as the table contains information about which continent the country is in, it is possible to format the table for the continents. The main usecase would be to make it easier for users to update the list, by editing one list instead of several. If that is not worth it, then so be it. I am only throwing ideas around at this stage anyway.--Snaevar (talk) 20:06, 23 August 2015 (UTC)
A separate "continent" field to allow a single country list could work, but that would get somewhat complicated (though not impossible) with transcontinental countries such as Russia. With separate lists of countries, any change for non-transcontinental countries would have to be made at two pages (those for the respective continent and the world); more if region-topic templates such as the Americas, Southeast Asia and Central America are included. Separate lists would be needed anyway if templates listing subnational entities (Brazil, UK, etc.) are also converted. SiBr4 (talk) 15:31, 24 August 2015 (UTC)
I moved my test module to Module:Region topic one week after my previous comment, and started sandboxing replacements for the existing continent templates (Asia, North America) afterwards. I think I'll start a discussion at the centralized Template talk:About continent and region topic templates regarding the Lua replacements—probably a better page than this. SiBr4 (talk) 19:06, 7 October 2015 (UTC)

Loops and Lua

Module:User:Doc Taxon/Hello and user:Doc Taxon/Hello

Hi, I am looking for help creating a loop by Lua. I want the script to output the hello line 5 times, but I get back this: "Lua error in Module:User:Doc_Taxon/Hello at line 10: attempt to concatenate global 'u' (a table value)." What can I do? Thank you very much Doc Taxon (talk) 15:07, 12 October 2015 (UTC)

You initiated u as a table, it needs to be a string. An easy fix so I’ve gone ahead, everything else in it seems fine.--JohnBlackburnewordsdeeds 15:58, 12 October 2015 (UTC)
I edited the module to show how 'for' is used. There is rarely a need for 'repeat'. Johnuniq (talk) 02:19, 13 October 2015 (UTC)
small style comment: it is very common to use boolean shortcut in lua, togehter with the fact that practically any type can be used as boolean. so instead of
    local name = frame.args[1]
    if not name then 
        name = 'World' 
    end
, it is very common to write
    local name = frame.args[1] or 'World'
personally i find this syntax not only more succinct, but also clearer and easier to read. often times you see "a or b or c or d", which will evaluate to the first of those expressions that is not "false". this pattern exists in other languages, but there is a small pitfall here: in lua, only "false", null and "undefined" are false. 0, empty string, empty table etc. are all "true". also note the "shortcut" part: the expression will stop evaluating once the outcome is known, so you can handily use it for control: e.g., instead of
if not a then
    do_something()
end
you can simply write
a or do_something()
in addition to being shorter and sweeter, the 2nd example actually return the value (either of a or the return value of the function). similarly, instead of
if a then
    do_something()
end
you can write
a and do_something()
some of the developers frequenting this page may scoff at this style, but i find it preferable, and it is very common among lua programmers, so even if you do not want to write this way, it's at least a good idea getting used to reading it.
peace. — Preceding unsigned comment added by קיפודנחש (talkcontribs) 20:08, 13 October 2015 (UTC)
Small nitpick: only false and nil are falsy in Lua. There is no distinction between null and undefined as there is in JavaScript, and in Lua the spelling is nil, never null. — Mr. Stradivarius ♪ talk ♪ 10:12, 16 October 2015 (UTC)

Requesting Module:Location map/data/Pyongyang

I'm requesting Module:Location map/data/Pyongyang (cf. Module:Location map/data/Istanbul). The map image can be found at File:Map Pyongyang.jpg. The relevant country level location map template is at Template:Location map North Korea. For reference, the requested module already exists on the French (fr:Modèle:Géolocalisation/Pyongyang) and Polish (pl:Szablon:Mapa dane Pjongjang) language Wikipedias. Finnusertop (talk | guestbook | contribs) 12:51, 15 October 2015 (UTC)

Module is now up and running. MrPenguin20 (talk) 16:02, 18 October 2015 (UTC)

Is it possible to get the dates of modification for files (in this case, files on Commons)?

Previously, I pinged some users to bring attention to this discussion. Their attention was no longer needed after the reply below. Sorry for the inconvenience.
Right now, Commons has a collection of war maps which are frequently updated using data from collaboration which happens on the English Wikipedia for each map. A problem exists where the date these war map images were last updated needs to be distributed to articles which use the maps, so that users can know how up-to-date they are ("current as of 10 Nov 2015" or something). This problem is currently being solved using this module which might as well be a template and has to be manually updated. Is it possible, using Lua, to automate the retrieval of this date, or possibly generalise it to any file so that future maps can also have this convention applied to them? If it isn't possible using lua, I'm strongly considering writing a bot which does this automatically. Thanks in advance. --BurritoBazooka (talk) 02:07, 10 November 2015 (UTC)

@BurritoBazooka: No, this isn't possible at the moment. You can see the file metadata available to Lua here, but the time of last update isn't in there. The closest we have is {{REVISIONTIMESTAMP: File:filename}}, but that only works for files on the local wiki, and it also includes edits to the file description page as well as new uploads. If that works for you, you can call it from Lua using frame:callParserFunction('REVISIONTIMESTAMP', 'File:Filename'). Best — Mr. Stradivarius ♪ talk ♪ 02:46, 10 November 2015 (UTC)
Ah, thanks for the reply. --BurritoBazooka (talk) 02:49, 10 November 2015 (UTC)

Why are module main objects called p?

I'm curious to know what the p stands for? Is it program? public? --Psychoslave (talk) 12:50, 25 November 2015 (UTC)

I think it might be "package", as used in PIL here, but I might be wrong. — Mr. Stradivarius ♪ talk ♪ 14:04, 25 November 2015 (UTC)
"package" would be my guess too. Anomie 14:41, 25 November 2015 (UTC)

Is Lua the right way to do a table lookup?

The current {{Zodiac date}} gives wrong answers for 2015. The approach of finding an empirical formula to predict dates of astronomical events is both not feasible and original research. I'm thinking of creating a Lua program that would have 12 tables, one for each sign of the zodiac. Each table would have a list of years from 2015 through 2050 (which is as far as my reliable source will predict). The index of the table would be the year, and the result from the table would be a day of the year (e.g "Feb. 18". Each table would have 35 rows.

I haven't programmed in Lua before, but I've programmed in many other languages from System/370 assembler to C#, so I'm not worried about figuring out the language. But I am concerned that having such a large template might be detrimental to the articles that include the template. Am I on the right track? — Preceding unsigned comment added by Jc3s5h (talkcontribs) 14:30, 29 November 2015 (UTC)

Yes. Module:Citation/CS1/Configuration, for example, is nothing but tables, some of them rather larger than your zodiac tables will be.
—Trappist the monk (talk) 15:02, 29 November 2015 (UTC)
We also have mw.loadData to make doing this kind of thing more efficient if two different #invokes on a page use the same data table. — Mr. Stradivarius ♪ talk ♪ 22:01, 29 November 2015 (UTC)
Thanks. It will take some time for me to generate the necessary data and write the template. (The reliable source is the US Naval Observatory's Multi-year Computer Interactive Almanac; it does not directly spit out the required dates, so the available information must be generated and then interpolated to find the dates.) Jc3s5h (talk) 22:14, 29 November 2015 (UTC)

scan for template text in category of articles

Is it possible to scan the contents of articles for specific text strings (actually template) based on a list of articles in a category and its sub-categories? I would like to make these table numbers dynamic. --Traveler100 (talk) 18:03, 4 January 2016 (UTC)

It would help if you were to spell out the operation required for an example, but I suspect the answer is that it is too complex to be achieved with a module. I think you need to list the articles in various categories, then read the wikitext from each page and work out if a certain template is used. I don't think "what links here" is available to a module so using that as a workaround wouldn't work. Some kind of bot would be needed. Johnuniq (talk) 22:16, 4 January 2016 (UTC)
On Wikivoyage the categories are very hierarchical and clean and the articles a standard format so not as risky as with Wikipedia. Task, take a category (say a country), progress through all sub-categories, for each article n categories do a text search for use of specific templates ({{outlinecity}}, {{guideregion}}, .. {{sleep , ..) if found at to count expression. Return count values. --Traveler100 (talk) 06:01, 5 January 2016 (UTC)
Modules don't have access to category members, so this is not possible in Lua at the moment. It is possible to load the wikitext of a given page, but then parsing that wikitext to find a list of templates is hard. You need to take into account things like nowiki tags, HTML comments, template redirects, capitalisation and whitespace allowed for template names/arguments, etc. (This kind of thing is the reason that we have Parsoid, but that data is not available from Lua by design.) The only practical way at the moment to do what you are proposing is to use a bot to update the table. — Mr. Stradivarius ♪ talk ♪ 13:03, 5 January 2016 (UTC)
Just a crazy idea... Could one use JS on the client side to run a mediawiki API to get categories then 'alert data' to call module (via expandtemplates) on server side to do some processing to get category/page names - then get page contents and parse for templates... I can imagine the CPU cycles would be a bit overwhelming and probably die, not to mention the complexity of data parsing. I would expect something like this would have to be limited. -- Definitely would be better if Lua could access category members!Matroc (talk) 01:53, 14 January 2016 (UTC)
in principle yes, though i think you are mixing your metaphors: the API call is "parse" - "expandtemplate" is something to use from lua, not on client side. you can call "parse" with any piece of wikicode, and even tell the backend to parse it "as if" this text was part of a specified page (so, for instance, magic words such as {{PAGENAME}} or {{PAGESIZE}} that the template might use, will receive the desired value.
this whole line of investigation may be wrong, IMO: i do not fully understand the requirements, but to me, it looks awfully close to a functionality cirrus-search already have: we now have meta-search words that can do what i think you want. specifically, "incategory:" and "hastemplate:". this will _not_ cover the "and its subcategories" part of the original request, so if this part is essential, my suggestion falls short. peace - קיפודנחש (aka kipod) (talk) 15:47, 14 January 2016 (UTC)
Thanks - I thought I might have been a bit off base, it was just something I had been thinking about - peace - Matroc (talk) 22:22, 14 January 2016 (UTC)

Code review of Module:Timing

If anyone has some spare time then perhaps do a code review of Module:Timing? And the doc page needs a spell check too! I believe the precision in the produced numbers are about as they get, but there could be other ideas out there. Note that this solution are for those that develop code on their own, without a debugger running in a controlled environment. Note also that the test cases are written for another library, and that it does not work as of this writing. Hopefully it will work later on. Jeblad (talk) 18:03, 18 January 2016 (UTC)

The code is good but since you asked here are some thoughts from a quick look.
  • Line 37–38: Empty for loop with no purpose?
  • Line 44: Nothing wrong with math.pow but it is the same as v^2.
  • Line 46: I don't know if the timing table could ever be empty, but I would test for #timing == 0 even if I thought it couldn't happen.
  • Line 59/63: With a loop like that I would just have time[i] on the lhs.
  • Line 74: Is there a reason p.combine is part of p? Why not just a local function, if module users don't need to access it? Similar for other functions.
  • Line 124: Could be "local function dummy()" as I don't think a global is needed.
It would be pretty rare for a module to need timing, although I happened to do some crude testing of a module I'm working on the other day. Johnuniq (talk) 08:36, 19 January 2016 (UTC)
Thanks for the reviw!
  • p.combine was an access point for testing, could be put inline instead
  • function dummy() is used for baseline timing, and usually you will not test local functions
You will probably never add this to an ordinary module, it is only for crude testing to figure out which kind of code actually works well in this Lua environment. Jeblad (talk) 09:42, 19 January 2016 (UTC)
I think the only effect of putting "local" in front of "function dummy()" would be to change the scope of where dummy can be accessed (along with the fact that a global dummy would be added to the _G globals table). As the code is now, executing dummy = 'hello' would wipe out the dummy function. By "pretty rare" I meant that it would be rare to need to test the timing of a module. I understand that you don't use Module:Timing in another module, but nearly all modules run very fast and don't need to be optimized. I would think any modules that are too slow are just trying to do too much work, and only a very small number of modules would benefit from measuring the time taken by various functions. As mentioned, I had one of those rare exceptions a few days ago where I found a bottleneck that was removed by using a different method. However, I was doing a ridiculously large number of tests just from interest to see how long it would take. Johnuniq (talk) 10:24, 19 January 2016 (UTC)
If you use this module to test load in modules you probably know that executing dummy = 'hello' would have some implications. I haven't checked timing for local lookup, but usually that is much faster in other languages. Often by a factor ten or more. I can put the dummy function in the exported lib, that would be close enough.
The module was written as part of a larger testing framework, which had some timing issues. It was also used for testing FSMs. Jeblad (talk)
I'm sorry to be argumentative and the issue is trivial and can be ignored, but a user would test the timing of a function by executing something like =require 'Module:Timing'(p.hello). In the timing module, timing for the following would then be obtained:
self.runner(dummy, ...)
self.runner(func, ...)
That compares the time to access and execute dummy with the time to access and execute func. The former is a global variable which needs to be looked up in the _G globals table, while the latter is a function parameter which has the same fast access time as a local variable. Therefore using a global for dummy is not adding any accuracy. I'm just mentioning that as something I noticed, but it is unimportant and if there are reasons for having dummy a global for use in another situation, that's good too. Johnuniq (talk) 02:01, 20 January 2016 (UTC)
I was going to point out that Scribunto will report the top functions by time in a page (in the "Parser profiling data" section at the bottom of the preview page) when the page uses more than 1s of time in Lua, but it turns out that was disabled while debugging T70413 and never turned back on. Anomie 03:36, 21 January 2016 (UTC)
Pushing the code above 1s to get a readout would be e bit nasty. The code is more than good enough to figure out simple bottlenecks. Jeblad (talk) 01:33, 22 January 2016 (UTC)