WP:Lua Project |
WT:Lua Project talk |
Help |
To do |
Requests |
Resources en: m: mw: external |
Lua scripts on Wikipedia are similar to templates but useful for performing more complex tasks for which templates are too complex or slow. Common examples include numeric computations, string manipulation and parsing, and decision trees. You can use this page to request help from Lua developers in writing a Lua module for a specific task on Wikipedia or another Wikimedia Foundation project. Both debugging help and full implementation are available.
To start a request, just make a new section below and describe what you need. You may wish to first check Special:PrefixIndex/Module: to see if you can find a suitable existing script.
It may help developers to provide examples of where the task is likely to be useful within Wikipedia. If the proposal would replace or improve upon existing templates, please note which ones.
Contents
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)
- @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:
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
local name = frame.args[1] or 'World'
if not a then do_something() end
a or do_something()
if a then do_something() end
a and do_something()
- peace. — Preceding unsigned comment added by קיפודנחש (talk • contribs) 20:08, 13 October 2015 (UTC)
- Small nitpick: only
andfalse
are falsy in Lua. There is no distinction betweennil
null
andundefined
as there is in JavaScript, and in Lua the spelling isnil
, nevernull
. — Mr. Stradivarius ♪ talk ♪ 10:12, 16 October 2015 (UTC)
- Small nitpick: only
- 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
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
. Best — Mr. Stradivarius ♪ talk ♪ 02:46, 10 November 2015 (UTC)frame:callParserFunction('REVISIONTIMESTAMP', 'File:Filename')
- Ah, thanks for the reply. --BurritoBazooka (talk) 02:49, 10 November 2015 (UTC)