Wikipedia talk:Lua

From Wikipedia, the free encyclopedia
  (Redirected from Wikipedia:Lua requests)
Jump to: navigation, search
Project talk
  To do
en: m: mw: external

Posting to external websites[edit]

I am trying to find out if it is possible to post (edit) to wikidata from a lua script in wikipedia? Julialturner (talk) 06:28, 31 May 2016 (UTC)

@Julialturner: No, it's not possible to edit pages from Scribunto modules (Scribunto is the name of Wikipedia's Lua implementation). Lua modules have roughly the same functionality as templates do. To edit a page, you would need to use a script that accesses the API. — Mr. Stradivarius ♪ talk ♪ 06:38, 31 May 2016 (UTC)

Lua error[edit]

Hello everyone! What is this error Lua error in Module:appellatio at line 55: attempt to concatenate local 'page_pron' (a nil value) saying? -- DenisWasRight (talk) 14:25, 1 June 2016 (UTC)

The code at line 55 of the Module:appellatio (not on, is attempting to concatenate two or more strings into a single string. Commonly, something like:
result = string_one .. ' ' .. string_two;
where either of string_one or string_two has a nil value. You can concatenate empty strings:
string_one = 'Some text';
string_two = ''; -- empty string
result = string_one .. ' ' .. string_two;
which gives the result:
"Some text "
If you identify where the module is and how you got the error message, someone here can probably provide more specific help.
Trappist the monk (talk) 14:48, 1 June 2016 (UTC)
The error is part of this module. -- DenisWasRight (talk) 16:28, 1 June 2016 (UTC)
The variable page_pron in that module is defined as
local page_pron = p.page_pron(lang_code) or p.radix_pron
One issue (there may be more) is that p.radix_pron is never defined, and thus always nil. It was defined in the original revision (with a different name), but removed here. SiBr4 (talk) 16:33, 1 June 2016 (UTC)
I change the names because it's in french. Will this solve my problem. -- DenisWasRight (talk) 16:37, 1 June 2016 (UTC)
It's ok now. Thanksss. -- DenisWasRight (talk) 16:53, 1 June 2016 (UTC)
How can I move the audio template behind the IPA pronunciation. Like in this picture? -- DenisWasRight (talk) 17:26, 1 June 2016 (UTC)

Template:cfd all[edit]

Can some one please convert {{cfd all}} intoa module-based template? Please set it up so that all the numbered parameters currently used will be derived from a single letter passed as a parameter (i.e {{cfd full}} will send a parameter "d" to represent the type of CfD tag, along with date parameters and an optional section parameter the way it does now; add a target parameter for the other CfD tags to work). עוד מישהו Od Mishehu 20:40, 11 July 2016 (UTC)

@Od Mishehu: It sounds like just replacing numbered parameters with one named parameter wouldn't need Lua. It might be simplest just to edit the template to add that parameter without converting it to Lua at all. I would try to do it myself, but from your description I'm sure exactly what you want to be done. Maybe make a more detailed suggestion on the template's talk page? Best — Mr. Stradivarius ♪ talk ♪ 23:36, 12 July 2016 (UTC)
If you look at {{cfr full}}, you'll see that it starts with: {{cfd all|renaming to {{#if:{{{target|}}}|{{cat|{{{target}}}}}|some other name}}|cfr|Rename|rename|renaming; I would like this to be replaced with {{tl|cfd all|r (note that {{{target}}} is passed on later in the list parameter list). עוד מישהו Od Mishehu 02:54, 13 July 2016 (UTC)

Lua conversion for Template:Sensitive IP addresses, and is a Lua-to-JSON feature possible?[edit]

Following up on Wikipedia:Village_pump_(technical)#, I wonder if it's possible to convert Template:Sensitive IP addresses to use Lua. And whether it's possible to make such a module create either wikitext output or JSON output, the latter for MediaWiki:Group-sysop.js - as discussed in the VPT thread the JSON there is far outdated. If that is possible, a good setup may be Module:Sensitive IP addresses containing the Lua code proper and Module:Sensitive IP addresses/List of addresses containing the list of IPs and associated owners.Jo-Jo Eumerus (talk, contributions) 21:44, 12 July 2016 (UTC)

Yes, it's possible. I did something similar with Lua data for Module:Signpost, its data tables at Module:Signpost/index/2016 etc., and User:Mr. Stradivarius/gadgets/SignpostTagger.js. I've actually started working on this, but I decided to go about it in a slightly roundabout way - I've started writing a library for dealing with IP addresses at Module:IP, and I plan to convert Template:Sensitive IP addresses after that's done. — Mr. Stradivarius ♪ talk ♪ 23:23, 12 July 2016 (UTC)
Sweet. Mr. Stradivarius, take note that I've proposed to use Template:Sensitive IP addresses on MediaWiki talk:Blockiptext and Wikipedia:Blocking policy, so some alterations may happen.Jo-Jo Eumerus (talk, contributions) 23:29, 12 July 2016 (UTC)
Module:IPblock does a lot of work with IPv4 and IPv6 addresses. It can parse them from wikitext and put each address in a table (same structure for both v4 and v6). Addresses can be compared, sorted, and masked, and the number of common prefix bits can be calculated (function common_length is astonishing!). It can output the text representation of an IP. Johnuniq (talk) 23:50, 12 July 2016 (UTC)
That's an impressive module! Thanks for pointing it out - I wasn't aware of it before. My instinct would be to move the generic IP functions to Module:IP so that other modules can use them, and keep the range-calculating code in Module:IPblock. There are already at least three modules that need to work with IP addresses - Module:IPAddress, Module:IPblock, and the new proposed Module:Sensitive IP addresses. What do you think? And also, what do you think of the interface I have sketched out? That is still a work in progress, and we can change stuff as necessary. — Mr. Stradivarius ♪ talk ♪ 02:01, 13 July 2016 (UTC)
Moving the code is fine. I'd like to postpone thoughts from me for 24 to 48 hours. If you're in a hurry, go for it; otherwise, you might wait for me to copy in the functions I think would help so they can be massaged into the required form. I do not understand what SignpostTagger.js or the module are doing, but it looks like the js is writing the module code—amazing! By the way, if you've never tried it, it can be quite easy and efficient for a module to parse a long string. That might be a good technique for the current IP application where all that is wanted is a plain-text list of IP addresses, possibly with CIDR ranges, and that would be simple to parse although my module does not handle big CIDR ranges because of some internal calculations it does (it keeps a list of every IP in a range, and that's not feasible for IPv6 or big IPv4 ranges). For an example of parsing a long string, see the "list" parameter in Template:Football manager history#Examples. The code which parses that is function make_list in Module:Football manager history. Johnuniq (talk) 04:50, 13 July 2016 (UTC)

@Mr. Stradivarius: I put some preliminary thoughts at Module talk:IP. Johnuniq (talk) 11:10, 14 July 2016 (UTC)

Adding references to Infobox template[edit]

I would like to be able to add references to lua template and have them show up at the bottom of the wikipedia page as when the <ref> tag is used. Is there a lua module somewhere to help me do this? see the section with diseases. These numbered references items should correspond to those numbered in the reference section. Thanks you. Julialturner (talk) 05:53, 13 July 2016 (UTC)

The only way to get a reference is for the wikitext to include <ref> tags. I don't think Module:Sandbox/genewiki/alllua outputs any refs. Modules are run after several other steps in preparing the wikitext are completed, and one of those steps involves processing ref tags. I think that means that any ref tags output by a module won't work. Instead, it appears a module would need to use extensionTag. I have never tried that. By the way, Lua handles true/false variables. Instead of f = "true" (a string), use f = true. After doing that, f can be tested with if f then ... (no need to mention true). Johnuniq (talk) 06:14, 13 July 2016 (UTC)
Thank you for the extensionTag suggestion I will try to go that route and also for the true false pointer. Julialturner (talk) 19:16, 13 July 2016 (UTC)
if you need to process stuff that is typically processed before the module is invoked, use frame:callParserFunction(), frame:extensionTag(), or frame:expandTemplate() (the last one only works if you have a template that produces the tag, which is often the case with ref tags) . it's explained here, and interestingly enough, the documentor(s) (sp?) chose the "ref" tag for one of the examples. peace - קיפודנחש (aka kipod) (talk) 22:49, 13 July 2016 (UTC)
I think you made a typo there - that should be frame:expandTemplate, not frame:extendTemplate. — Mr. Stradivarius ♪ talk ♪ 23:17, 13 July 2016 (UTC)
thanks. fixed. whoever reads this should not go by what i wrote directly - the important part was the link to the section on the manual page. peace - קיפודנחש (aka kipod) (talk) 14:03, 14 July 2016 (UTC)



I was hoping for someone to create a new function to the Module:String.

The function will give the first line of a string

for example:





will give you hello Thanks in advance--Mikey641 (talk) 15:51, 22 July 2016 (UTC)

  • This is not necessary:

Paweł Ziemian (talk) 18:46, 22 July 2016 (UTC)

Paweł Ziemian Thanks alot!!!--Mikey641 (talk) 00:25, 24 July 2016 (UTC)

Saving modules[edit]

I am having difficulty saving a module and its documentation page. Is there anyone I can ask for help? --פוילישער (talk) 18:29, 26 July 2016 (UTC)

@פוילישער: What happens when you try to save it? Could you give us a link to the pages you are trying to save, or maybe paste the content here if that's easier? — Mr. Stradivarius ♪ talk ♪ 22:46, 26 July 2016 (UTC)
Thank you. The problem manifests itself on yiwiki. I was trying to save the code for Module:Infobox. You can find it in my sandbox (as part1). When I try to save it nothing happens.

Many thanks --פוילישער (talk) 05:41, 27 July 2016 (UTC)
I have just tried again without the modifications I made and have been successful this time. I must have introduced some error in the code. --פוילישער (talk) 05:55, 27 July 2016 (UTC)

Is frame:getParent() efficient?[edit]

There seem to be two ways for a module to get the parameters from the template that invoked it: one is to have the template explicitly pass all of its parameters, and the other is to have the module get all the parameters via frame:getParent().args. Does anyone know if one way is computationally cheaper that the other? Uanfala (talk) 13:13, 5 August 2016 (UTC)

I do not know the implementation details, however I suspect that frame:getParent().args is better. The parameters passed to template are already parsed but using them while invoking the template need additional cost. But forget the details and try Module:Arguments, which make all the dirty things transparent and allows to mix various method including calling functions even from other modules. Paweł Ziemian (talk) 15:35, 5 August 2016 (UTC)
The two ways to get parameters into a module are:
  1. frame.args parameters from the template invoking the module
  2. frame:getParent().args parameters from the page using the template
You probably mean that wikitext in the template could attempt to pass the expected parameters so #2 would be a duplicate of #1. There is no reason to do that and modules are sufficiently fast to know that the overhead of getParent is trivial. Like Paweł Ziemian, I would expect that duplicating the parameters in the template would be a tiny bit slower because it would require MediaWiki to parse the parameters twice, whereas the getParent code is probably much more efficient. Module:Arguments combines the parameters from the above two methods. Johnuniq (talk) 01:16, 6 August 2016 (UTC)
When Scribunto was first being developed, the ability to get arguments directly from frame:getParent().args was actually one of the big reasons that Lua modules were anticipated to be faster than wikitext templates. This is apparent from the design documents, which talk about a "substantial cost" for "every triple brace and every pipe". The speed of parsing wikitext improved greatly with the introduction of HHVM in 2014 (a year after the Scribunto rollout), but I am guessing that you could still get a considerable performance boost by switching from frame.args to frame:getParent().args for modules that accept a lot of parameters. To say anything for certain someone would need to run some benchmarks, though. — Mr. Stradivarius ♪ talk ♪ 05:30, 6 August 2016 (UTC)
More importantly, I can't imagine there being any downside to using frame:getParent().args over frame.args, so you may as well use it. These days I mostly use Module:Arguments with the wrappers option, though, which has the same benefits as using frame:getParent().args and also allows you to use the same arguments with #invoke directly if you want. Module:Arguments also allows you to automatically trim whitespace and to remove blank arguments, which I find is almost always needed. — Mr. Stradivarius ♪ talk ♪ 05:38, 6 August 2016 (UTC)
Thank you everyone for the responses. I'll have a look at Module:Arguments (hopefully this isn't going to slow things down compared to frame.getParent().args?). Speaking of performance, I notice that for a few days now I haven't been able to see much in the Parser profiling data area at the bottom of the page when previewing an edit. This used to be a table containing information about Lua memory usage or template argument size, but now it only lists the number of Wikibase entities. Does anyone know anything about that? Uanfala (talk) 15:44, 10 August 2016 (UTC)

Passing wikitables as arguments[edit]

Hello, it seems that passing Wikitables as arguments does not always work as expected. The internal "|" are apparently interpreted as parameter separators: see Commons:Module talk:Artwork. Does anyone have a solution, other than rewriting all templates to avoid Wikitables ? --Zolo (talk) 06:17, 12 August 2016 (UTC)

if you must pass a whole wikitable, have you tried frame:preprocess?
Trappist the monk (talk) 09:16, 12 August 2016 (UTC)
nevermind; wrong end of the process. It's not clear to me what it is that you are trying to accomplish with the module that isn't already accomplished by the template. You can, of course replace the content of the template with a module that writes the html of a table (HTML library). But why do that if the template does what it is supposed to do?
Trappist the monk (talk) 09:29, 12 August 2016 (UTC)
this issue is not specific to lua - it is a general thing with passing tables as parameters to templates. basically, there are 2 ways to handle this: (1) replace the | and || with {{!}} and {{!!}}, or (2) use html tags for the tables instead of wikicode (i.e., <table>..</table>, <tr>..</tr>, <th>..</th>, and <td>..</td>). HTH, peace - קיפודנחש (aka kipod) (talk) 15:49, 12 August 2016 (UTC)
Mediawiki parses the "|" character expecting a new parameter after it. To escape it, you have to use nested templates to escape this character. This was mentioned above by קיפודנחש (aka kipod) -- Don't forget that the same goes for the "=" character as well. -- Matroc (talk) 19:19, 12 August 2016 (UTC)
Thanks for the replies. If I undestand right, you are saying that I should change the Wikitext passed by the parameters to make it work ? What I don't get is why the non-Lua version works fine but not the Lua-based sandbox, in cases like {{Artwork|permission = {{PD-art}} }}.
@Trappist the monk: the template works, but is really not suited for integrating somewhat complex Wikidata retrieving features that would be really useful for internationalized artwork descriptions on Commons. --Zolo (talk) 21:31, 12 August 2016 (UTC)
The module needs to get a wikitable as an argument only because a table is the only kind of output produced by the permissions template, right? Wouldn't it make sense then to change the permissions template so that it can optionally produce its output in another, more parseable, format? Disclaimer: I don't know much about either Lua or templates Uanfala (talk) 21:53, 12 August 2016 (UTC)

Lua table for airports destinations[edit]

Hello everyone-that-are-well-of-Lua, any help would be greatly appreciated.

I know that one can pass wikidata<->Lua to write down a wikitable with information issued from wikidata, thanks for Mr Stradivarius.

I've started to work on an idea that would enable multilingual use of Wikidata to build for any airport XXX a table in which all linked airports would appear, and would be always up to date in any language [provided Wikidata is properly filled]. ==> The aim : prevent the fastidious work of updating airport pages.

For instance, this code (in french wikipedia) : {{Aéroport-Destinations|entity=Q17430|property=P521|P521|P931|P137|P521=Aéroport|P931=Ville|P137=Compagnie(s)}} would return the result shown in my page Utilisateur:Bouzinac. This code has been inspired of this one fr:Modèle:Tableau qualificateurs.

I'd like to have a finally simple template {{Aéroport-destinations}} which could be inserted into an airport wiki article.

This template would call a LUA script that will check and return all destinations for the said airport into a table with these properties ==>

  • "Airport name in short" (P1813)
  • "City served by airport" (P931)
  • "Airline" (P137)
  • "Start time" (P580), [if destination hasn't started yet, background-color in green]
  • "End time" (P582) [if destination has ended, no line show for this destination/airline OR background-color in red]
  • "Comment and reference(s)" (P2315)+(P854)

This new lua code would be properly working with airports or

Should this new code be working, it would then be adapted to destinations served by one airline.

Any help would be greatly appreciated. --Bouzinac (talk) 12:52, 26 August 2016 (UTC)

I had a go at creating a airport destinations table. It takes into account P931, P137 and P582, but not any of the other properties. If P582 is specified then that line is not processed at all. It is currently limited to show only one airline, just for now. The first argument is used to specify an item id, feel free to play with it as you see fit. Example below.
Aéroport Compagnie Ville
Dzaoudzi Pamandzi International Airport Air Austral Dzaoudzi
Orly Airport Air France Paris
Paris-Charles de Gaulle Airport Air Austral Paris
Sir Seewoosagur Ramgoolam International Airport Air Mauritius Mauritius
Suvarnabhumi Airport Air Austral
Seychelles International Airport Air Austral
Ivato Airport Air Madagascar
Chennai International Airport Air Austral
OR Tambo International Airport Air Austral
Prince Said Ibrahim International Airport Air Austral
Fascene Airport Air Austral Nosy Be
Marseille Provence Airport XL Airways France
Toamasina Airport Air Austral

--Snaevar (talk) 15:18, 28 August 2016 (UTC)