![]() | This page 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 talk page. |
Following up on Wikipedia:Village_pump_(technical)#51.171.156.10, 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)
@ Mr. Stradivarius: I put some preliminary thoughts at Module talk:IP. Johnuniq ( talk) 11:10, 14 July 2016 (UTC)
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? /info/en/?search=User:Julialturner/RELN 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)
<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)
invoke
d, 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)
frame:expandTemplate
, not frame:extendTemplate
. —
Mr. Stradivarius
♪ talk ♪
23:17, 13 July 2016 (UTC)
Hey.
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:
hello
world
what's
up
will give you
hello
Thanks in advance--
Mikey641 (
talk)
15:51, 22 July 2016 (UTC)
{{#invoke:String|match|hello world what's up |^%s*.- |||}}→
hello
Paweł Ziemian (
talk)
18:46, 22 July 2016 (UTC)
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)
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)
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)frame.args
parameters from the template invoking the moduleframe:getParent().args
parameters from the page using the templateframe: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)
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)
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)
frame:preprocess
?{{Artwork|permission = {{PD-art}} }}
.Not sure where else to put this. I turned Template:ColPollTable into a module ( small test here). But it's weird because this is set to replace 20 independent templates. What bugs me though is whether or not the template is necessary. It seems to be used on only a few pages, which makes me wonder if its functionality might be covered by a superior template. If that's not the case and the template serves a unique function, then I'm not sure exactly how I should proceed to update the templates and their calls. mol uɐɯ 13:35, 30 August 2016 (UTC)
In
Module:Routemap/sandbox, I'd like to use the option removeBlanks = false
for the p._BSrow function, but only that function. Is it necessary to make another module for this?
Jc86035 (
talk •
contribs) Use {{
re|Jc86035}} to reply to me
12:25, 1 September 2016 (UTC)
|removeBlanks=false
to not remove blanks, or might omit that parameter to include them. And the template would invoke function BSrow
in the module. I don't see a problem and don't see why another module might be needed. What is the concern?positive(x)
and negative(x)
functions that would presumably be used to test args.removeBlanks
. If the wikitext omits the parameter (or equivalently, given that
Module:Arguments is used probably with defaults, omits the value), positive(args.removeBlanks)
would evaluate as false, and so would negative(args.removeBlanks)
. That's a bit awkward.
Johnuniq (
talk)
00:20, 2 September 2016 (UTC)
positive(x)
and negative(x)
functions are purely for internal use and I'm not sure why I'd use an args.removeBlanks in them.) Would having a makeInvokeFunction2 (duplicate but using removeBlanks = false) work, or is there a better solution?
Jc86035 (
talk •
contribs) Use {{
re|Jc86035}} to reply to me
07:08, 2 September 2016 (UTC)
The Wikidata implementation in {{
Coord}} (activated when |1=
and |2=
are both missing) doesn't seem to be working. On, for example,
Empire State Building, {{Coord}}
returns "40.7483°N 73.9853°WInvalid arguments have been passed to the {{#coordinates:}} function". Coordinates seem to be fine (other than that the coordinates were originally imported to Wikidata with 1⁄1000th of an arcsecond's accuracy), but it still returns the error. Does anyone have any idea why? Thanks,
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
13:22, 7 September 2016 (UTC)
{{#coordinates:...}}
? I don't understand what the bits and pieces are supposed to do, but it looks like #coordinates will output that error message unless it is fed valid data, and putting "{{Coord}}
" on a page would not feed it anything valid that I can see.
Johnuniq (
talk)
02:26, 8 September 2016 (UTC)
{{#invoke:Coordinates|coord}}
" at the article displays what is wanted without an error.
Johnuniq (
talk)
02:28, 8 September 2016 (UTC)
{{#property:P625|from=Q9188}}
- 40°44'54"N, 73°59'7"W if you just want standalone coordinates (with no links). --
Matroc (
talk)
03:15, 8 September 2016 (UTC)
{{#coordinates:}}
part to be put into the module as well, since otherwise the Wikidata implementation is a bit broken? There's
Module:WikidataCoord, but it doesn't have a template wrapper and is only used on a few pages.)
Jc86035 (
talk) Use {{
re|Jc86035}}{{#coordinates:}}
(and using it through the module), or is there a better solution?
Jc86035 (
talk) Use {{
re|Jc86035}} -- https://bugzilla.wikimedia.org/show_bug.cgi?id=50863 RESOLVED
return mw.getCurrentFrame():callParserFunction("#coordinates", params) or ""
where params is a table with parameters as described in mw:Extension:GeoData. Paweł Ziemian ( talk) 20:30, 8 September 2016 (UTC)
<maplink zoom="13" longitude="-73.985656" latitude="40.748433" />
40°44′54″N 73°59′8″W or <maplink zoom="13" text="Click Me!" longitude="-73.985656" latitude="40.748433" />
Click Me! - The decimal coordinates can be found by querying Wikidata. -- It all depends on what you are trying to do and what can be done with available tools/templates/modules etc.|latd=
, |latm=
, |longd=
etc. parameters in several hundred thousand infoboxes to just |coordinates=
) and this could have quite some changes in how the replacement's being carried out. (Side note: what do the Geohack parameters in {{#coordinates:}}
actually do?)
Jc86035 (
talk) Use {{
re|Jc86035}}Commons is a project where we spend a lot of effort on presenting everything in the language of the person viewing the page. That was traditionally done by layers and layers of very large and complicated templates, some of which become so complicated as to become unmanageable. Over the last several years we were working on transitioning some of them to Lua, which is a great improvement. Recently me and others were working on transition of c:Template:Creator and c:template:Artwork to c:Module:Creator and c:Module:Artwork and we are running into a problem of Expansion depth. Template version of the templates do not trigger it, but Lua versions do. See for example c:Module talk:Creator/testcases. The issue seems to be that if a template written in Lua is processing output of another template written in Lua than that triggers Expansion depth error. I reported some earlier case in phabricator:T133918, it seems like it will be a blocking issue before c:Module:Creator can be used. Do anybody have experience with working with that limit or understands logic of how Lua triggers Expansion depth. -- Jarekt ( talk) 13:18, 17 September 2016 (UTC)
p.creator
function, line 262) you seem to be using both Args
and args
; is this intended? I'm not sure where the expansion depth error is in the page.
Jc86035 (
talk) Use {{
re|Jc86035}}return {
creator = function (frame)
return frame.args.Workloc
end
}
#8 PPTemplateFrame_Hash->getArguments() called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:782] #9 Scribunto_LuaEngine->preprocess(current, {{int:lang}}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaSandbox/Engine.php:407] #10 Scribunto_LuaSandboxCallback->__call(preprocess, Array) #11 LuaSandboxFunction->call(Object of class LuaSandboxFunction could not be converted to string, getLabel) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaSandbox/Engine.php:319] #12 Scribunto_LuaSandboxInterpreter->callFunction(Object of class LuaSandboxFunction could not be converted to string, Object of class LuaSandboxFunction could not be converted to string, getLabel) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:245] #13 Scribunto_LuaEngine->executeModule(Object of class LuaSandboxFunction could not be converted to string, getLabel, tplframe{"entity":"<value><tplarg><title>1</title><part><name index=\"1\"/><value/></part></tplarg></value>", "lang":"<value><tplarg><title>2</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><tplarg><title>link</title><part><name index=\"1\"/><value>wikipedia</value></part></tplarg> </value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:898] #14 Scribunto_LuaModule->invoke(getLabel, tplframe{"entity":"<value><tplarg><title>1</title><part><name index=\"1\"/><value/></part></tplarg></value>", "lang":"<value><tplarg><title>2</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><tplarg><title>link</title><part><name index=\"1\"/><value>wikipedia</value></part></tplarg> </value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/common/Hooks.php:121] #15 ScribuntoHooks::invokeHook(Object of class Parser could not be converted to string, tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}, Array) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3352] #16 Parser->callParserFunction(tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}, invoke, Array) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3076] #17 Parser->braceSubstitution(Array, tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016] #18 PPFrame_Hash->expand(<root><ignore><includeonly></ignore><template><title>#invoke: Wikidata </title><part><name index="1"/><value> getLabel </value></part><part><name>entity</name><equals>=</equals><value><tplarg><title>1</title><part><name index="1"/><value/></part></tplarg></value></part><part><name>lang</name><equals>=</equals><value><tplarg><title>2</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><tplarg><title>link</title><part><name index="1"/><value>wikipedia</value></part></tplarg> </value></part></template><ignore></includeonly></ignore><ignore><noinclude> {{documentation}}</noinclude></ignore></root>) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3229] #19 Parser->braceSubstitution(Array, tplframe{}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016] #20 PPFrame_Hash->expand(<root><template><title>Label</title><part><name index="1"/><value>Q47465</value></part><part><name index="2"/><value><tplarg><title>1</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><template><title>#if:<tplarg><title>nolink</title><part><name index="1"/><value/></part></tplarg></title><part><name index="1"/><value>-</value></part><part><name index="2"/><value>wikipedia</value></part></template></value></part></template><ignore><noinclude> {{Documentation|Template:GeoName/doc}} [[Category:Multilingual tags: Locations in France|{{PAGENAME}}]] [[Category:Aix-en-Provence|~{{PAGENAME}}]] [[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]] </noinclude></ignore></root>, 0) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1449] #21 PPTemplateFrame_Hash->cachedExpand(Template:Aix-en-Provence, <root><template><title>Label</title><part><name index="1"/><value>Q47465</value></part><part><name index="2"/><value><tplarg><title>1</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><template><title>#if:<tplarg><title>nolink</title><part><name index="1"/><value/></part></tplarg></title><part><name index="1"/><value>-</value></part><part><name index="2"/><value>wikipedia</value></part></template></value></part></template><ignore><noinclude> {{Documentation|Template:GeoName/doc}} [[Category:Multilingual tags: Locations in France|{{PAGENAME}}]] [[Category:Aix-en-Provence|~{{PAGENAME}}]] [[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]] </noinclude></ignore></root>) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3226] #22 Parser->braceSubstitution(Array, frame{}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016] #23 PPFrame_Hash->expand(<value> <template><title>Aix-en-Provence</title></template>, <template><title>Paris</title></template>, <template><title>city</title><part><name index="1"/><value>Auvers-sur-Oise</value></part></template>, <template><title>Marseille</title></template> </value>, 4) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1529] #24 PPTemplateFrame_Hash->getNamedArgument(Workloc) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1541] #25 PPTemplateFrame_Hash->getArgument(Workloc) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1473]
Workloc
parameter (#25-23), which expands {{
Label}} (#22-18), which invokes
c:Module:Wikidata (#17-11), which calls frame:preprocess('{{int:lang}}')
in some manner (#10-9), which needs to expand the parameters passed into the current frame (#8), which includes Workloc
so repeat until the expansion depth is exceeded. The top-level local defaultlang = mw.getCurrentFrame():preprocess("{{int:lang}}")
in
c:Module:Wikidata,
c:Module:Wikidata/Tools,
c:Module:Wikidata/FormatEntity, and so on looks particularly suspicious.
BJorsch (WMF) (
talk)
23:54, 17 September 2016 (UTC)
frame:preprocess('{{int:lang}}')
is actually usually written as mw.message.new( "lang" ):plain()
to avoid calling preprocess. frame:preprocess('{{int:lang}}')
as the language parameter should be passes from outside (you only get users language if you pass it from the outside, like
here). --
Jarekt (
talk)
02:32, 18 September 2016 (UTC)
mw.message.new( "lang" ):plain()
is not equivalent to frame:preprocess('{{int:lang}}')
. --
Jarekt (
talk)
15:42, 19 September 2016 (UTC)
Args
and args
. That part of the code was wrong, but I was focusing on the expansion depth issue. --
Jarekt (
talk)
13:52, 20 September 2016 (UTC)(Pinging
Braveheart.)
Module:Coordinates now calls the {{#coordinates:}}
parser function through mw.getCurrentFrame():callParserFunction
. This unexpectedly broke
Module:HS listed building, which calls
Module:Coordinates' coordinates.coord
function directly. Any way of fixing this?
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
14:46, 20 September 2016 (UTC)
I've just started a discussion at VPT about rolling out the new sensitive IP modules, which might be of interest to people who want to use information about sensitive IPs in other modules or templates. Another item in the proposal which might be of interest is libLua.js, a library for calling Lua functions from JavaScript more easily than is currently possible with the "scribunto-console" API action. — Mr. Stradivarius ♪ talk ♪ 14:10, 22 September 2016 (UTC)
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 =>
This new lua code would be properly working with airports https://www.wikidata.org/wiki/Q17430 or https://www.wikidata.org/wiki/Q642313
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)
-- Snaevar ( talk) 15:18, 28 August 2016 (UTC)
-- Bouzinac ( talk) 22:20, 29 August 2016 (UTC)
Is there a way to encode URLs not in UTF-8, but in an older method, like the function de:Wikipedia:Lua/Modul/WLink/en#ansiPercent is doing? If no, can this maybe be imported here? It is needed for Template:Album chart and Template:Single chart, see Template talk:Album chart#Agnetha_Fältskog_name_problem. -- Ali1610 ( talk) 19:22, 22 October 2016 (UTC)
Hello, Is there any means of getting the screenname of the user looking at the page the module is on? I can't find anything about this in the manual, and it seems like an obvious function that should be part of the language. BigGreenCahuna ( talk) 02:06, 27 October 2016 (UTC)
Hi everybody! Google Code-in (GCI) will soon take place again - a seven week long contest for 13-17 year old students to contribute to free software projects. Tasks should take an experienced contributed about two or three hours and can be of the categories Code, Documentation/Training, Outreach/Research, Quality Assurance, and User Interface/Design. Do you have any Lua / template related idea for a task (needs documentation, or some code / code changes) and can imagine enjoying mentoring such a task to help a new contributor? If yes, please check out mw:Google Code-in 2016 and become a mentor! Thanks in advance! -- AKlapper (WMF) ( talk) 14:38, 8 November 2016 (UTC)
{{
Routemap}} seems to be loading rather slowly (especially when there are collapsible sections and/or multiple Routemaps on the same page). This (coupled with the slowness of {{
Rail-interchange}}) is causing occasional problems with page size; see
Talk:List of New York City Subway terminals. Is there any way to make
Module:Routemap (specifically up until row 836) work faster? (Some of its newer bits were written by me; this is likely to be a cause because I learned Lua primarily from editing this module.) —
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:17, 13 November 2016 (UTC)
string.gsub
have been replaced with mw.ustring.gsub
and the couple of cases I looked at show that the change was not needed. The latter is much slower than the former, although I do not know whether the code using gsub is called often enough to make a difference. For speed, I would be looking at considering an example input and trying to work out what the code does in general terms. Ideally there would be a profiling tool to show which functions it spends the most time in—as there isn't, it needs someone who understands the code to try and guess which functions might be involved. I have seen some poorly designed modules which loop to locate needed information, but this module is too complex for me to quickly see what is going on. Do you know of places in the module which need to loop to process one item? Re string.gsub
: I could explain, but a simpler step would be to copy the module into a sandbox and change all the ustring stuff back to plain gsub. Don't worry if it breaks something (some of them might be needed). The question is, does it show a significant difference in the wgPageParseReport in the html source of a page using the module.
Johnuniq (
talk)
09:29, 13 November 2016 (UTC)
mw.ustring.gsub(overlapProps[i].abbr, '"', '"')
string.gsub(overlapProps[i].abbr, '"', '"')
regardless of what text is being processed. It works because MediaWiki uses
UTF-8 to encode text. For another example, it is also fine to do stuff like string.gsub(text, '-', '–')
(changes hyphen to Unicode en dash) or string.gsub(text, '−', '-')
(changes Unicode minus to hyphen). You need mw.ustring when the regex needs to treat alternatives as characters, say if the pattern is [aä]
which wants to search for a
or ä
. Lua regards the latter as two bytes (the UTF-8 encoding of ä), and string.gsub would search for any of the three bytes (one for a and two for ä). I have not done any testing, but I have a vague idea of what mw.ustring has to do, and it would be much slower, although that would only matter if gsub is executed many times in a loop.
Johnuniq (
talk)
01:16, 15 November 2016 (UTC)
Hello. I need help for Module. el:Module:Περισσότερεςκατακτήσεις (is in English).
See Cypriot First Division (Q155965), property 1346, qualifier P1355. I want to show the item of P1346 if it has the largest qualifier P1355. Xaris333 ( talk) 23:59, 26 November 2016 (UTC)
Hi all. :-) Special:Search/cat s and dog in curly braces does not transclude the list of search results. Does Lua have access to search results lists? (I recall that it does not have API access, but apart from that, I have difficulty finding what relevant access or objects it does have.) -- Gryllida 01:45, 9 December 2016 (UTC)
?withJS=
, though. You can simply create a default-on JavaScript gadget that only runs when you are viewing that page. —
Mr. Stradivarius
♪ talk ♪
05:10, 9 December 2016 (UTC)An editor has nominated Module:PropertyLink for deletion. Input from those familiar with modules is welcome at Wikipedia:Miscellany for deletion/Module:PropertyLink. Thanks, — Godsy ( TALK CONT) 09:11, 20 December 2016 (UTC)
Is it possible to retrieve the date & time of a user's most recent edit? This would be found at Special:Contributions/USERNAME .. or the data returned by API:Usercontribs -- Green C 17:42, 23 December 2016 (UTC)
For example:
local tab = mw.html.create('table')
tab
:addClass('wikitable')
:tag('caption'):wikitext('something '):wikitext('and something')
:tag('tr'):tag('td'):wikitext('a')
:tag('tr'):tag('td'):wikitext('b')
return tab
Why it knows that I want to get:
<table class="wikitable">
<caption>something and something</caption>
<tr><td>a</td></tr>
<tr><td>b</td></tr>
</table>
rather than:
<table class="wikitable">
<caption>something and something
<tr><td>a
<tr><td>b</td></tr>
</td></tr>
</caption>
</table>
Where the :tag('caption')
is closed?--
A Sword in the Wind (
talk |
changes)
06:01, 15 October 2016 (UTC)
<table class="wikitable"><caption>something and something<tr><td>a<tr><td>b</td></tr></td></tr></caption></table>
<table class="wikitable">
<caption>something and something
<tr>
<td>a
<tr>
<td>b</td>
</tr>
</td>
</tr>
</caption>
</table>
local tab = mw.html.create('table')
tab:addClass('wikitable')
tab:tag('caption'):wikitext('something '):wikitext('and something')
tab:tag('tr'):tag('td'):wikitext('a')
tab:tag('tr'):tag('td'):wikitext('b')
<table class="wikitable"><caption>something and something</caption><tr><td>a</td></tr><tr><td>b</td></tr></table>
local tab = mw.html.create('table')
tab:addClass('wikitable')
local caption = tab:tag('caption')
caption:wikitext('something ')
caption:wikitext('and something')
local tr1 = tab:tag('tr')
local td1 = tr1:tag('td')
td1:wikitext('a')
local tr2 = tab:tag('tr')
local td2 = tr2:tag('td')
td2:wikitext('b')
<table>
node inside another table's <td>
node, then that's your job done. The part that usually confuses people is that every time you call :tag()
mw.html returns a new node. This can have unexpected results if you don't know how it works. For example:-- Example 1
local t1 = mw.html.create('table')
t1:tag('tr'):tag('td'):wikitext('foo') -- t1 points to the "table" node because we defined it on the line above.
mw.log(tostring(t1)) -- Logs "<table><tr><td>foo</td></tr></table>"
-- Example 2
local t2 = mw.html.create('table'):tag('tr'):tag('td'):wikitext('foo') -- t2 points to the "td" node, as that is the return value of the expression
mw.log(tostring(t2)) -- Logs "<td>foo</td>"
foo:bar():baz()
) the expressions are expanded from left to right. I find it easiest to visualise what's happening if I add more parentheses, like this: ( foo:bar() ):baz()
. In effect, we are hoping that foo:bar()
returns an object that has a "baz" method, and then attempting to call that method. Because of this, the overall return value of an expression with chained methods is the return value of the right-most method. Let me break down my example above.mw.html.create('table') -- Returns a table node
:tag('tr') -- Calls the table node's "tag" method, and returns a new "tr" node
:tag('td') -- Calls the "tr" node's "tag" method, and returns a new "td" node
:wikitext('foo') -- Calls the "td" node's "wikitext" method, and returns the "td" node
local root = mw.html.create('table')
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row.')
:done()
:tag('td')
:wikitext('The second cell of the first row.')
:done()
:done()
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row.')
:done()
:tag('td')
:wikitext('The second cell of the second row. This cell has a nested table in it.')
:tag('table')
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row of the nested table.')
:done()
:done()
:done()
:done()
:done()
:done()
:done()
calls if you make sure that root always refers to the original table element:local root = mw.html.create('table')
root
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row.')
:done()
:tag('td')
:wikitext('The second cell of the first row.')
:done()
:done()
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row.')
:done()
:tag('td')
:wikitext('The second cell of the second row. This cell has a nested table in it.')
:tag('table')
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row of the nested table.')
-- Make the root table and store a reference to it in the rootTable variable
local rootTable = mw.html.create('table')
-- Add a row to the root table
rootTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row.')
:done()
:tag('td')
:wikitext('The second cell of the first row.')
-- Add a second row to the root table, and make a reference to the nested table's "table" node
local nestedTable = rootTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row.')
:done()
:tag('td')
:wikitext('The second cell of the second row. This cell has a nested table in it.')
:tag('table')
-- Add a row to the nested table.
nestedTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row of the nested table.')
-- Add a third row to the root table
rootTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the third row.')
:done()
:tag('td')
:wikitext('The second cell of the third row.')
-- Add another row to the nested table
nestedTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row of the nested table.')
I saw User talk:Peter coxhead#Testcases page in mainspace and tried to move it to Module space. However, when I tried I got "Non-Module pages cannot be moved to the Module namespace (except for /doc pages), and Module pages (except for /doc pages) cannot be moved out of the Module namespace." and it deletes the target page without letting you know what it has done. How do you move stuff over. I figure you could move it to a Module:something/doc and then to the correct title but I've done enough screwing around for now. CambridgeBayWeather, Uqaqtuq (talk), Sunasuttuq 03:43, 30 December 2016 (UTC)
I've tested templates in my user space, by using {{User:TJRC/Sandbox/TemplateName}}
. It looks like you can't do that with modules, i.e., with something like
{{#invoke:User:TJRC/Sandbox/Modulename|func}}
. Is this correct? I just want to check before I create something in
Special:PrefixIndex/Module:Sandbox.
TJRC (
talk)
01:11, 7 January 2017 (UTC)
<pre>
block is returned by a module, but I should have used a more generic name because I have used it for lots of small tests, mostly without saving anything. I write some code to test a point I'm working on, edit that page but don't bother saving. Instead, under "Preview page with this module" enter "Module talk:Sandbox/Johnuniq/testpre" for the Page title and click "Show preview". Of course if you are building a larger module you can save and muck around, but the the preview feature is very handy.
Johnuniq (
talk)
01:41, 7 January 2017 (UTC)
Hi, I am wondering how I can test a module like module:labels that contains functions that doesn't take parameters but rather fetches the parameters from the parent scope - in this case a template instantiation. Can I use Module:UnitTests for this? Moberg ( talk) 20:11, 21 February 2017 (UTC)
Hey,
I was wondering if there is a way to find how many lines does a text contain.
for example:
a b c
would give 3
Thanks--
Mikey641 (
talk)
12:00, 22 February 2017 (UTC)
local function countLines(s)
local _, count = s:gsub('\n', '%0') -- Count newline characters in s
return count + 1
end
{{#invoke:מונה הופעות|countlines|text goes here}}
or {{#invoke:מונה הופעות|countlines|text=text goes here}}
. Best —
Mr. Stradivarius
♪ talk ♪
23:27, 22 February 2017 (UTC)Hi, in itwiki we were wondering if the expansion of a module is cached by the MediaWiki parser or not. Let's say page A includes ten times {{#invoke:B|main}}. Is the main function in module:B executed once or ten times? I would say "ten times", but I don't know parser internals. The module could contain randomly generated content or os.time(), so the parser can't cache it, or is it able to be aware of these functions? -- Rotpunkt ( talk) 16:11, 25 February 2017 (UTC)
local count = 10
and functions then use and change count
. However, count
is always 10 when the module starts—nothing is shared between the separate calls to module B. The good news is that it is astonishingly fast.
Module:Convert is breathtakingly enormous and complex yet well over 1000 {{
convert}} calls can be executed on a single page.mw.loadData
instead of require
.
Johnuniq (
talk)
00:43, 26 February 2017 (UTC)
mw.loadData( module )
does not support functions, a module that does not use global variables actually it is not recognized as "
functional", calling it only 1 time in the whole page. I'm right? --
Valerio Bozzolan (
talk)
04:01, 26 February 2017 (UTC)
{{example|one|two}}
would give exactly the same result regardless of anything else on the page—it does not matter if the template being rendered is the first occurrence on the page or the tenth. MediaWiki is like that because the designers want section editing to work (say for preview) without having to process the whole page.
Johnuniq (
talk)
06:55, 26 February 2017 (UTC)mw.loadData
does all steps only once and relies on the read-only wrapping to prevent one invoke from affecting the next.
Anomie
⚔
15:26, 26 February 2017 (UTC)
It was pointed out at
Template talk:when#Breaks inside Infobox settlement that if you try to pass various inline cleanup templates through infoboxes which apply {{formatnum: }}
that the year in the tracking category is mangled (comma inserted). would it be a good idea to create a smart formatnum which excludes the categories, and say references, from the formatnum transformation? or, does this already exist? thank you.
Frietjes (
talk)
22:14, 27 February 2017 (UTC)
A trivial change (I suspect) is needed to a Lua module; please see Template talk:Article history#maindate2. Any takers? - Dank ( push to talk) 03:14, 28 February 2017 (UTC)
Hi,
I'm not sure if it's the right place to ask about this: is there any way to extract say the country property (P17) from the item linked to the headquarters location property (P159) of an item? For example, the headquarters location property of Nordea is Stockholm ; if we then look for the country property of Stockholm, we'll get Sweden. So if could get the country that way, we wouldn't need to set a country qualifier for the headquarters location property of Nordea, is there any way to do that? The RedBurn ( ϕ) 21:40, 1 March 2017 (UTC)
{{#invoke:RexxS|getValueIndirect|P159|P17}}
→ Finland|qid=
for testing the call outside of the current article). The value of
headquarters location (P159) in
Nordea (Q1123823) is
Stockholm (Q1754); and the value of
country (P17) for
Stockholm (Q1754) is
Sweden (Q34). I'm just taking the first value of each property, assuming they are single-valued. You'd have to specify how you'd want to handle the situation if either were multi-valued.Hi everyone! I'm trying to create an option in Module:Wd that adds references from Wikidata to claims from Wikidata. However, simply outputting a reference between the tags <ref>...</ref> from a module keeps these tags as plain text; they are not processed by Wikipedia. This differs from templates, where such output is actually processed and converted into a real reference.
Is there any way to add references from a module? Or am I condemned to using templates for this?
Thanks, thayts 💬 13:10, 9 December 2016 (UTC)
f.sfn()
.buildCite
(which can probably be changed to include
Module:Citation/CS1 directly via require()
). That said, is there a reason you aren't e.g. working in
Module:Wikidata/sandbox? We don't really need two general purpose Wikidata modules. --
Izno (
talk)
13:44, 9 December 2016 (UTC)frame:preprocess('<ref name="foo">bar</ref>')
, but it is more efficient if you do it with frame:extensionTag{name = 'ref', content = 'bar', args = {name = 'foo'}}
, as it avoids the overhead of the parser having to parse the HTML tags and preprocess whatever content you put inside them. —
Mr. Stradivarius
♪ talk ♪
01:10, 10 December 2016 (UTC)
|nowikidata=true/false
when I call the module"? If you don't like using a special parameter value in the way that
Module:Wikidata does, you have a perfectly good alternative in
Module:WikidataIB that also addresses the "opt-in" vs "opt-out" issues. --
RexxS (
talk)
21:37, 4 March 2017 (UTC)
{{#invoke:wikidata|{{{country|FETCH_WIKIDATA}}}}}
I would do something like {{{country|{{#invoke:wd}}}}}
and so there is no real difference (except that the latter doesn't do a superfluous call to a module).
thayts
💬
22:45, 4 March 2017 (UTC)I am working on a location map wrapper in Module:Australian place map for use in Template:Infobox Australian place. I have implemented the module in the sandbox, and now in Template:Infobox Australian place/testcases I am seeing something strange. in particular, in the "Nyabing" I am currently seeing two pin markers, and in one of the "Woy Woy" examples, I am seeing zero pin markers. basically, it looks like the pin from the first "Woy Woy" has migrated up the page to the "Nyabing". my guess is that this is some quirk with using the {{ Testcase table}} template and/or something odd going on in Module:Location map? on a related note, I imagine it would probably be better if I could call the main function in Module:Location map directly instead of going through expandTemplate? I am hoping Jackmcbarn or one of the other LUA experts can help. thank you. Frietjes ( talk) 16:41, 4 March 2017 (UTC)
latd = -33.49
and that puts the pin a long way off the map.latd
. However,
Module:Australian place map applies abs to the longitude rather than the latitude. Some mucking around makes me think you probably want abs(longitude) to avoid an ugly error message if a negative longitude is entered. However, the module needs the same for latitude, and that is why the pin is in the wrong place with the negative latitude.
Johnuniq (
talk)
09:38, 5 March 2017 (UTC)
I'm reuploading a lot of images using
Commonist, which unfortunately overwrites file description pages. Is there a way to find text currently in the page (for example, the original uploader's username in the file information template) by transcluding the page, or does that not work because of Lua being parsed at the wrong time?
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
10:34, 5 March 2017 (UTC)
mw.title.getCurrentTitle():getContent()
. You can also expand any templates etc. in that wikitext by using
frame:preprocess. Whether you can manage to get useful information from either or both of those steps is another matter, however. —
Mr. Stradivarius
♪ talk ♪
23:37, 5 March 2017 (UTC)
Hey
I need help creating a module that will order 2 words alphabeticaly.
I did it in wiki code so I will explain how I did it, if you have better sugestions please offer:
Tagging User:Mr. Stradivarius who has helped me here before-- Mikey641 ( talk) 21:47, 7 March 2017 (UTC)
i = 1
.mw.ustring.char(mw.ustring.codepoint(s, i, i))
).So, we are using a system in hewiki to "verify" template parameters. i will be happy to explain about the system, but my question here is a bot different:
it turns out that this system adds significant load to some template parsing, and this cases a small number of pages to violate some limits of the parser, and these pages then are not parsed correctly.
the only remedy we found so far is to completely (i.e., globally) disable this system - if we do that, the pages are parsed ok.
what we are looking for, is a way to gate specific lua functions, based on the some attribute of the page, something similar to {{ Nobots}}, for lua modules.
it is perfectly kosher to use something like categories (naturally, it will be a hidden one), i.e., i will be happy to define a new hidden category, say "No template parameters validation", and add those pages to the category. however, i could not find a way to ask in lua "does this page belong to category X", or "give me the list of categories this page belongs to". i cannot think of something other than category that will do the job, but i am willing to learn any new tricks.
note that the #invoke call is not in the page itself, but rather pretty deep in some templates (many may not even be transcluded directly, but through other templates, going 2, 3 and even 4 levels deep).
any help and advice will be appreciated. peace - קיפודנחש (aka kipod) ( talk) 16:04, 12 March 2017 (UTC)
mw.title.getCurrentTitle():getContent():find('__NOPARAMETERVALIDATION__')
. The second is to have a blacklist module with e.g. return {['Page name 1' = true, 'Page name 2' = true}
which you check before doing the validation. I'd be quite interested in hearing about the system you are using, though - what kind of parameter verification are you doing that's creating so much load? —
Mr. Stradivarius
♪ talk ♪
23:39, 12 March 2017 (UTC)
local verbotten = {
'page name 1' = '',
'page name 2' = '',
-- ..... etc. etc. etc.
}
function envelope( frame )
local pageName = mw.title.getCurrentTitle().text
-- exploiting the fact that unline JS, in lua '' is actually true
return verbottenpageName or require( 'actualModule' ).actualFunction( frame )
end
mw.templateData.getTemplateData( templatename )
, which is open for ~ 2 years now. "they" actually put "priorily:lowest" on it (see
phab:T107119, so we call getContent() on the template page,, distill the stuff enclosed inside the "templatedata" tag, and call "jsonDecode()" on it. after that, the rest is trivial. you may want to look in
he:Module:ParamValidator - i tried to document it as much as possible. the system is working, and exposed thousands (literally) of errors in templates.There was some discussion at TfD about
Template:Infobox map. basically, all that
Template:Infobox map does right now is (1) check to see if the map exists, and then (2) call either
Template:Location map or
Module:InfoboxImage. this is somewhat inefficient since there is already an ifexists check in the getMapParams
function in
Module:Location map. so, my thought is that we could change the code of {{
infobox map}} to something like
{{location map|{{{map}}} | relief = {{{relief|}}} | overlay_image = {{{overlay|}}} [...] | nomap_message = {{#invoke:InfoboxImage | InfoboxImage | image={{{map}}} | size={{{map_width|}}} | maxsize={{{max_width|}}} | sizedefault={{if empty|{{{default_width|}}}|220px}} | alt={{{map_alt|}}} | title={{{map_caption|}}} }}{{#if:{{{map_caption|}}}|<div>{{{map_caption|}}}</div>}} }}
so, that instead of returning the error message on line 50 of
Module:Location map it would return the value of |nomap_message=
if |nomap_message=
is not nil. does this seem like a good idea? if so, it would be helpful if someone could implement this |nomap_message=
in
Module:Location map/sandbox for testing. I would do it, but I am not sure the best way to pass this through to the getMapParams
function and the best way to catch it when it comes out of the getMapParams
function. probably need a second return flag with 0 for no error, and 1 for error or something like that? thank you.
Frietjes (
talk)
16:35, 16 March 2017 (UTC)
An editor has asked for a discussion regarding Module:Navbox with nowrap lists. Input from those familiar with modules is welcome at Wikipedia:Miscellany for deletion/Module:Navbox with nowrap lists. Thanks, — Godsy ( TALK CONT) 09:11, 20 December 2016 (UTC)
How can I modify
Module:Tone superscript so that it only adds superscript tags to numbers not part of HTML entities (or filenames/links/anything which breaks when <sup>
tags are added)? The module was originally written by someone else but I'm trying to repurpose it so it works in {{
Infobox Chinese}}.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
09:15, 24 March 2017 (UTC)
+
):
x = arg:gsub("(%d+)", "<sup>%1</sup>")
+
, which isn't really a problem since there are fewer than 10 tones in most tonal languages. The module could have the entities changed to characters to avoid inserting <sup>
tags in them, although there could be a better solution.
Jc86035 (
talk) Use {{
re|Jc86035}}| j3 = {{Jpingauto|Can4 Gong2 Sang1}}
–
or –
, and might have a link which should not be damaged, I could fix the module.
Johnuniq (
talk)
06:25, 25 March 2017 (UTC)
<sup>...</sup>
to a digit only if it's preceded by letters? –
Uanfala (talk)
08:40, 25 March 2017 (UTC)
Hello folks, is there any chance putting a function inside this module, which will give me the opportunity to add languages with {{#invoke:Languages|getCode|language code}}? -- Vēnī‧vīdī‧scrīpsī [DM] 18:03, 27 March 2017 (UTC)
{{#invoke:Wt/cu/PartOfSpeech|get_wiki|de}}
get_wiki()
. You aren't getting the language code argument from the arguments table passed into the function from wiki text; instead, you are getting the arguments table and passing that to mw.text.trim()
which is expecting a string, not an arguments table. See
mw:Extension:Scribunto/Lua_reference_manual#Accessing parameters from wikitext for a more detailed description of how arguments work.get_wiki()
with {{#invoke:Wt/cu/PartOfSpeech|get_wiki|de}}
I'm looking for a script that will look at a range of values, display the most recent three (or any other number to be defined) and then show the rest of the values in a collapsed list. The example I am looking at is {{ Infobox GB station}} and the usage statistics. These figures exist going back to 2002/3 (and a parallel set of interchange figures as well) so including them all gives a very long list. Ideally a script would look at the list, find the most recent three recorded, which are not necessarily the most up-to-date three, display those and then show the rest in a collapsed table. I know there are issues about the template needing an update to show the most recent figures first but if the base data was most recent first like {{ UK railway station usage}} is this something that can be done? Nthep ( talk) 13:12, 12 April 2017 (UTC)
@
Nthep: The
Wikidata property for patronage/ridership has been created, so I assume the data can now be imported into there using QuickStatements. I'm not sure how to use a qualifier for interchange traffic although has role (
P2868) → interchange station (
Q1147171) might work.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:14, 19 April 2017 (UTC)
Hello. I am a user in Greek Wikipedia.
1) w:el:Module:Επίσημηονομασίασεξένηγλώσσα These shows the P1448 property if the language is not Greek. But is showing only the first language. If there are shows of them, only shows the first one.
2) I want, near the result, to have language code. For example, "London ( en)". The code must be link to wikidata item of the language if there is not an article to Greek Wikipedia. If there is an article of the language to Greek Wikipedia, to show link to that article. If it is too difficult is ok only to show the code. Maybe can link to w:el:ISO 639-1.
If the module works, then you must see the phrase "Επίσημη ονομασία: London ( en)" or "Επίσημη ονομασία: London (en)" under the blue box [2].
Xaris333 ( talk) 14:47, 18 April 2017 (UTC)
Επίσημη ονομασία: London ([[English language|en]])
language = "en"
and text = "London"
. How would "English language" be derived from "en"?
Xaris333 ( talk) 13:24, 19 April 2017 (UTC)
We just rolled out on Commons c:Module:Creator that mimics c:Template:Creator but can also fetch any field from Wikidata if needed. The issue I have is with few creator templates like c:Creator:Tomás Povedano that end up in Category:Pages with script errors. At this moment c:Creator:Tomás Povedano only shows "The ID entered is unknown to the system. Please use a valid entity ID." error, but the message like that disappeared from other pages without any edits. c:Creator:Tomás Povedano links to d:Q19675193 which is correct "entity ID". Any idea on how to debug this issue or what might cause it. phabricator:T143970 deals with this error but in context of how to detect bad "entity IDs" aka q-codes. -- Jarekt ( talk) 17:46, 23 April 2017 (UTC)
Hi. Is there a way to include a submodule that is relative to the current module like require("Module:SomeName/sub")
where SomeName
is not fixed? I.e. is there a way to include /sub
without the need to define Module:SomeName
or is there a way to dynamically determine the current module's title Module:SomeName
?
thayts
💬
21:33, 4 May 2017 (UTC)
function module_name.main(frame)
local some_data = mw.loadData (frame:getTitle() .. '/sub');
frame:getTitle()
before, but that does not necessarily return the title of the calling module itself. For example, if the module is invoked in the examples section of its documentation then the returned value is actually Module:Documentation
.
thayts
💬
06:56, 5 May 2017 (UTC)
frame:getTitle()
is the best thing we have, as far as I'm aware. —
Mr. Stradivarius
♪ talk ♪
14:34, 5 May 2017 (UTC)
frame:getTitle()
is called. If inside a function that received the frame object, then the current module's title seems to be returned. If outside a function call, like where require()
is typically called, then it depends (also, I was using mw.getCurrentFrame():getTitle()
there). I think I will have a look at mw.loadData()
. Thank you both!
thayts
💬
17:49, 5 May 2017 (UTC)And what if the module that is including the submodule is actually included through require()
itself? I.e. require("Module:SomeName")
, how does Module:SomeName
know it was included by that name? There is no frame involved here and mw.getCurrentFrame():getTitle()
certainly does not return Module:SomeName
, so how could it construct Module:SomeName/sub
?
thayts
💬
10:34, 6 May 2017 (UTC)
...
passed to the module.
thayts
💬
18:21, 6 May 2017 (UTC)It's a FAQ, could not find the answer. Q: Can I make nested calls to an #invoking template?
{{OuterTemplate |title=Bar |{{InnerTemplate|a|A}} |{{InnerTemplate|b|B}} }}
(And does the answer apply for both template calls and direct #invoke|main calls?) - DePiep ( talk) 11:15, 11 May 2017 (UTC)
{{#invoke:String|match|s=123{{snd}}456 |pattern=%d*(.*) |plain=false |nomatch=nomatch_output }}
{{snd}}
was called before the {{#invoke:}}
. Which is to be expected.
Module:Navbar appears to contain :newline();
for no reason (after each of the square brackets in "[ v · t · e ]"), which might be causing a detected syntax error
on the German Wikivoyage (discussion in English). Are they necessary and should they be replaced with spaces? (Pinging
DerFussi.)
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
16:05, 10 May 2017 (UTC)
Is it possible to use
Module:Unsubst on infoboxes so that the parameters and their equals signs have correct indentation and are in the correct order, and parameter aliases are replaced with their canonical values on substitution? (This would be done for {{
Infobox song}}, {{
Infobox single}} and their auxiliary templates like {{
Extra chronology}}.)
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:26, 13 May 2017 (UTC)
I've tried setting up {{
Infobox song/sandbox}} with the new module, but the alias handling |$A=
isn't working for some reason. Could anyone help with this? Thanks,
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
05:49, 14 May 2017 (UTC)
(to test, take a random template from
Template:Infobox song/doc, change the template title to subst:Infobox song/sandbox
, and press the "show changes" button
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
05:54, 14 May 2017 (UTC))
Could someone help me with
Module:Unsubst-infobox, which I'm trying to fork from
Module:Unsubst? I'm trying to get some of the new parameters in it to work but for some reason the input data gets lost somewhere. Maybe I'm using mw.text.split wrong.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
14:42, 15 May 2017 (UTC)
{{subst:Infobox song/sandbox | Name = Song }}
{{Infobox song/sandbox | name = Song | type = | writer = | composer = | lyricist = | written = | published = | misc = }}
{{Infobox song/sandbox | name = | cover = | cover_size = | alt = | border = | caption = | type = | artist = | album = | EP = | language = | English_title = | writer = | composer = | lyricist = | written = | published = | genre = | recorded = | studio = | venue = | length = | producer = | released = | label = | format = | A-side = | B-side = | ISWC = | chronology = | prev_title = | prev_year = | next_title = | next_year = | prev = | prev_no = | next = | next_no = | tracks = | misc = }}
|$S3=
) is supposed to replace the full list, and the value of parameter |Name=
should be transferred to parameter |name=
(lowercase) as defined in |$A=
.
Jc86035 (
talk) Use {{
re|Jc86035}}if
that tests mw.isSubsting:
error('mw.isSubsting is true')
aliases[tmp[1]] = aliases[tmp[2]]
correct? The RHS should be tmp[2]
.tmp[2]
works for some of the aliases but not all of them (e.g. try showing changes for substituting the infobox of
Waltzing Matilda, with title changed to "subst:Infobox song/sandbox").
Jc86035 (
talk) Use {{
re|Jc86035}}@ Jc86035: I fixed two problems in Module:Unsubst-infobox:
-- Changed for k, v in ipairs( {frame.args['$S1'], frame.args['$S2'], frame.args['$S3']} ) do -- to for k = 1, 3 do local v = frame.args['$S' .. k] -- Changed if v ~= {} then -- to if next(v) then -- if table v is not empty
In the first, ipairs stops at the first nil
, so if there is no $S1
parameter, the original code would not test the other two parameters.
In the second, two different tables are never equal. Consider the following code:
t = {} if t == {} then print('1: EMPTY') else print('1: NOT empty') end if next(t) then print('2: NOT empty') else print('2: EMPTY') end
If run on a computer with Lua, the above would print:
1: NOT empty 2: EMPTY
There may be other issues, but that's all I have time for at the moment. If there is still a problem, please provide an example using $S1
(add it
here if wanted) and outline what shows that it is wrong, and what the correct result would be.
Johnuniq (
talk)
10:38, 18 May 2017 (UTC)
$S1
or $S3
. I'm not sure why. {{
Audio sample}}, which also uses the module (but with only $P
and $E
) works fine.
Jc86035 (
talk) Use {{
re|Jc86035}}ipairs( sets )
which should be pairs
because each item in the set is of the form 'example' = true
so ipairs
will get nothing. I'm hopelessly confused about $P
and $S
and more so I'm not going to fix it at the moment. However, I might look at working out what should be done if you don't fix it first.
Johnuniq (
talk)
00:41, 20 May 2017 (UTC)
sets
is a table containing three other tables, so ipairs should work for it. Maybe it's better to just scrap the thing and use parser functions to add parameters to $E instead.
Jc86035 (
talk) Use {{
re|Jc86035}}ipairs(sets)
, it is ipairs(params)
in line 147. Bear in mind that I still do not understand the parameters or what is going on, but at line 147 params might be a numbered table (in which case ipairs would work as expected), but it might be a set. That would occur if the code at line 129 executed params = v
which would replace params with sets[1] (for the case where $S1 has a relevant value).
Johnuniq (
talk)
06:42, 20 May 2017 (UTC)@
Johnuniq: So params = v
was the problem. It should be fixed now.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:52, 20 May 2017 (UTC)
![]() | This page 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 talk page. |
Following up on Wikipedia:Village_pump_(technical)#51.171.156.10, 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)
@ Mr. Stradivarius: I put some preliminary thoughts at Module talk:IP. Johnuniq ( talk) 11:10, 14 July 2016 (UTC)
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? /info/en/?search=User:Julialturner/RELN 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)
<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)
invoke
d, 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)
frame:expandTemplate
, not frame:extendTemplate
. —
Mr. Stradivarius
♪ talk ♪
23:17, 13 July 2016 (UTC)
Hey.
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:
hello
world
what's
up
will give you
hello
Thanks in advance--
Mikey641 (
talk)
15:51, 22 July 2016 (UTC)
{{#invoke:String|match|hello world what's up |^%s*.- |||}}→
hello
Paweł Ziemian (
talk)
18:46, 22 July 2016 (UTC)
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)
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)
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)frame.args
parameters from the template invoking the moduleframe:getParent().args
parameters from the page using the templateframe: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)
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)
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)
frame:preprocess
?{{Artwork|permission = {{PD-art}} }}
.Not sure where else to put this. I turned Template:ColPollTable into a module ( small test here). But it's weird because this is set to replace 20 independent templates. What bugs me though is whether or not the template is necessary. It seems to be used on only a few pages, which makes me wonder if its functionality might be covered by a superior template. If that's not the case and the template serves a unique function, then I'm not sure exactly how I should proceed to update the templates and their calls. mol uɐɯ 13:35, 30 August 2016 (UTC)
In
Module:Routemap/sandbox, I'd like to use the option removeBlanks = false
for the p._BSrow function, but only that function. Is it necessary to make another module for this?
Jc86035 (
talk •
contribs) Use {{
re|Jc86035}} to reply to me
12:25, 1 September 2016 (UTC)
|removeBlanks=false
to not remove blanks, or might omit that parameter to include them. And the template would invoke function BSrow
in the module. I don't see a problem and don't see why another module might be needed. What is the concern?positive(x)
and negative(x)
functions that would presumably be used to test args.removeBlanks
. If the wikitext omits the parameter (or equivalently, given that
Module:Arguments is used probably with defaults, omits the value), positive(args.removeBlanks)
would evaluate as false, and so would negative(args.removeBlanks)
. That's a bit awkward.
Johnuniq (
talk)
00:20, 2 September 2016 (UTC)
positive(x)
and negative(x)
functions are purely for internal use and I'm not sure why I'd use an args.removeBlanks in them.) Would having a makeInvokeFunction2 (duplicate but using removeBlanks = false) work, or is there a better solution?
Jc86035 (
talk •
contribs) Use {{
re|Jc86035}} to reply to me
07:08, 2 September 2016 (UTC)
The Wikidata implementation in {{
Coord}} (activated when |1=
and |2=
are both missing) doesn't seem to be working. On, for example,
Empire State Building, {{Coord}}
returns "40.7483°N 73.9853°WInvalid arguments have been passed to the {{#coordinates:}} function". Coordinates seem to be fine (other than that the coordinates were originally imported to Wikidata with 1⁄1000th of an arcsecond's accuracy), but it still returns the error. Does anyone have any idea why? Thanks,
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
13:22, 7 September 2016 (UTC)
{{#coordinates:...}}
? I don't understand what the bits and pieces are supposed to do, but it looks like #coordinates will output that error message unless it is fed valid data, and putting "{{Coord}}
" on a page would not feed it anything valid that I can see.
Johnuniq (
talk)
02:26, 8 September 2016 (UTC)
{{#invoke:Coordinates|coord}}
" at the article displays what is wanted without an error.
Johnuniq (
talk)
02:28, 8 September 2016 (UTC)
{{#property:P625|from=Q9188}}
- 40°44'54"N, 73°59'7"W if you just want standalone coordinates (with no links). --
Matroc (
talk)
03:15, 8 September 2016 (UTC)
{{#coordinates:}}
part to be put into the module as well, since otherwise the Wikidata implementation is a bit broken? There's
Module:WikidataCoord, but it doesn't have a template wrapper and is only used on a few pages.)
Jc86035 (
talk) Use {{
re|Jc86035}}{{#coordinates:}}
(and using it through the module), or is there a better solution?
Jc86035 (
talk) Use {{
re|Jc86035}} -- https://bugzilla.wikimedia.org/show_bug.cgi?id=50863 RESOLVED
return mw.getCurrentFrame():callParserFunction("#coordinates", params) or ""
where params is a table with parameters as described in mw:Extension:GeoData. Paweł Ziemian ( talk) 20:30, 8 September 2016 (UTC)
<maplink zoom="13" longitude="-73.985656" latitude="40.748433" />
40°44′54″N 73°59′8″W or <maplink zoom="13" text="Click Me!" longitude="-73.985656" latitude="40.748433" />
Click Me! - The decimal coordinates can be found by querying Wikidata. -- It all depends on what you are trying to do and what can be done with available tools/templates/modules etc.|latd=
, |latm=
, |longd=
etc. parameters in several hundred thousand infoboxes to just |coordinates=
) and this could have quite some changes in how the replacement's being carried out. (Side note: what do the Geohack parameters in {{#coordinates:}}
actually do?)
Jc86035 (
talk) Use {{
re|Jc86035}}Commons is a project where we spend a lot of effort on presenting everything in the language of the person viewing the page. That was traditionally done by layers and layers of very large and complicated templates, some of which become so complicated as to become unmanageable. Over the last several years we were working on transitioning some of them to Lua, which is a great improvement. Recently me and others were working on transition of c:Template:Creator and c:template:Artwork to c:Module:Creator and c:Module:Artwork and we are running into a problem of Expansion depth. Template version of the templates do not trigger it, but Lua versions do. See for example c:Module talk:Creator/testcases. The issue seems to be that if a template written in Lua is processing output of another template written in Lua than that triggers Expansion depth error. I reported some earlier case in phabricator:T133918, it seems like it will be a blocking issue before c:Module:Creator can be used. Do anybody have experience with working with that limit or understands logic of how Lua triggers Expansion depth. -- Jarekt ( talk) 13:18, 17 September 2016 (UTC)
p.creator
function, line 262) you seem to be using both Args
and args
; is this intended? I'm not sure where the expansion depth error is in the page.
Jc86035 (
talk) Use {{
re|Jc86035}}return {
creator = function (frame)
return frame.args.Workloc
end
}
#8 PPTemplateFrame_Hash->getArguments() called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:782] #9 Scribunto_LuaEngine->preprocess(current, {{int:lang}}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaSandbox/Engine.php:407] #10 Scribunto_LuaSandboxCallback->__call(preprocess, Array) #11 LuaSandboxFunction->call(Object of class LuaSandboxFunction could not be converted to string, getLabel) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaSandbox/Engine.php:319] #12 Scribunto_LuaSandboxInterpreter->callFunction(Object of class LuaSandboxFunction could not be converted to string, Object of class LuaSandboxFunction could not be converted to string, getLabel) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:245] #13 Scribunto_LuaEngine->executeModule(Object of class LuaSandboxFunction could not be converted to string, getLabel, tplframe{"entity":"<value><tplarg><title>1</title><part><name index=\"1\"/><value/></part></tplarg></value>", "lang":"<value><tplarg><title>2</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><tplarg><title>link</title><part><name index=\"1\"/><value>wikipedia</value></part></tplarg> </value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/engines/LuaCommon/LuaCommon.php:898] #14 Scribunto_LuaModule->invoke(getLabel, tplframe{"entity":"<value><tplarg><title>1</title><part><name index=\"1\"/><value/></part></tplarg></value>", "lang":"<value><tplarg><title>2</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><tplarg><title>link</title><part><name index=\"1\"/><value>wikipedia</value></part></tplarg> </value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/extensions/Scribunto/common/Hooks.php:121] #15 ScribuntoHooks::invokeHook(Object of class Parser could not be converted to string, tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}, Array) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3352] #16 Parser->callParserFunction(tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}, invoke, Array) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3076] #17 Parser->braceSubstitution(Array, tplframe{"1":"<value>Q47465</value>", "2":"<value><tplarg><title>1</title><part><name index=\"1\"/><value><template><title>int:lang</title></template></value></part></tplarg></value>", "link":"<value><template><title>#if:<tplarg><title>nolink</title><part><name index=\"1\"/><value/></part></tplarg></title><part><name index=\"1\"/><value>-</value></part><part><name index=\"2\"/><value>wikipedia</value></part></template></value>"}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016] #18 PPFrame_Hash->expand(<root><ignore><includeonly></ignore><template><title>#invoke: Wikidata </title><part><name index="1"/><value> getLabel </value></part><part><name>entity</name><equals>=</equals><value><tplarg><title>1</title><part><name index="1"/><value/></part></tplarg></value></part><part><name>lang</name><equals>=</equals><value><tplarg><title>2</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><tplarg><title>link</title><part><name index="1"/><value>wikipedia</value></part></tplarg> </value></part></template><ignore></includeonly></ignore><ignore><noinclude> {{documentation}}</noinclude></ignore></root>) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3229] #19 Parser->braceSubstitution(Array, tplframe{}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016] #20 PPFrame_Hash->expand(<root><template><title>Label</title><part><name index="1"/><value>Q47465</value></part><part><name index="2"/><value><tplarg><title>1</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><template><title>#if:<tplarg><title>nolink</title><part><name index="1"/><value/></part></tplarg></title><part><name index="1"/><value>-</value></part><part><name index="2"/><value>wikipedia</value></part></template></value></part></template><ignore><noinclude> {{Documentation|Template:GeoName/doc}} [[Category:Multilingual tags: Locations in France|{{PAGENAME}}]] [[Category:Aix-en-Provence|~{{PAGENAME}}]] [[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]] </noinclude></ignore></root>, 0) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1449] #21 PPTemplateFrame_Hash->cachedExpand(Template:Aix-en-Provence, <root><template><title>Label</title><part><name index="1"/><value>Q47465</value></part><part><name index="2"/><value><tplarg><title>1</title><part><name index="1"/><value><template><title>int:lang</title></template></value></part></tplarg></value></part><part><name>link</name><equals>=</equals><value><template><title>#if:<tplarg><title>nolink</title><part><name index="1"/><value/></part></tplarg></title><part><name index="1"/><value>-</value></part><part><name index="2"/><value>wikipedia</value></part></template></value></part></template><ignore><noinclude> {{Documentation|Template:GeoName/doc}} [[Category:Multilingual tags: Locations in France|{{PAGENAME}}]] [[Category:Aix-en-Provence|~{{PAGENAME}}]] [[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]] </noinclude></ignore></root>) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Parser.php:3226] #22 Parser->braceSubstitution(Array, frame{}) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1016] #23 PPFrame_Hash->expand(<value> <template><title>Aix-en-Provence</title></template>, <template><title>Paris</title></template>, <template><title>city</title><part><name index="1"/><value>Auvers-sur-Oise</value></part></template>, <template><title>Marseille</title></template> </value>, 4) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1529] #24 PPTemplateFrame_Hash->getNamedArgument(Workloc) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1541] #25 PPTemplateFrame_Hash->getArgument(Workloc) called at [/srv/mediawiki/php-1.28.0-wmf.18/includes/parser/Preprocessor_Hash.php:1473]
Workloc
parameter (#25-23), which expands {{
Label}} (#22-18), which invokes
c:Module:Wikidata (#17-11), which calls frame:preprocess('{{int:lang}}')
in some manner (#10-9), which needs to expand the parameters passed into the current frame (#8), which includes Workloc
so repeat until the expansion depth is exceeded. The top-level local defaultlang = mw.getCurrentFrame():preprocess("{{int:lang}}")
in
c:Module:Wikidata,
c:Module:Wikidata/Tools,
c:Module:Wikidata/FormatEntity, and so on looks particularly suspicious.
BJorsch (WMF) (
talk)
23:54, 17 September 2016 (UTC)
frame:preprocess('{{int:lang}}')
is actually usually written as mw.message.new( "lang" ):plain()
to avoid calling preprocess. frame:preprocess('{{int:lang}}')
as the language parameter should be passes from outside (you only get users language if you pass it from the outside, like
here). --
Jarekt (
talk)
02:32, 18 September 2016 (UTC)
mw.message.new( "lang" ):plain()
is not equivalent to frame:preprocess('{{int:lang}}')
. --
Jarekt (
talk)
15:42, 19 September 2016 (UTC)
Args
and args
. That part of the code was wrong, but I was focusing on the expansion depth issue. --
Jarekt (
talk)
13:52, 20 September 2016 (UTC)(Pinging
Braveheart.)
Module:Coordinates now calls the {{#coordinates:}}
parser function through mw.getCurrentFrame():callParserFunction
. This unexpectedly broke
Module:HS listed building, which calls
Module:Coordinates' coordinates.coord
function directly. Any way of fixing this?
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
14:46, 20 September 2016 (UTC)
I've just started a discussion at VPT about rolling out the new sensitive IP modules, which might be of interest to people who want to use information about sensitive IPs in other modules or templates. Another item in the proposal which might be of interest is libLua.js, a library for calling Lua functions from JavaScript more easily than is currently possible with the "scribunto-console" API action. — Mr. Stradivarius ♪ talk ♪ 14:10, 22 September 2016 (UTC)
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 =>
This new lua code would be properly working with airports https://www.wikidata.org/wiki/Q17430 or https://www.wikidata.org/wiki/Q642313
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)
-- Snaevar ( talk) 15:18, 28 August 2016 (UTC)
-- Bouzinac ( talk) 22:20, 29 August 2016 (UTC)
Is there a way to encode URLs not in UTF-8, but in an older method, like the function de:Wikipedia:Lua/Modul/WLink/en#ansiPercent is doing? If no, can this maybe be imported here? It is needed for Template:Album chart and Template:Single chart, see Template talk:Album chart#Agnetha_Fältskog_name_problem. -- Ali1610 ( talk) 19:22, 22 October 2016 (UTC)
Hello, Is there any means of getting the screenname of the user looking at the page the module is on? I can't find anything about this in the manual, and it seems like an obvious function that should be part of the language. BigGreenCahuna ( talk) 02:06, 27 October 2016 (UTC)
Hi everybody! Google Code-in (GCI) will soon take place again - a seven week long contest for 13-17 year old students to contribute to free software projects. Tasks should take an experienced contributed about two or three hours and can be of the categories Code, Documentation/Training, Outreach/Research, Quality Assurance, and User Interface/Design. Do you have any Lua / template related idea for a task (needs documentation, or some code / code changes) and can imagine enjoying mentoring such a task to help a new contributor? If yes, please check out mw:Google Code-in 2016 and become a mentor! Thanks in advance! -- AKlapper (WMF) ( talk) 14:38, 8 November 2016 (UTC)
{{
Routemap}} seems to be loading rather slowly (especially when there are collapsible sections and/or multiple Routemaps on the same page). This (coupled with the slowness of {{
Rail-interchange}}) is causing occasional problems with page size; see
Talk:List of New York City Subway terminals. Is there any way to make
Module:Routemap (specifically up until row 836) work faster? (Some of its newer bits were written by me; this is likely to be a cause because I learned Lua primarily from editing this module.) —
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:17, 13 November 2016 (UTC)
string.gsub
have been replaced with mw.ustring.gsub
and the couple of cases I looked at show that the change was not needed. The latter is much slower than the former, although I do not know whether the code using gsub is called often enough to make a difference. For speed, I would be looking at considering an example input and trying to work out what the code does in general terms. Ideally there would be a profiling tool to show which functions it spends the most time in—as there isn't, it needs someone who understands the code to try and guess which functions might be involved. I have seen some poorly designed modules which loop to locate needed information, but this module is too complex for me to quickly see what is going on. Do you know of places in the module which need to loop to process one item? Re string.gsub
: I could explain, but a simpler step would be to copy the module into a sandbox and change all the ustring stuff back to plain gsub. Don't worry if it breaks something (some of them might be needed). The question is, does it show a significant difference in the wgPageParseReport in the html source of a page using the module.
Johnuniq (
talk)
09:29, 13 November 2016 (UTC)
mw.ustring.gsub(overlapProps[i].abbr, '"', '"')
string.gsub(overlapProps[i].abbr, '"', '"')
regardless of what text is being processed. It works because MediaWiki uses
UTF-8 to encode text. For another example, it is also fine to do stuff like string.gsub(text, '-', '–')
(changes hyphen to Unicode en dash) or string.gsub(text, '−', '-')
(changes Unicode minus to hyphen). You need mw.ustring when the regex needs to treat alternatives as characters, say if the pattern is [aä]
which wants to search for a
or ä
. Lua regards the latter as two bytes (the UTF-8 encoding of ä), and string.gsub would search for any of the three bytes (one for a and two for ä). I have not done any testing, but I have a vague idea of what mw.ustring has to do, and it would be much slower, although that would only matter if gsub is executed many times in a loop.
Johnuniq (
talk)
01:16, 15 November 2016 (UTC)
Hello. I need help for Module. el:Module:Περισσότερεςκατακτήσεις (is in English).
See Cypriot First Division (Q155965), property 1346, qualifier P1355. I want to show the item of P1346 if it has the largest qualifier P1355. Xaris333 ( talk) 23:59, 26 November 2016 (UTC)
Hi all. :-) Special:Search/cat s and dog in curly braces does not transclude the list of search results. Does Lua have access to search results lists? (I recall that it does not have API access, but apart from that, I have difficulty finding what relevant access or objects it does have.) -- Gryllida 01:45, 9 December 2016 (UTC)
?withJS=
, though. You can simply create a default-on JavaScript gadget that only runs when you are viewing that page. —
Mr. Stradivarius
♪ talk ♪
05:10, 9 December 2016 (UTC)An editor has nominated Module:PropertyLink for deletion. Input from those familiar with modules is welcome at Wikipedia:Miscellany for deletion/Module:PropertyLink. Thanks, — Godsy ( TALK CONT) 09:11, 20 December 2016 (UTC)
Is it possible to retrieve the date & time of a user's most recent edit? This would be found at Special:Contributions/USERNAME .. or the data returned by API:Usercontribs -- Green C 17:42, 23 December 2016 (UTC)
For example:
local tab = mw.html.create('table')
tab
:addClass('wikitable')
:tag('caption'):wikitext('something '):wikitext('and something')
:tag('tr'):tag('td'):wikitext('a')
:tag('tr'):tag('td'):wikitext('b')
return tab
Why it knows that I want to get:
<table class="wikitable">
<caption>something and something</caption>
<tr><td>a</td></tr>
<tr><td>b</td></tr>
</table>
rather than:
<table class="wikitable">
<caption>something and something
<tr><td>a
<tr><td>b</td></tr>
</td></tr>
</caption>
</table>
Where the :tag('caption')
is closed?--
A Sword in the Wind (
talk |
changes)
06:01, 15 October 2016 (UTC)
<table class="wikitable"><caption>something and something<tr><td>a<tr><td>b</td></tr></td></tr></caption></table>
<table class="wikitable">
<caption>something and something
<tr>
<td>a
<tr>
<td>b</td>
</tr>
</td>
</tr>
</caption>
</table>
local tab = mw.html.create('table')
tab:addClass('wikitable')
tab:tag('caption'):wikitext('something '):wikitext('and something')
tab:tag('tr'):tag('td'):wikitext('a')
tab:tag('tr'):tag('td'):wikitext('b')
<table class="wikitable"><caption>something and something</caption><tr><td>a</td></tr><tr><td>b</td></tr></table>
local tab = mw.html.create('table')
tab:addClass('wikitable')
local caption = tab:tag('caption')
caption:wikitext('something ')
caption:wikitext('and something')
local tr1 = tab:tag('tr')
local td1 = tr1:tag('td')
td1:wikitext('a')
local tr2 = tab:tag('tr')
local td2 = tr2:tag('td')
td2:wikitext('b')
<table>
node inside another table's <td>
node, then that's your job done. The part that usually confuses people is that every time you call :tag()
mw.html returns a new node. This can have unexpected results if you don't know how it works. For example:-- Example 1
local t1 = mw.html.create('table')
t1:tag('tr'):tag('td'):wikitext('foo') -- t1 points to the "table" node because we defined it on the line above.
mw.log(tostring(t1)) -- Logs "<table><tr><td>foo</td></tr></table>"
-- Example 2
local t2 = mw.html.create('table'):tag('tr'):tag('td'):wikitext('foo') -- t2 points to the "td" node, as that is the return value of the expression
mw.log(tostring(t2)) -- Logs "<td>foo</td>"
foo:bar():baz()
) the expressions are expanded from left to right. I find it easiest to visualise what's happening if I add more parentheses, like this: ( foo:bar() ):baz()
. In effect, we are hoping that foo:bar()
returns an object that has a "baz" method, and then attempting to call that method. Because of this, the overall return value of an expression with chained methods is the return value of the right-most method. Let me break down my example above.mw.html.create('table') -- Returns a table node
:tag('tr') -- Calls the table node's "tag" method, and returns a new "tr" node
:tag('td') -- Calls the "tr" node's "tag" method, and returns a new "td" node
:wikitext('foo') -- Calls the "td" node's "wikitext" method, and returns the "td" node
local root = mw.html.create('table')
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row.')
:done()
:tag('td')
:wikitext('The second cell of the first row.')
:done()
:done()
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row.')
:done()
:tag('td')
:wikitext('The second cell of the second row. This cell has a nested table in it.')
:tag('table')
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row of the nested table.')
:done()
:done()
:done()
:done()
:done()
:done()
:done()
calls if you make sure that root always refers to the original table element:local root = mw.html.create('table')
root
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row.')
:done()
:tag('td')
:wikitext('The second cell of the first row.')
:done()
:done()
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row.')
:done()
:tag('td')
:wikitext('The second cell of the second row. This cell has a nested table in it.')
:tag('table')
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row of the nested table.')
-- Make the root table and store a reference to it in the rootTable variable
local rootTable = mw.html.create('table')
-- Add a row to the root table
rootTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row.')
:done()
:tag('td')
:wikitext('The second cell of the first row.')
-- Add a second row to the root table, and make a reference to the nested table's "table" node
local nestedTable = rootTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row.')
:done()
:tag('td')
:wikitext('The second cell of the second row. This cell has a nested table in it.')
:tag('table')
-- Add a row to the nested table.
nestedTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the first row of the nested table.')
-- Add a third row to the root table
rootTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the third row.')
:done()
:tag('td')
:wikitext('The second cell of the third row.')
-- Add another row to the nested table
nestedTable
:tag('tr')
:tag('td')
:wikitext('The first cell of the second row of the nested table.')
I saw User talk:Peter coxhead#Testcases page in mainspace and tried to move it to Module space. However, when I tried I got "Non-Module pages cannot be moved to the Module namespace (except for /doc pages), and Module pages (except for /doc pages) cannot be moved out of the Module namespace." and it deletes the target page without letting you know what it has done. How do you move stuff over. I figure you could move it to a Module:something/doc and then to the correct title but I've done enough screwing around for now. CambridgeBayWeather, Uqaqtuq (talk), Sunasuttuq 03:43, 30 December 2016 (UTC)
I've tested templates in my user space, by using {{User:TJRC/Sandbox/TemplateName}}
. It looks like you can't do that with modules, i.e., with something like
{{#invoke:User:TJRC/Sandbox/Modulename|func}}
. Is this correct? I just want to check before I create something in
Special:PrefixIndex/Module:Sandbox.
TJRC (
talk)
01:11, 7 January 2017 (UTC)
<pre>
block is returned by a module, but I should have used a more generic name because I have used it for lots of small tests, mostly without saving anything. I write some code to test a point I'm working on, edit that page but don't bother saving. Instead, under "Preview page with this module" enter "Module talk:Sandbox/Johnuniq/testpre" for the Page title and click "Show preview". Of course if you are building a larger module you can save and muck around, but the the preview feature is very handy.
Johnuniq (
talk)
01:41, 7 January 2017 (UTC)
Hi, I am wondering how I can test a module like module:labels that contains functions that doesn't take parameters but rather fetches the parameters from the parent scope - in this case a template instantiation. Can I use Module:UnitTests for this? Moberg ( talk) 20:11, 21 February 2017 (UTC)
Hey,
I was wondering if there is a way to find how many lines does a text contain.
for example:
a b c
would give 3
Thanks--
Mikey641 (
talk)
12:00, 22 February 2017 (UTC)
local function countLines(s)
local _, count = s:gsub('\n', '%0') -- Count newline characters in s
return count + 1
end
{{#invoke:מונה הופעות|countlines|text goes here}}
or {{#invoke:מונה הופעות|countlines|text=text goes here}}
. Best —
Mr. Stradivarius
♪ talk ♪
23:27, 22 February 2017 (UTC)Hi, in itwiki we were wondering if the expansion of a module is cached by the MediaWiki parser or not. Let's say page A includes ten times {{#invoke:B|main}}. Is the main function in module:B executed once or ten times? I would say "ten times", but I don't know parser internals. The module could contain randomly generated content or os.time(), so the parser can't cache it, or is it able to be aware of these functions? -- Rotpunkt ( talk) 16:11, 25 February 2017 (UTC)
local count = 10
and functions then use and change count
. However, count
is always 10 when the module starts—nothing is shared between the separate calls to module B. The good news is that it is astonishingly fast.
Module:Convert is breathtakingly enormous and complex yet well over 1000 {{
convert}} calls can be executed on a single page.mw.loadData
instead of require
.
Johnuniq (
talk)
00:43, 26 February 2017 (UTC)
mw.loadData( module )
does not support functions, a module that does not use global variables actually it is not recognized as "
functional", calling it only 1 time in the whole page. I'm right? --
Valerio Bozzolan (
talk)
04:01, 26 February 2017 (UTC)
{{example|one|two}}
would give exactly the same result regardless of anything else on the page—it does not matter if the template being rendered is the first occurrence on the page or the tenth. MediaWiki is like that because the designers want section editing to work (say for preview) without having to process the whole page.
Johnuniq (
talk)
06:55, 26 February 2017 (UTC)mw.loadData
does all steps only once and relies on the read-only wrapping to prevent one invoke from affecting the next.
Anomie
⚔
15:26, 26 February 2017 (UTC)
It was pointed out at
Template talk:when#Breaks inside Infobox settlement that if you try to pass various inline cleanup templates through infoboxes which apply {{formatnum: }}
that the year in the tracking category is mangled (comma inserted). would it be a good idea to create a smart formatnum which excludes the categories, and say references, from the formatnum transformation? or, does this already exist? thank you.
Frietjes (
talk)
22:14, 27 February 2017 (UTC)
A trivial change (I suspect) is needed to a Lua module; please see Template talk:Article history#maindate2. Any takers? - Dank ( push to talk) 03:14, 28 February 2017 (UTC)
Hi,
I'm not sure if it's the right place to ask about this: is there any way to extract say the country property (P17) from the item linked to the headquarters location property (P159) of an item? For example, the headquarters location property of Nordea is Stockholm ; if we then look for the country property of Stockholm, we'll get Sweden. So if could get the country that way, we wouldn't need to set a country qualifier for the headquarters location property of Nordea, is there any way to do that? The RedBurn ( ϕ) 21:40, 1 March 2017 (UTC)
{{#invoke:RexxS|getValueIndirect|P159|P17}}
→ Finland|qid=
for testing the call outside of the current article). The value of
headquarters location (P159) in
Nordea (Q1123823) is
Stockholm (Q1754); and the value of
country (P17) for
Stockholm (Q1754) is
Sweden (Q34). I'm just taking the first value of each property, assuming they are single-valued. You'd have to specify how you'd want to handle the situation if either were multi-valued.Hi everyone! I'm trying to create an option in Module:Wd that adds references from Wikidata to claims from Wikidata. However, simply outputting a reference between the tags <ref>...</ref> from a module keeps these tags as plain text; they are not processed by Wikipedia. This differs from templates, where such output is actually processed and converted into a real reference.
Is there any way to add references from a module? Or am I condemned to using templates for this?
Thanks, thayts 💬 13:10, 9 December 2016 (UTC)
f.sfn()
.buildCite
(which can probably be changed to include
Module:Citation/CS1 directly via require()
). That said, is there a reason you aren't e.g. working in
Module:Wikidata/sandbox? We don't really need two general purpose Wikidata modules. --
Izno (
talk)
13:44, 9 December 2016 (UTC)frame:preprocess('<ref name="foo">bar</ref>')
, but it is more efficient if you do it with frame:extensionTag{name = 'ref', content = 'bar', args = {name = 'foo'}}
, as it avoids the overhead of the parser having to parse the HTML tags and preprocess whatever content you put inside them. —
Mr. Stradivarius
♪ talk ♪
01:10, 10 December 2016 (UTC)
|nowikidata=true/false
when I call the module"? If you don't like using a special parameter value in the way that
Module:Wikidata does, you have a perfectly good alternative in
Module:WikidataIB that also addresses the "opt-in" vs "opt-out" issues. --
RexxS (
talk)
21:37, 4 March 2017 (UTC)
{{#invoke:wikidata|{{{country|FETCH_WIKIDATA}}}}}
I would do something like {{{country|{{#invoke:wd}}}}}
and so there is no real difference (except that the latter doesn't do a superfluous call to a module).
thayts
💬
22:45, 4 March 2017 (UTC)I am working on a location map wrapper in Module:Australian place map for use in Template:Infobox Australian place. I have implemented the module in the sandbox, and now in Template:Infobox Australian place/testcases I am seeing something strange. in particular, in the "Nyabing" I am currently seeing two pin markers, and in one of the "Woy Woy" examples, I am seeing zero pin markers. basically, it looks like the pin from the first "Woy Woy" has migrated up the page to the "Nyabing". my guess is that this is some quirk with using the {{ Testcase table}} template and/or something odd going on in Module:Location map? on a related note, I imagine it would probably be better if I could call the main function in Module:Location map directly instead of going through expandTemplate? I am hoping Jackmcbarn or one of the other LUA experts can help. thank you. Frietjes ( talk) 16:41, 4 March 2017 (UTC)
latd = -33.49
and that puts the pin a long way off the map.latd
. However,
Module:Australian place map applies abs to the longitude rather than the latitude. Some mucking around makes me think you probably want abs(longitude) to avoid an ugly error message if a negative longitude is entered. However, the module needs the same for latitude, and that is why the pin is in the wrong place with the negative latitude.
Johnuniq (
talk)
09:38, 5 March 2017 (UTC)
I'm reuploading a lot of images using
Commonist, which unfortunately overwrites file description pages. Is there a way to find text currently in the page (for example, the original uploader's username in the file information template) by transcluding the page, or does that not work because of Lua being parsed at the wrong time?
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
10:34, 5 March 2017 (UTC)
mw.title.getCurrentTitle():getContent()
. You can also expand any templates etc. in that wikitext by using
frame:preprocess. Whether you can manage to get useful information from either or both of those steps is another matter, however. —
Mr. Stradivarius
♪ talk ♪
23:37, 5 March 2017 (UTC)
Hey
I need help creating a module that will order 2 words alphabeticaly.
I did it in wiki code so I will explain how I did it, if you have better sugestions please offer:
Tagging User:Mr. Stradivarius who has helped me here before-- Mikey641 ( talk) 21:47, 7 March 2017 (UTC)
i = 1
.mw.ustring.char(mw.ustring.codepoint(s, i, i))
).So, we are using a system in hewiki to "verify" template parameters. i will be happy to explain about the system, but my question here is a bot different:
it turns out that this system adds significant load to some template parsing, and this cases a small number of pages to violate some limits of the parser, and these pages then are not parsed correctly.
the only remedy we found so far is to completely (i.e., globally) disable this system - if we do that, the pages are parsed ok.
what we are looking for, is a way to gate specific lua functions, based on the some attribute of the page, something similar to {{ Nobots}}, for lua modules.
it is perfectly kosher to use something like categories (naturally, it will be a hidden one), i.e., i will be happy to define a new hidden category, say "No template parameters validation", and add those pages to the category. however, i could not find a way to ask in lua "does this page belong to category X", or "give me the list of categories this page belongs to". i cannot think of something other than category that will do the job, but i am willing to learn any new tricks.
note that the #invoke call is not in the page itself, but rather pretty deep in some templates (many may not even be transcluded directly, but through other templates, going 2, 3 and even 4 levels deep).
any help and advice will be appreciated. peace - קיפודנחש (aka kipod) ( talk) 16:04, 12 March 2017 (UTC)
mw.title.getCurrentTitle():getContent():find('__NOPARAMETERVALIDATION__')
. The second is to have a blacklist module with e.g. return {['Page name 1' = true, 'Page name 2' = true}
which you check before doing the validation. I'd be quite interested in hearing about the system you are using, though - what kind of parameter verification are you doing that's creating so much load? —
Mr. Stradivarius
♪ talk ♪
23:39, 12 March 2017 (UTC)
local verbotten = {
'page name 1' = '',
'page name 2' = '',
-- ..... etc. etc. etc.
}
function envelope( frame )
local pageName = mw.title.getCurrentTitle().text
-- exploiting the fact that unline JS, in lua '' is actually true
return verbottenpageName or require( 'actualModule' ).actualFunction( frame )
end
mw.templateData.getTemplateData( templatename )
, which is open for ~ 2 years now. "they" actually put "priorily:lowest" on it (see
phab:T107119, so we call getContent() on the template page,, distill the stuff enclosed inside the "templatedata" tag, and call "jsonDecode()" on it. after that, the rest is trivial. you may want to look in
he:Module:ParamValidator - i tried to document it as much as possible. the system is working, and exposed thousands (literally) of errors in templates.There was some discussion at TfD about
Template:Infobox map. basically, all that
Template:Infobox map does right now is (1) check to see if the map exists, and then (2) call either
Template:Location map or
Module:InfoboxImage. this is somewhat inefficient since there is already an ifexists check in the getMapParams
function in
Module:Location map. so, my thought is that we could change the code of {{
infobox map}} to something like
{{location map|{{{map}}} | relief = {{{relief|}}} | overlay_image = {{{overlay|}}} [...] | nomap_message = {{#invoke:InfoboxImage | InfoboxImage | image={{{map}}} | size={{{map_width|}}} | maxsize={{{max_width|}}} | sizedefault={{if empty|{{{default_width|}}}|220px}} | alt={{{map_alt|}}} | title={{{map_caption|}}} }}{{#if:{{{map_caption|}}}|<div>{{{map_caption|}}}</div>}} }}
so, that instead of returning the error message on line 50 of
Module:Location map it would return the value of |nomap_message=
if |nomap_message=
is not nil. does this seem like a good idea? if so, it would be helpful if someone could implement this |nomap_message=
in
Module:Location map/sandbox for testing. I would do it, but I am not sure the best way to pass this through to the getMapParams
function and the best way to catch it when it comes out of the getMapParams
function. probably need a second return flag with 0 for no error, and 1 for error or something like that? thank you.
Frietjes (
talk)
16:35, 16 March 2017 (UTC)
An editor has asked for a discussion regarding Module:Navbox with nowrap lists. Input from those familiar with modules is welcome at Wikipedia:Miscellany for deletion/Module:Navbox with nowrap lists. Thanks, — Godsy ( TALK CONT) 09:11, 20 December 2016 (UTC)
How can I modify
Module:Tone superscript so that it only adds superscript tags to numbers not part of HTML entities (or filenames/links/anything which breaks when <sup>
tags are added)? The module was originally written by someone else but I'm trying to repurpose it so it works in {{
Infobox Chinese}}.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
09:15, 24 March 2017 (UTC)
+
):
x = arg:gsub("(%d+)", "<sup>%1</sup>")
+
, which isn't really a problem since there are fewer than 10 tones in most tonal languages. The module could have the entities changed to characters to avoid inserting <sup>
tags in them, although there could be a better solution.
Jc86035 (
talk) Use {{
re|Jc86035}}| j3 = {{Jpingauto|Can4 Gong2 Sang1}}
–
or –
, and might have a link which should not be damaged, I could fix the module.
Johnuniq (
talk)
06:25, 25 March 2017 (UTC)
<sup>...</sup>
to a digit only if it's preceded by letters? –
Uanfala (talk)
08:40, 25 March 2017 (UTC)
Hello folks, is there any chance putting a function inside this module, which will give me the opportunity to add languages with {{#invoke:Languages|getCode|language code}}? -- Vēnī‧vīdī‧scrīpsī [DM] 18:03, 27 March 2017 (UTC)
{{#invoke:Wt/cu/PartOfSpeech|get_wiki|de}}
get_wiki()
. You aren't getting the language code argument from the arguments table passed into the function from wiki text; instead, you are getting the arguments table and passing that to mw.text.trim()
which is expecting a string, not an arguments table. See
mw:Extension:Scribunto/Lua_reference_manual#Accessing parameters from wikitext for a more detailed description of how arguments work.get_wiki()
with {{#invoke:Wt/cu/PartOfSpeech|get_wiki|de}}
I'm looking for a script that will look at a range of values, display the most recent three (or any other number to be defined) and then show the rest of the values in a collapsed list. The example I am looking at is {{ Infobox GB station}} and the usage statistics. These figures exist going back to 2002/3 (and a parallel set of interchange figures as well) so including them all gives a very long list. Ideally a script would look at the list, find the most recent three recorded, which are not necessarily the most up-to-date three, display those and then show the rest in a collapsed table. I know there are issues about the template needing an update to show the most recent figures first but if the base data was most recent first like {{ UK railway station usage}} is this something that can be done? Nthep ( talk) 13:12, 12 April 2017 (UTC)
@
Nthep: The
Wikidata property for patronage/ridership has been created, so I assume the data can now be imported into there using QuickStatements. I'm not sure how to use a qualifier for interchange traffic although has role (
P2868) → interchange station (
Q1147171) might work.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:14, 19 April 2017 (UTC)
Hello. I am a user in Greek Wikipedia.
1) w:el:Module:Επίσημηονομασίασεξένηγλώσσα These shows the P1448 property if the language is not Greek. But is showing only the first language. If there are shows of them, only shows the first one.
2) I want, near the result, to have language code. For example, "London ( en)". The code must be link to wikidata item of the language if there is not an article to Greek Wikipedia. If there is an article of the language to Greek Wikipedia, to show link to that article. If it is too difficult is ok only to show the code. Maybe can link to w:el:ISO 639-1.
If the module works, then you must see the phrase "Επίσημη ονομασία: London ( en)" or "Επίσημη ονομασία: London (en)" under the blue box [2].
Xaris333 ( talk) 14:47, 18 April 2017 (UTC)
Επίσημη ονομασία: London ([[English language|en]])
language = "en"
and text = "London"
. How would "English language" be derived from "en"?
Xaris333 ( talk) 13:24, 19 April 2017 (UTC)
We just rolled out on Commons c:Module:Creator that mimics c:Template:Creator but can also fetch any field from Wikidata if needed. The issue I have is with few creator templates like c:Creator:Tomás Povedano that end up in Category:Pages with script errors. At this moment c:Creator:Tomás Povedano only shows "The ID entered is unknown to the system. Please use a valid entity ID." error, but the message like that disappeared from other pages without any edits. c:Creator:Tomás Povedano links to d:Q19675193 which is correct "entity ID". Any idea on how to debug this issue or what might cause it. phabricator:T143970 deals with this error but in context of how to detect bad "entity IDs" aka q-codes. -- Jarekt ( talk) 17:46, 23 April 2017 (UTC)
Hi. Is there a way to include a submodule that is relative to the current module like require("Module:SomeName/sub")
where SomeName
is not fixed? I.e. is there a way to include /sub
without the need to define Module:SomeName
or is there a way to dynamically determine the current module's title Module:SomeName
?
thayts
💬
21:33, 4 May 2017 (UTC)
function module_name.main(frame)
local some_data = mw.loadData (frame:getTitle() .. '/sub');
frame:getTitle()
before, but that does not necessarily return the title of the calling module itself. For example, if the module is invoked in the examples section of its documentation then the returned value is actually Module:Documentation
.
thayts
💬
06:56, 5 May 2017 (UTC)
frame:getTitle()
is the best thing we have, as far as I'm aware. —
Mr. Stradivarius
♪ talk ♪
14:34, 5 May 2017 (UTC)
frame:getTitle()
is called. If inside a function that received the frame object, then the current module's title seems to be returned. If outside a function call, like where require()
is typically called, then it depends (also, I was using mw.getCurrentFrame():getTitle()
there). I think I will have a look at mw.loadData()
. Thank you both!
thayts
💬
17:49, 5 May 2017 (UTC)And what if the module that is including the submodule is actually included through require()
itself? I.e. require("Module:SomeName")
, how does Module:SomeName
know it was included by that name? There is no frame involved here and mw.getCurrentFrame():getTitle()
certainly does not return Module:SomeName
, so how could it construct Module:SomeName/sub
?
thayts
💬
10:34, 6 May 2017 (UTC)
...
passed to the module.
thayts
💬
18:21, 6 May 2017 (UTC)It's a FAQ, could not find the answer. Q: Can I make nested calls to an #invoking template?
{{OuterTemplate |title=Bar |{{InnerTemplate|a|A}} |{{InnerTemplate|b|B}} }}
(And does the answer apply for both template calls and direct #invoke|main calls?) - DePiep ( talk) 11:15, 11 May 2017 (UTC)
{{#invoke:String|match|s=123{{snd}}456 |pattern=%d*(.*) |plain=false |nomatch=nomatch_output }}
{{snd}}
was called before the {{#invoke:}}
. Which is to be expected.
Module:Navbar appears to contain :newline();
for no reason (after each of the square brackets in "[ v · t · e ]"), which might be causing a detected syntax error
on the German Wikivoyage (discussion in English). Are they necessary and should they be replaced with spaces? (Pinging
DerFussi.)
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
16:05, 10 May 2017 (UTC)
Is it possible to use
Module:Unsubst on infoboxes so that the parameters and their equals signs have correct indentation and are in the correct order, and parameter aliases are replaced with their canonical values on substitution? (This would be done for {{
Infobox song}}, {{
Infobox single}} and their auxiliary templates like {{
Extra chronology}}.)
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:26, 13 May 2017 (UTC)
I've tried setting up {{
Infobox song/sandbox}} with the new module, but the alias handling |$A=
isn't working for some reason. Could anyone help with this? Thanks,
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
05:49, 14 May 2017 (UTC)
(to test, take a random template from
Template:Infobox song/doc, change the template title to subst:Infobox song/sandbox
, and press the "show changes" button
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
05:54, 14 May 2017 (UTC))
Could someone help me with
Module:Unsubst-infobox, which I'm trying to fork from
Module:Unsubst? I'm trying to get some of the new parameters in it to work but for some reason the input data gets lost somewhere. Maybe I'm using mw.text.split wrong.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
14:42, 15 May 2017 (UTC)
{{subst:Infobox song/sandbox | Name = Song }}
{{Infobox song/sandbox | name = Song | type = | writer = | composer = | lyricist = | written = | published = | misc = }}
{{Infobox song/sandbox | name = | cover = | cover_size = | alt = | border = | caption = | type = | artist = | album = | EP = | language = | English_title = | writer = | composer = | lyricist = | written = | published = | genre = | recorded = | studio = | venue = | length = | producer = | released = | label = | format = | A-side = | B-side = | ISWC = | chronology = | prev_title = | prev_year = | next_title = | next_year = | prev = | prev_no = | next = | next_no = | tracks = | misc = }}
|$S3=
) is supposed to replace the full list, and the value of parameter |Name=
should be transferred to parameter |name=
(lowercase) as defined in |$A=
.
Jc86035 (
talk) Use {{
re|Jc86035}}if
that tests mw.isSubsting:
error('mw.isSubsting is true')
aliases[tmp[1]] = aliases[tmp[2]]
correct? The RHS should be tmp[2]
.tmp[2]
works for some of the aliases but not all of them (e.g. try showing changes for substituting the infobox of
Waltzing Matilda, with title changed to "subst:Infobox song/sandbox").
Jc86035 (
talk) Use {{
re|Jc86035}}@ Jc86035: I fixed two problems in Module:Unsubst-infobox:
-- Changed for k, v in ipairs( {frame.args['$S1'], frame.args['$S2'], frame.args['$S3']} ) do -- to for k = 1, 3 do local v = frame.args['$S' .. k] -- Changed if v ~= {} then -- to if next(v) then -- if table v is not empty
In the first, ipairs stops at the first nil
, so if there is no $S1
parameter, the original code would not test the other two parameters.
In the second, two different tables are never equal. Consider the following code:
t = {} if t == {} then print('1: EMPTY') else print('1: NOT empty') end if next(t) then print('2: NOT empty') else print('2: EMPTY') end
If run on a computer with Lua, the above would print:
1: NOT empty 2: EMPTY
There may be other issues, but that's all I have time for at the moment. If there is still a problem, please provide an example using $S1
(add it
here if wanted) and outline what shows that it is wrong, and what the correct result would be.
Johnuniq (
talk)
10:38, 18 May 2017 (UTC)
$S1
or $S3
. I'm not sure why. {{
Audio sample}}, which also uses the module (but with only $P
and $E
) works fine.
Jc86035 (
talk) Use {{
re|Jc86035}}ipairs( sets )
which should be pairs
because each item in the set is of the form 'example' = true
so ipairs
will get nothing. I'm hopelessly confused about $P
and $S
and more so I'm not going to fix it at the moment. However, I might look at working out what should be done if you don't fix it first.
Johnuniq (
talk)
00:41, 20 May 2017 (UTC)
sets
is a table containing three other tables, so ipairs should work for it. Maybe it's better to just scrap the thing and use parser functions to add parameters to $E instead.
Jc86035 (
talk) Use {{
re|Jc86035}}ipairs(sets)
, it is ipairs(params)
in line 147. Bear in mind that I still do not understand the parameters or what is going on, but at line 147 params might be a numbered table (in which case ipairs would work as expected), but it might be a set. That would occur if the code at line 129 executed params = v
which would replace params with sets[1] (for the case where $S1 has a relevant value).
Johnuniq (
talk)
06:42, 20 May 2017 (UTC)@
Johnuniq: So params = v
was the problem. It should be fixed now.
Jc86035 (
talk) Use {{
re|Jc86035}}
to reply to me
07:52, 20 May 2017 (UTC)