Wikipedia talk:Lua/Archive 4
![]() | This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 | Archive 2 | Archive 3 | Archive 4 | Archive 5 | Archive 6 | → | Archive 10 |
Lua code editor
I've been away too long. Can someone tell me what is the/a code editor for Lua? I'd like to have syntax highlighting in wiki. -DePiep (talk) 21:49, 20 October 2015 (UTC)
- @DePiep: The default code editor is mw:Extension:CodeEditor, which is enabled on all WMF wikis. You can toggle it on and off by clicking the "<>" symbol at the top-left of the edit window when you edit Lua modules, JavaScript pages or CSS pages. It requires JavaScript, and it also requires the "Enable enhanced editing toolbar" option in your preferences. — Mr. Stradivarius ♪ talk ♪ 23:24, 20 October 2015 (UTC)
- Sorry, couldn't get this working. Ido not have the "<>" symbol (somewhere top-left) you mention. I think I checked the other settings well. -DePiep (talk) 11:55, 29 October 2015 (UTC)
(strange: now that I edit this section, I see its text marking by bg-colors, but these are shifted some 5 lines up i.e. starts above the editbox). -DePiep (talk)12:00, 29 October 2015 (UTC)- That's by Syntax highlighter I just enabled. Different topic, so I struck. -DePiep (talk) 12:05, 29 October 2015 (UTC)
- Do you get any errors in the JavaScript console when you edit module pages? There might be something in your settings which is causing JavaScript to fail. — Mr. Stradivarius ♪ talk ♪ 13:50, 29 October 2015 (UTC)
- That's by Syntax highlighter I just enabled. Different topic, so I struck. -DePiep (talk) 12:05, 29 October 2015 (UTC)
Beginner question on string concatenation
I've been playing with Lua for the very first time (under my other account) and I got pretty close to replacing the broken Bugzilla links by Phabricator links on mw:Developers/Maintainers in https://www.mediawiki.org/w/index.php?title=Module:Bugzilla&oldid=1922142 but I could not solve one issue: If the "component" is e.g. the string "JobQueue", the component string has incorrect surrounding dashes so the incorrectly constructed URL is "https://phabricator.wikimedia.org/tag/mediawiki--jobqueue-". How do I avoid these dashes around the component name (it should be "-jobqueue" and not "--jobqueue-")? Thanks in advance for any pointers! --Malyacko (talk) 21:52, 24 October 2015 (UTC)
- you might want to
mw.text.trim()
component before you replace spaces with dashes. If component has leading and/or trailing white space, they will be replaces with dashes and then when you concatenate with another dash ... - —Trappist the monk (talk) 22:14, 24 October 2015 (UTC)
- That worked! Thank you a lot! --Malyacko (talk) 10:45, 25 October 2015 (UTC)
Help someone fix a small bug in a template or gadget: It's Google Code-In time!
- Are you a developer and have small, self-contained, "easy" bugs in your Wikimedia code that you would love to get fixed?
- Would you enjoy helping someone port your template to Lua?
- Does your gadget use some deprecated API calls?
- Does the documentation of your code need some improvements?
- Do you enjoy mentoring to a new contributor fixing small tasks?
Google Code-In (GCI) will take place again in December and January: a contest for 13-17 year old students to provide small contributions to free software projects. Wikimedia will apply again to take part and would like to offer a wide range of tasks. Just one example: Multimedia saw some impressive achievements in last year's contest!
Tasks should take an experienced contributed about two-three hours ("beginner tasks" also welcome which are smaller) and can be of the categories Code, Documentation/Training, Outreach/Research, Quality Assurance, and User Interface/Design. For more information, check the wiki page and if something is unclear, please ask on the talk page!
Thank you, --AKlapper (WMF) (talk) 00:01, 2 November 2015 (UTC)
Detecting ref tag
I want to detect if the input has an initial <ref> tag. Long time ago I learned that in input strings this shows up as strip marker like ?UNIQ...QINU?
, and that it is a risky to use that knowledge (mw code may change). However, it seems to be the only way to detect the tag in Lua.
My question is: is there a (more or less) stable way to detect a ref in the input string? Planned usage is: in a comment (suffix) parameter, check whether it starts with a reference tag. In that case, do not add the space:
|distance=100 km
|comment=<ref>example.com</ref> as the cow flies
- to show:
100 km[1] as the cow flies
- otherwise, show:
100 km_as the cow flies
(_=space added)
I see module:Convert has something like (search QINU):
... match('^(\127UNIQ[^\127]*%-ref%-%x+%-QINU\127)')
Any wisdom? -DePiep (talk) 09:58, 8 November 2015 (UTC)
- First, I see no added space, so I must be missing something. Second, tags are always stripped by the preprocessor before being send of to the LUA interpreter, so what you want as such is not possible. That code from the Convert module is already a hack...
-- [[User:Edokter]] {{talk}}
10:16, 8 November 2015 (UTC)- Yes, the convert code is a gross hack, but I had to do it because people add references to numbers in infoboxes, and those numbers (with the ref or refs) are then passed to convert. The hack has already broken once due to a MediaWiki change because convert originally carefully checked for the exact format used at the time on the principle that I didn't want any false hits. In the example above, the comment parameter would strip any leading/trailing spaces from the text, so I guess DePiep needs to add the space to save the user the hassle of entering
at the start, or some other workaround. @DePiep: Why can't the user just add the ref after the distance? Johnuniq (talk) 10:44, 8 November 2015 (UTC) - (edit conflict) @Edokter: I imagine that the module code is something like
args.distance .. args.comment
, which with|distance=100km|comment=<ref>example.com</ref> as the cow flies
will render as100 km[1] as the cow flies
. With|distance=100km|comment=as the cow flies
, though, it would render as100 kmas the cow flies
, hence the need for an extra space in the Lua module. (I like the cow flying image, by the way.) @DePiep: It's just as Edokter says - you can't get the raw ref tags from Lua, you have to rely on searching for the strip markers, which is a hack, and may change with future versions of MediaWiki. I don't think strip markers are very likely to change in the near future, though. I would do it by splitting the strip-marker-matching code out into a separate function, so that if the MediaWiki code changes, all you have to do is update that code. In fact, it might be worth making a stand-alone module for this so that any modules that work with strip markers can be updated straight away if the MediaWiki code changes. Come to think of it, Scribunto has mw.text.killMarkers, which will remove all strip markers from a string, so you can check whether a string s has strip markers or not with the codes ~= mw.text.killMarkers(s)
. I don't think there's a 100% certain way to check whether the strip marker is a reference or if it is at the start of the string without making your own Lua pattern, though. — Mr. Stradivarius ♪ talk ♪ 10:57, 8 November 2015 (UTC)- Yes, using killMarkers like that is a good idea. It doesn't matter whether it is some other kind of marker like <math>, the template can insert a space if killMarkers did not find any kind of marker. That would be perfect for the usage needed, although it would not be right for cases like the ref being at the end of comment rather than at the beginning. Johnuniq (talk) 22:35, 8 November 2015 (UTC)
- Marked the added space (diff: starts with ref=no space, starts with regular text=add space). The value ('100 km') is best to be by separate parameter in my case. -DePiep (talk) 22:40, 8 November 2015 (UTC)
- @Johnuniq: "Why can't the user just add the ref after the distance?" - I need the value in a distinct parameter to format the value.
- If I can not detect the opening ref (in the suffix parameter input), I and the editor needs two params:
|suffix_ref=
and|suffix_anytext=
to omit/add the space. This is what currently happens in {{Chembox}}: every value actually has two such suffix params. -DePiep (talk) 22:47, 8 November 2015 (UTC)- Re general: as Stradivarius describes. Using killMarkers instead if hardcoding into a small module is safer, esp in case of mw changes. All other tags firing just as well is a rare and minor nuisance (to be documented in the template /doc). (And 'the cow flies' :-) originally was a typo I saw & kept). -DePiep (talk) 23:00, 8 November 2015 (UTC)
- Yes, using killMarkers like that is a good idea. It doesn't matter whether it is some other kind of marker like <math>, the template can insert a space if killMarkers did not find any kind of marker. That would be perfect for the usage needed, although it would not be right for cases like the ref being at the end of comment rather than at the beginning. Johnuniq (talk) 22:35, 8 November 2015 (UTC)
- Yes, the convert code is a gross hack, but I had to do it because people add references to numbers in infoboxes, and those numbers (with the ref or refs) are then passed to convert. The hack has already broken once due to a MediaWiki change because convert originally carefully checked for the exact format used at the time on the principle that I didn't want any false hits. In the example above, the comment parameter would strip any leading/trailing spaces from the text, so I guess DePiep needs to add the space to save the user the hassle of entering
The following is probably sufficient. If comment does not start with a marker, a space is inserted before comment.
comment = 'as the cow flies' -- this comes from the template parameter
if comment:sub(1, 1) ~= '\127' then comment = ' ' .. comment end
The above relies on the fact that every marker starts with a delete character, and that is enough for this application. Using killMarkers would fail for:
|distance=100 km |comment=as the cow flies<ref>example.com</ref>
Hello,
Can somebody add an option (like others options of this module module : same, limit...) in order to have an intern link (ex : Bogota and not Bogota) without having to write for example {{#invoke:random|item|[[Bogota]]|[[Paris]]|[[Berlin]]}} but simply {{#invoke:random|item|Bogota|Paris|Berlin}}.
PS: on the spanish version of the module:list , there is a fonction enlazar whitch seems to do what I need but I don't know how to integrate it on module:random.
Thanks. Lepsyleon (talk) 11:13, 9 November 2015 (UTC)
- @Lepsyleon: That's an easy one: just use
[[{{#invoke:random|item|Bogota|Paris|Berlin}}]]
. Best — Mr. Stradivarius ♪ talk ♪ 11:15, 9 November 2015 (UTC)- @Mr. Stradivarius:, sorry but it doesn't work if you use some options of this modul like limit. For example, with
{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3}}
, it makes ONE red lind with THREE terms. That's why I ask if it's possible to add a new option like enlazar (link). Best. Lepsyleon (talk) 11:39, 9 November 2015 (UTC)- @Lepsyleon: Hmm, ok. I'm reluctant to add just a "link" option, because other people might want their results formatted in different ways, for example made into an external link or put into a template invocation. How about an option that specifies a pattern to format the result with? Perhaps something like
{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3|format=[[$1]]}}
, which would return, e.g.[[Berlin]], [[Bogota]] and [[Paris]]
. For things like template invocations this would need to be done with nowiki tags, like{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3|format=<nowiki>{{my template|$1}}</nowiki>}}
. But then, for most uses{{#invoke:random|text_list|[[Bogota]]|[[Paris]]|[[Berlin]]|[[Londres]]|[[Madrid]]|limit=3}}
isn't really that complicated. Did you have any more complicated uses in mind? — Mr. Stradivarius ♪ talk ♪ 13:59, 9 November 2015 (UTC)- @Mr. Stradivarius: OK for
{{#invoke:random|text_list|Bogota|Paris|Berlin|Londres|Madrid|limit=3|format=[[$1]]}}
but when I try it,there is no internal links. - The matter with
{{#invoke:random|text_list|[[Bogota]]|[[Paris]]|[[Berlin]]|[[Londres]]|[[Madrid]]|limit=3}}
is the weight of the pages generated with this model when there is a lot of items. - Lepsyleon (talk) 14:41, 9 November 2015 (UTC)
- Someone can help me, please ? Best. Lepsyleon (talk) 21:24, 11 November 2015 (UTC)
- @Lepsyleon: What do you mean by weight of the pages? Jackmcbarn (talk) 02:48, 12 November 2015 (UTC)
- @Jackmcbarn: : weight = bytes for a page. For example, I use the module:random with a javascript code for the french version of [1]. With it, I can make a list of all the articles linked to this portal. But when there is too much articles linked to a portal, the javascript code is bugging, because the weight of the page is big. And if I use [[ ]] for each item like with
{{#invoke:random|text_list|[[Bogota]]|[[Paris]]|[[Berlin]]|[[Londres]]|[[Madrid]]|limit=3}}
, the weight of the page generated is bigger. Lepsyleon (talk) 08:24, 12 November 2015 (UTC)- The page's output is exactly the same size no matter what the module does to generate it. I'm not sure what you're referring to that's changing sizes. Jackmcbarn (talk) 16:50, 12 November 2015 (UTC)
- Lepsyleon is talking about the size of the source wikitext. This is edited by fr:MediaWiki:Gadget-PageAuHasard.js (see e.g. this page history). The gadget is apparently having problems on pages with a large source size. — Mr. Stradivarius ♪ talk ♪ 02:13, 13 November 2015 (UTC)
- Yes, it's what I mean (sorry for my bad english). In fact, I would like that only the three random selected items (if there is the option limit=3) have [[ ]] and not all items of the array list. Lepsyleon (talk) 08:41, 13 November 2015 (UTC)
- No idea ? Lepsyleon (talk) 13:12, 18 November 2015 (UTC)
- Yes, it's what I mean (sorry for my bad english). In fact, I would like that only the three random selected items (if there is the option limit=3) have [[ ]] and not all items of the array list. Lepsyleon (talk) 08:41, 13 November 2015 (UTC)
- Lepsyleon is talking about the size of the source wikitext. This is edited by fr:MediaWiki:Gadget-PageAuHasard.js (see e.g. this page history). The gadget is apparently having problems on pages with a large source size. — Mr. Stradivarius ♪ talk ♪ 02:13, 13 November 2015 (UTC)
- The page's output is exactly the same size no matter what the module does to generate it. I'm not sure what you're referring to that's changing sizes. Jackmcbarn (talk) 16:50, 12 November 2015 (UTC)
- @Jackmcbarn: : weight = bytes for a page. For example, I use the module:random with a javascript code for the french version of [1]. With it, I can make a list of all the articles linked to this portal. But when there is too much articles linked to a portal, the javascript code is bugging, because the weight of the page is big. And if I use [[ ]] for each item like with
- @Lepsyleon: What do you mean by weight of the pages? Jackmcbarn (talk) 02:48, 12 November 2015 (UTC)
- Someone can help me, please ? Best. Lepsyleon (talk) 21:24, 11 November 2015 (UTC)
- @Mr. Stradivarius: OK for
- @Lepsyleon: Hmm, ok. I'm reluctant to add just a "link" option, because other people might want their results formatted in different ways, for example made into an external link or put into a template invocation. How about an option that specifies a pattern to format the result with? Perhaps something like
- @Mr. Stradivarius:, sorry but it doesn't work if you use some options of this modul like limit. For example, with
Metamodule for wikitable
Is there a metamodule to build a wikitext WP:wikitable? Or would that be inefficient/inelegant coding? -DePiep (talk) 12:09, 29 October 2015 (UTC)
- There isn't one as far as I know. It wouldn't be inefficient or inelegant to use one, in my opinion, but most people just use
mw.html
with<table>
tags, as in most cases that does all that you need. Also, if you just need a simple wikitable you might get away with something like themakeWikitable
function that I wrote in Module:Find sources/autodoc. — Mr. Stradivarius ♪ talk ♪ 13:46, 29 October 2015 (UTC) - See this .17:29, 4 January 2016 (UTC)
Is it possible...
The heading sucks, but I digress. Is it possible to use a basic replacement string to make a template overwrite another template? Now I know very little about code except basic BASIC but basically can you do something like if you're editing X module -if issomethingsomething then replace the entire text of x module and invoke Y template Or would you need some sort of container template? Because I don't want it to give a new string of lua, but to replace literally the wikitext that links to the template that links to the module. This may be total BS, I don't know. --Monochrome_Monitor 00:43, 29 November 2015 (UTC) @Jackmcbarn: --Monochrome_Monitor 00:47, 29 November 2015 (UTC)
- I don't understand what you're asking. Can you give an example? Jackmcbarn (talk) 03:16, 29 November 2015 (UTC)
- Sure. For the Main template, if it's an article it will display the default string "the main article for this is...", if it's a category it will display "the main article for this catgory is...". But we are supposed to use Cat main, not regular main, for categories, even though the main template can technically display a category-appropriate string. I was wondering if it's possible that main could "replace" itself with cat main (not the module, the template) on the condition that the page is a category. --Monochrome_Monitor 14:37, 30 November 2015 (UTC)@Jackmcbarn:
- Sort of like a redirect. --Monochrome_Monitor 14:38, 30 November 2015 (UTC)
- @Monochrome Monitor: You can do
return frame:expandTemplate{ title = 'cat main', args = frame.args }
. Try it and see if that's what you mean. Jackmcbarn (talk) 02:06, 3 December 2015 (UTC)- Sweet thanks. --Monochrome_Monitor 04:24, 3 December 2015 (UTC)
- It almost works, but it doesn't just return the cat main. It returns the entire text on the category's page. --Monochrome_Monitor 04:45, 3 December 2015 (UTC)
- Check it out [2]. It's stupid that there's a speedy delete banner on it because I want the module deleted. I don't want the sandbox deleted. --Monochrome_Monitor 04:53, 3 December 2015 (UTC) @Jackmcbarn:
- Silly how you can't keep a subpage like that. Anyway, I truly wish I could tinker and solve it, but I'd have to do tedious research. I simply don't know most of the functions. --Monochrome_Monitor 04:59, 3 December 2015 (UTC)
- Check it out [2]. It's stupid that there's a speedy delete banner on it because I want the module deleted. I don't want the sandbox deleted. --Monochrome_Monitor 04:53, 3 December 2015 (UTC) @Jackmcbarn:
- It almost works, but it doesn't just return the cat main. It returns the entire text on the category's page. --Monochrome_Monitor 04:45, 3 December 2015 (UTC)
- Sweet thanks. --Monochrome_Monitor 04:24, 3 December 2015 (UTC)
- @Monochrome Monitor: You can do
- Sort of like a redirect. --Monochrome_Monitor 14:38, 30 November 2015 (UTC)
- Sure. For the Main template, if it's an article it will display the default string "the main article for this is...", if it's a category it will display "the main article for this catgory is...". But we are supposed to use Cat main, not regular main, for categories, even though the main template can technically display a category-appropriate string. I was wondering if it's possible that main could "replace" itself with cat main (not the module, the template) on the condition that the page is a category. --Monochrome_Monitor 14:37, 30 November 2015 (UTC)@Jackmcbarn:
@Monochrome Monitor: I don't see a speedy delete banner anywhere. Where were you seeing it? Also, since you're using a _main method in your module, frame isn't in scope, so you'll need to either pass it from main to _main, or use local frame = mw.getCurrentFrame()
just before that line. Jackmcbarn (talk) 21:55, 3 December 2015 (UTC)
@Jackmcbarn: Oh, someone resolved that by deleting the main page (therefore deleting the main page's delete template and deleting the sandbox's delete template). It turns out you can delete a page without deleting its subpage. Anyway, I have absolutely no idea what "frame" and "scope" are (did I mention I'm basic at BASIC?), but I'll try it. --Monochrome_Monitor 00:46, 4 December 2015 (UTC)
- Still not working for me :/ [3]
Sorry for the insolence! --Monochrome_Monitor 00:51, 4 December 2015 (UTC)
- @Monochrome Monitor: Can you create and save a page that uses that module, so that I can test it more easily? It's hard for me to debug a module that isn't currently being ran anywhere. Jackmcbarn (talk) 03:09, 4 December 2015 (UTC)
- @Jackmcbarn: Sure thing, I'll make a template. --Monochrome_Monitor 09:01, 4 December 2015 (UTC)
- Assuming that's what you meant. --Monochrome_Monitor 09:02, 4 December 2015 (UTC)
- Oh, a test page. Yeah, I'd need some help with the "function... self:preprocess_equals..." bit. Not sure how to apply it, invoking the module and naming the function the module name isn't working. --Monochrome_Monitor 09:09, 4 December 2015 (UTC)
- @Monochrome Monitor: I don't need a full-fledged testcases page. Just set up some kind of page that uses it. Jackmcbarn (talk) 15:39, 5 December 2015 (UTC)
- @Jackmcbarn: Do I need to make a template for such a thing? Also, perhaps we should move this to one of our talk pages for less pinging and more talk-backing...ing. --Monochrome_Monitor 18:26, 5 December 2015 (UTC)
- @Monochrome Monitor: I don't need a full-fledged testcases page. Just set up some kind of page that uses it. Jackmcbarn (talk) 15:39, 5 December 2015 (UTC)
- Oh, a test page. Yeah, I'd need some help with the "function... self:preprocess_equals..." bit. Not sure how to apply it, invoking the module and naming the function the module name isn't working. --Monochrome_Monitor 09:09, 4 December 2015 (UTC)
- @Monochrome Monitor: Can you create and save a page that uses that module, so that I can test it more easily? It's hard for me to debug a module that isn't currently being ran anywhere. Jackmcbarn (talk) 03:09, 4 December 2015 (UTC)
stripmarkers and mw.text.unstripNoWiki()
Module:Citation/CS1/sandbox uses mw.text.unstripNoWiki()
to to replace nowiki stripmarkers in parameter values that become part of the cs1|2 template metadata. |title=
is one such. This simple cs1 cite, using the current live version:
{{cite book |title=<nowiki>title</nowiki>}}
renders like this:
- title.
and produces this output:
'"`UNIQ--templatestyles-0000001E-QINU`"'<cite class="citation book cs1">''title''.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=title&rfr_id=info%3Asid%2Fen.wikipedia.org%3AWikipedia+talk%3ALua%2FArchive+4" class="Z3988"></span>
where in the metadata is this string:
&rft.btitle=%7FUNIQ--nowiki-00000005-QINU%7F
which shows that the stripmarker is used in the metadata's book title parameter.
Changing to use the module sandbox produces this output because the parameter data are first passed to mw.text.unstripNoWiki()
before assignment:
'"`UNIQ--templatestyles-00000021-QINU`"'<cite class="citation book cs1">''title''.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=title&rfr_id=info%3Asid%2Fen.wikipedia.org%3AWikipedia+talk%3ALua%2FArchive+4" class="Z3988"></span>
where we can see that the metadata are correct:
&rft.btitle=title
If I change the markup in |title=
to use any of <pre>...</pre>
, <gallery>...</gallery>
, or <ref>...</ref>
then the stripmarker isn't removed:
'"`UNIQ--templatestyles-00000025-QINU`"'<cite class="citation book cs1">'''"`UNIQ--ref-00000024-QINU`"'''.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=%7F%27%22%60UNIQ--ref-00000024-QINU%60%22%27%7F&rfr_id=info%3Asid%2Fen.wikipedia.org%3AWikipedia+talk%3ALua%2FArchive+4" class="Z3988"></span> <span class="cs1-visible-error citation-comment"><code class="cs1-code">{{[[Template:cite book|cite book]]}}</code>: </span><span class="cs1-visible-error citation-comment">ref stripmarker in <code class="cs1-code">|title=</code> at position 1 ([[Help:CS1 errors#invisible_char|help]])</span>
which is correct because the module sandbox does not attempt to replace these stripmarkers in the metadata.
But, if I use <math>...</math>
, then I get unexpected results:
'"`UNIQ--templatestyles-00000028-QINU`"'<cite class="citation book cs1">'''"`UNIQ--math-00000027-QINU`"'''.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=MATH+RENDER+ERROR&rfr_id=info%3Asid%2Fen.wikipedia.org%3AWikipedia+talk%3ALua%2FArchive+4" class="Z3988"></span>
and we can see that the metadata are incorrect:
&rft.btitle=%3Cimg+class%3D%22mwe-math-fallback-image-inline+tex%22+alt%3D%22title%22+src%3D%22%2F%2Fupload.wikimedia.org%2Fmath%2Fd%2F5%2Fd%2Fd5d3db1765287eef77d7927cc956f50a.png%22+%2F%3E
Is it not true that mw.text.unstripNoWiki()
should not be replacing math stripmarkers?
I know that the sandbox is receiving a stripmarker because it is visible in the metadata of the live module:
'"`UNIQ--templatestyles-0000002B-QINU`"'<cite class="citation book cs1">'''"`UNIQ--math-0000002A-QINU`"'''.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=MATH+RENDER+ERROR&rfr_id=info%3Asid%2Fen.wikipedia.org%3AWikipedia+talk%3ALua%2FArchive+4" class="Z3988"></span>
Is this a bug? Am I not understanding something about mw.text.unstripNoWiki()
? Is there a complete list of stripmarkers?
References
- ^ title
—Trappist the monk (talk) 23:30, 9 December 2015 (UTC)
- Yep, this is a bug. Per the docs, mw.text.unstripNoWiki should only be replacing nowiki strip markers. Could you file a task for this in Phabricator? — Mr. Stradivarius ♪ talk ♪ 00:56, 10 December 2015 (UTC)
- Actually, don't bother now - I've filed it as phab:T121085. — Mr. Stradivarius ♪ talk ♪ 08:41, 10 December 2015 (UTC)
- Thanks for doing that. It seems to have gotten nowhere though since Editor Anomie peremptorily closed it as 'invlaid' but included a note
I don't know if there's any particular reason that T62799 wanted to use nowiki markers rather than general markers, possibly so it would be passed through Tidy.
- Thanks for doing that. It seems to have gotten nowhere though since Editor Anomie peremptorily closed it as 'invlaid' but included a note
- Editor User:Anomie: If you don't know, shouldn't you find out or ask someone who does know before simply declaring a Phabricator task invalid?
- —Trappist the monk (talk) 14:20, 11 December 2015 (UTC)
- As explained in the task, Scribunto is working properly in unstripping "nowiki" strip markers as opposed to "general" strip markers. The unexpected situation here is because the Math extension is using "nowiki" markers rather than "general" markers. I went to the extra trouble of tracking down when the Math extension started doing that, but tracking down the developers who did it and asking them for a reason is beyond what I care to do. Anomie⚔ 15:22, 12 December 2015 (UTC)
- Thanks for your help in tracking down the issue - I had a feeling that it would be something like that. I agree that this isn't a bug in Scribunto, but I think that being able to access the output HTML from Lua should probably count as a bug somewhere. How about reopening the bug, but filed against the Math extension rather than against Scribunto? — Mr. Stradivarius ♪ talk ♪ 18:33, 12 December 2015 (UTC)
- As explained in the task, Scribunto is working properly in unstripping "nowiki" strip markers as opposed to "general" strip markers. The unexpected situation here is because the Math extension is using "nowiki" markers rather than "general" markers. I went to the extra trouble of tracking down when the Math extension started doing that, but tracking down the developers who did it and asking them for a reason is beyond what I care to do. Anomie⚔ 15:22, 12 December 2015 (UTC)
- —Trappist the monk (talk) 14:20, 11 December 2015 (UTC)
Moving modules
When moving a module called "A" to a module called "B", a redirect should be left at Module:A with the content return require('Module:B')
unless you uncheck the box that says "Leave a redirect behind" (which should no longer be disabled or unchecked by default). Also, Gerrit 146608 should be implemented to allow for redirects in the module namespace. GeoffreyT2000 (talk) 03:33, 13 December 2015 (UTC)
title object getContent()
If a module uses a single instance of title object getContent()
to get the content of the current page and there are multiple instances of the same module in the current page, does getContent()
get the page contents once per page (somewhat akin to how mw.loadData()
works) or once per each {{#invoke:}}
(somewhat akin to how require()
works)?
—Trappist the monk (talk) 11:54, 21 December 2015 (UTC)
- Just once - the content gets cached inside the getContent method. You can see the code here. — Mr. Stradivarius ♪ talk ♪ 14:03, 21 December 2015 (UTC)
Hi! FYI: Module talk:First steps#comments states:
- Module talk:First steps#MW lists the tables and functions of the global "mw" library
- Module talk:First steps#_G lists the tables and functions of the global "_G" library
- Best regards Gangleri also aka I18n (talk) 05:57, 28 December 2015 (UTC)
Problem with getParent()
Hi.... Its the first time that i get an error message "attempt to call method 'getParent' (a nil value)" (de:Wikivoyage:Wikidata/Test Modul:Wikidata2). I am just want to read the arguments. The strange thing is. I use this feature (function: getParameter) in many modules like de:Modul:Wikidata2 and de:Modul:Quickbar2. And in that case on Module de:Modul:Quickbar Ort i get this error message on de:Wikivoyage:Wikidata/Test_Modul:Wikidata2 : Lua-Fehler in Modul:Quickbar_Ort, Zeile 10: attempt to call method 'getParent' (a nil value)... What is different here? Icant see it... The whole test article works fine.. but this one causes an error. Whats the problem with the: local argsParent=Frame:getParent().args
? -- DerFussi 21:04, 28 December 2015 (UTC)
- @DerFussi: I have only had a very quick look but one problem appears to be that
function getParameter
is used in both voy:de:Modul:Quickbar Ort and voy:de:Modul:Wikidata2. The issue is that each is a global function so whichever is defined last will replace the other. The fix is to insert "local" before each. I would also fix the other items which should be local. Let me know if you want me to do that. Johnuniq (talk) 22:13, 28 December 2015 (UTC)- @Johnuniq. I did the changes. To be safe I renamed the function that gets the parameters in eched module. So it is always unique. but its still the same problem. Only voy:de:Modul:Quickbar Ort (our upcoming infobox for towns) causes ths error on de:Wikivoyage:Wikidata/Test Modul:Wikidata2. The other modules are used heavily on this test site and work fine. I have no idea at the moment. -- DerFussi 05:59, 29 December 2015 (UTC) -- one second.. I've just seen.. the error switched over to Wikidata2. Maybe its still this kind of problem.... let me check it... -- DerFussi 06:01, 29 December 2015 (UTC)
- I've found the problem. It was the way I called the function in the Wikidata2 modul. That function expects a frame object. I called it directly with a string variable because i called it from an other object. i will fix it -- DerFussi 06:37, 29 December 2015 (UTC)
- Good, please ping me when you get a result. It appears that everything is under control. It's not a big deal, but there are still a couple of unnecessary globals that I'll clean up if you like. Johnuniq (talk) 06:50, 29 December 2015 (UTC)
- Feel free to do it. The modules are still under construction and I still have a long to-do list. But professional input is always welcome... I am still learning... I will continue working on it after new years eve.... thanks... DerFussi 10:45, 30 December 2015 (UTC)
- Good, please ping me when you get a result. It appears that everything is under control. It's not a big deal, but there are still a couple of unnecessary globals that I'll clean up if you like. Johnuniq (talk) 06:50, 29 December 2015 (UTC)
I did some trivial edits in three modules (my contribs). I didn't look at anything else, but I noticed a couple of points which you might like to consider. In voy:de:Modul:Quickbar Ort, string.lower(key)
only works if key has only ASCII characters. Use the mw.ustring library (which can be quite slow, but that is irrelevant for a couple of usages) for Unicode text.
Assuming an argument is never the Lua false
(it can't be), it is worth getting used to the following style.
-- Rather than this: local value = argsParent[Parameter] if value == nil then value = argsFrame[Parameter] end if value == nil then value = Params[Parameter] end return value -- Lua style is: return argsParent[Parameter] or argsFrame[Parameter] or Params[Parameter]
Johnuniq (talk) 02:50, 31 December 2015 (UTC)
- Thanks for the edits and your suggestion... Happy New Year. -- DerFussi 08:16, 31 December 2015 (UTC)
Raw parameters
I want to parse parameters before the wiki-parser gets to them. Is this a pipe dream? All the best: Rich Farmbrough, 01:20, 3 January 2016 (UTC).
- You can't get raw parameters. The peculiarities that apply to template parameters also apply to the parameters passed to modules. #invoke has the same parameter rules as does a template. For a very special purpose with limited usage, it is possible for a module to read the wikitext of a page, which it could attempt to scan to guess where it was invoked, and could then see the raw wikitext. That's not a viable option. Johnuniq (talk) 03:22, 3 January 2016 (UTC)
- There was a patch proposed to do this, but it was never adopted (and the chances of it being adopted in the future don't look good). In some situations, you can work around it by making users pass in arguments enclosed in
<nowiki>...</nowiki>
tags, and then unstripping the tags using mw.text.unstripNoWiki. That's what Template:Test case nowiki does, for example. — Mr. Stradivarius ♪ talk ♪ 07:46, 3 January 2016 (UTC)- Hm... sounds like a good idea, but I know how difficult getting patches agreed can be. All the best: Rich Farmbrough, 16:03, 3 January 2016 (UTC).
- Hm... sounds like a good idea, but I know how difficult getting patches agreed can be. All the best: Rich Farmbrough, 16:03, 3 January 2016 (UTC).
- Can you give me an example of the "special circumstances"? Not sure it helps here, but nonetheless it might prove useful in certain other cases. All the best: Rich Farmbrough, 16:03, 3 January 2016 (UTC).
- A small module that doesn't have a lot of other things to do seems to be an appropriate restriction. I thought about using the title object
getContent()
to look for variations of the string{{use dmy dates
(accounting for variations in spacing and for the various template aliases) so that Module:Citation/CS1 could automatically adapt date formatting to be in compliance with the article's established date style. For very long lists of cs1|2 templates, the module timed-out before getting all of the citations rendered. Not a good thing. - —Trappist the monk (talk) 16:33, 3 January 2016 (UTC)
- In that case you would want to use a persistent variable across invocations during the same rendering. I assume that's not possible? All the best: Rich Farmbrough, 18:30, 3 January 2016 (UTC).
- Correct. Jackmcbarn (talk) 19:54, 3 January 2016 (UTC)
- In that case you would want to use a persistent variable across invocations during the same rendering. I assume that's not possible? All the best: Rich Farmbrough, 18:30, 3 January 2016 (UTC).
- A small module that doesn't have a lot of other things to do seems to be an appropriate restriction. I thought about using the title object
- There was a patch proposed to do this, but it was never adopted (and the chances of it being adopted in the future don't look good). In some situations, you can work around it by making users pass in arguments enclosed in
- @Rich Farmbrough: I also wanted this ability, but the Parsoid team said no. Jackmcbarn (talk) 19:54, 3 January 2016 (UTC)
Wrapping in nowiki
local p = {}
function p.test(frame)
local string= mw.ustring.toNFC (frame.args[1])
rv = "<nowiki>" .. string .. "<nowiki>"
return rv
end
return p
— Preceding unsigned comment added by Rich Farmbrough (talk • contribs) 09:51, 7 January 2016 (UTC)
- Is there a question here? Is it how to make
string
invisible to MediaWiki? Have you tried:return mw.text.nowiki(rv)
(mw:Extension:Scribunto/Lua_reference_manual#mw.text.nowiki)
- I've not used this so perhaps it doesn't do what you want. There may be other options if you search the Lua reference manual.
- Saved wrong version :)
- The above returns, for example:
- <nowiki>xyzzy</nowiki>
- But substed: [[xyzzy]]
- So the nowikis act very oddly. I'll try what you suggest at some point.
- All the best: Rich Farmbrough, 11:36, 7 January 2016 (UTC).
- You need to preprocess extension tags for them to work properly. (Yes, technically nowiki tags aren't from an extension, but the same principle applies.) This code should do the trick:
local p = {}
function p.test(frame)
local s = mw.ustring.toNFC(frame.args[1])
local rv = frame:extensionTag('nowiki', s)
return rv
end
return p
- The reason that this is necessary is outlined here, and you can find all of the different ways of preprocessing wikitext in the documentation for the frame object. Also, something to watch out for is that
mw.text.nowiki(s)
is not equivalent to usingframe:extensionTag('nowiki', s)
. The former escapes the output with HTML entities, but the latter produces a strip marker. (And finally, be careful about usingstring
as a variable name, as doing so overrides Lua's native string library.) — Mr. Stradivarius ♪ talk ♪ 15:35, 7 January 2016 (UTC)
- The reason that this is necessary is outlined here, and you can find all of the different ways of preprocessing wikitext in the documentation for the frame object. Also, something to watch out for is that
"This"
Is there any concept of "this" in Lua? Such that one could interrogate "this.isRedirect", for example?
All the best: Rich Farmbrough, 22:42, 12 January 2016 (UTC).
- @Rich Farmbrough: Sort of. In functions defined using the colon operator you can access a
self
variable, which is equivalent to the function's invisible first parameter. However, it just acts like an ordinary local variable, so you can reassign it, etc. In anything other than functions using the colon operator, there is no equivalent of "this" that you can access. — Mr. Stradivarius ♪ talk ♪ 23:19, 12 January 2016 (UTC)
New module across many wikis
Hi, I am a bit worried about a user spamming a new module d:Module:Cycling race across many wikis. In my opinion the code is really *bad*, and it seems we are forced to use that module. I have already informed him that I prefer to rewrite it from scratch for itwiki (it will take some time because I am busy the moment). --Rotpunkt (talk) 10:30, 18 January 2016 (UTC)
- Well, it would be nice for the module to have consistent indentation, and on scanning it I also see quite a few instances of redundant code which should be factored out. But most importantly, I can't really tell what the module is supposed to do. Is there some documentation for it somewhere? — Mr. Stradivarius ♪ talk ♪ 10:18, 19 January 2016 (UTC)
- @Mr Stradivarius hi thanks, however it's a mess, it's full of programming errors: the wrong/horrible usage of pcall, see foo/foo2/foo3 (plus variable unexpected_condition ?!?), variables called "var", "uu", the function flag (x, date) full of "if" instead of table, too many problems. Surely for me it take less time rewriting it from scratch. --Rotpunkt (talk) 13:16, 19 January 2016 (UTC)
Merge proposal
I propose that we merge Wikipedia:Lua/Requests to this page. When Scribunto was introduced in 2013, there were an awful lot of templates that needed converting to Lua, and so we had a lot of conversion requests, so having a separate page for requests was probably a good idea. However, at the moment requests for template conversions have all but dried up, so having a separate page is not very useful, and is likely confusing for people who come here to ask questions. I think having one talk page for all Lua-related things would make things easier to manage for both regulars here and people new to Scribunto on this wiki. Let me know what your thoughts are about this. — Mr. Stradivarius ♪ talk ♪ 10:13, 19 January 2016 (UTC)
- Yes that seems like a good idea. Johnuniq (talk) 01:46, 20 January 2016 (UTC)
- +1 All the best: Rich Farmbrough, 00:15, 24 January 2016 (UTC).
How should a merge be implemented? There are five archive pages (total 4K lines, 670K bytes) and a small amount of text at Wikipedia:Lua/Requests. Perhaps we should not bother with a merge, but just archive the current page, put an explanatory box on it with a link to this page, add to the note at the top of this page so there is a link to the old requests, then edit the header to remove "Requests"? Johnuniq (talk) 02:50, 5 February 2016 (UTC)
- I was thinking of archiving the existing threads at /Requests, redirecting the page here, removing "Requests" from the header, and then adding the /Requests archive pages to the archive box. I think redirecting /Requests to here would be the best way, otherwise people may be tempted to keep using it. — Mr. Stradivarius ♪ talk ♪ 05:19, 5 February 2016 (UTC)
- OK, that's a proper merge, and I suggest doing it as soon as convenient. Johnuniq (talk) 06:01, 5 February 2016 (UTC)
- I've done it. I've tried to make the new archive box fairly compact, but it can probably be improved - feel free to tweak it if you want. — Mr. Stradivarius ♪ talk ♪ 07:42, 5 February 2016 (UTC)
- Looks good, thanks. Johnuniq (talk) 08:08, 5 February 2016 (UTC)
- I've done it. I've tried to make the new archive box fairly compact, but it can probably be improved - feel free to tweak it if you want. — Mr. Stradivarius ♪ talk ♪ 07:42, 5 February 2016 (UTC)
- OK, that's a proper merge, and I suggest doing it as soon as convenient. Johnuniq (talk) 06:01, 5 February 2016 (UTC)
Module:IPA/templates
Hello, I get constantly this error mw.lua: 511 and this also [C] and it says there is a language code missing. What can it be the problem with this template? -- Denis Marinov (talk) 22:11, 1 February 2016 (UTC)
- Please provide some background. You link to nl:wikt:Module:IPA/templates which requires nl:wikt:Module:IPA; both were created very recently. Were they copied from wikt:Module:IPA? If copied, there is supposed to be a link to the source in the edit summary. Please create a test page somewhere with some wikitext that demonstrates the problem because it is much easier to work on a problem when you can see it live. Regarding the error, bear in mind that if you have scripting enabled in your browser, you can click the error message to see a little more detail. My guess is that you are using a lang code unknown to mw.lua. See mw:Lua manual#Language library. Johnuniq (talk) 22:46, 1 February 2016 (UTC)
- I'm working on categorizing the IPA pronunciation and de audio links and using therefore the english template. This is the testpage. I understand the problem is with the iso codes. We using in the dutch wiktionary the three letter codes. However, I changed the lang codes on the Module:languages/data2. How can I fix this. I have not create any documentation yet. -- Denis Marinov (talk) 22:57, 1 February 2016 (UTC)
- So the problem is with lang=nld? There seems to be something broken in nl:wikt:Module:languages at function getDataModuleName where local prefix is defined but not used. "nld" gives module "languages/data3/u" but nl:wikt:Module:languages/data3/u does not define anything for nld. I have never worked with IPA so I'm just skimming the Lua code. Johnuniq (talk) 23:30, 1 February 2016 (UTC)
- Yes, but I tried this template also in another wiktionary and its working fine. Because the dutch wiktionary is using the three letter iso codes this gives me an error. We don't have any expert who can solve this and that's why I decided to write hier. -- Denis Marinov (talk) 00:13, 2 February 2016 (UTC)
- If I had a link to a page showing the same wikitext but where the result worked, it would be pretty straightforward to track down the problem. I might be called away for some hours soon, but I'll get around to noticing any reply here. Specifically, have you ever seen nld work somewhere? If so, please link to a page with an example that works. Johnuniq (talk) 00:32, 2 February 2016 (UTC)
- Yes I do have some examples of mine. It's been used on this template for example, by which all words using the template and has an language code in it are categorizing in this category. There you have the three letter codes, such as -nld- or -eng-. But, I did a search and discover that we are using the two letter codes into this template, by which we post the translation using the template:trans-top/midd and bottom. So it is some kind of strange thinking. Is there a bot who actually can fix the three letter codes to a two letter codes by renaming all the templates and the linking pages with it., so we don't have troubles anymore by using other templates. -- Denis Marinov (talk) 11:04, 2 February 2016 (UTC)
- Sorry, I don't understand what is needed. I think you are saying there is no longer a Lua problem. Someone at WP:VPT might have a suggestion about a bot if you could explain exactly what is wanted, with an estimate of how many pages would be involved. Generally people use WP:AWB for routine changes. Johnuniq (talk) 05:02, 3 February 2016 (UTC)
- I solve the problem without modules. It's working fine, the only problem is that we have more than 400.000 words with template:audio en template:IPA linked to them, but there is no language code in the template its self. I was wondering if there is an bot who actually can add the language code into the template in all this 400.000 words. -- Denis Marinov (talk) 12:27, 3 February 2016 (UTC)
- Can the template be changed so it is not necessary to edit 400,000 pages? If the edits are needed, my suggestion would be to make a manual edit that is typical of what is wanted, then write a brief proposal at a central noticeboard at your project where you show the diff of your edit with an outline of what it did and why it is needed. Add your proposal that similar edits should be made at every page using the template (400,000 pages?). Also find people who frequently work with a template similar to yours—that might be at at en wiktionary? Ask them if your proposal is good, or should something else be done, or should something extra be done at the same time. Once the proposal has been accepted, perhaps because there have been no objections after ten days or so, ask for someone to do the changes. I suspect the best place for that would be at en wiktionary because they would be used to the particular template. Failing that, perhaps ask at WP:BOTREQ, making it clear that your request is for another project. If WP:AWB were used, an admin at your project would need to grant AWB access to whoever does the work—I'm not sure how that works, and I think at least one admin would need to agree that the changes should be made to avoid any trouble if someone starts editing 400,000 pages. Johnuniq (talk) 22:03, 3 February 2016 (UTC)
- I solve the problem without modules. It's working fine, the only problem is that we have more than 400.000 words with template:audio en template:IPA linked to them, but there is no language code in the template its self. I was wondering if there is an bot who actually can add the language code into the template in all this 400.000 words. -- Denis Marinov (talk) 12:27, 3 February 2016 (UTC)
- Sorry, I don't understand what is needed. I think you are saying there is no longer a Lua problem. Someone at WP:VPT might have a suggestion about a bot if you could explain exactly what is wanted, with an estimate of how many pages would be involved. Generally people use WP:AWB for routine changes. Johnuniq (talk) 05:02, 3 February 2016 (UTC)
- Yes I do have some examples of mine. It's been used on this template for example, by which all words using the template and has an language code in it are categorizing in this category. There you have the three letter codes, such as -nld- or -eng-. But, I did a search and discover that we are using the two letter codes into this template, by which we post the translation using the template:trans-top/midd and bottom. So it is some kind of strange thinking. Is there a bot who actually can fix the three letter codes to a two letter codes by renaming all the templates and the linking pages with it., so we don't have troubles anymore by using other templates. -- Denis Marinov (talk) 11:04, 2 February 2016 (UTC)
- If I had a link to a page showing the same wikitext but where the result worked, it would be pretty straightforward to track down the problem. I might be called away for some hours soon, but I'll get around to noticing any reply here. Specifically, have you ever seen nld work somewhere? If so, please link to a page with an example that works. Johnuniq (talk) 00:32, 2 February 2016 (UTC)
- Yes, but I tried this template also in another wiktionary and its working fine. Because the dutch wiktionary is using the three letter iso codes this gives me an error. We don't have any expert who can solve this and that's why I decided to write hier. -- Denis Marinov (talk) 00:13, 2 February 2016 (UTC)
- So the problem is with lang=nld? There seems to be something broken in nl:wikt:Module:languages at function getDataModuleName where local prefix is defined but not used. "nld" gives module "languages/data3/u" but nl:wikt:Module:languages/data3/u does not define anything for nld. I have never worked with IPA so I'm just skimming the Lua code. Johnuniq (talk) 23:30, 1 February 2016 (UTC)
- I'm working on categorizing the IPA pronunciation and de audio links and using therefore the english template. This is the testpage. I understand the problem is with the iso codes. We using in the dutch wiktionary the three letter codes. However, I changed the lang codes on the Module:languages/data2. How can I fix this. I have not create any documentation yet. -- Denis Marinov (talk) 22:57, 1 February 2016 (UTC)
We have fixed the categorisations without any using of Modules. We create also an bot to add the langcode into the template. -- Denis Marinov (talk) 12:07, 15 February 2016 (UTC)
Title of template that called template that did invoke
I'm writing a module to replace {{Football manager history}} which is used by over 1000 navboxes. If a navbox has invalid parameters, the module should report the title of the navbox to simplify finding the page with the problem.
Consider this example:
- Navbox {{America Football Club managers}} uses {{Football manager history/sandbox}}
- {{Football manager history/sandbox}} invokes Module:Football manager history
Suppose {{America Football Club managers}} has an invalid parameter. Can the module find the title Template:America Football Club managers? Using [[frame:getParent():getTitle()]]
returns "Template:Football manager history/sandbox" as expected and it is does not appear to be possible to get the parent of the parent. Johnuniq (talk) 04:35, 11 February 2016 (UTC)
- You could consider using Module:TemplatePar in each. I'm not sure if that could solve the question. -DePiep (talk) 08:10, 11 February 2016 (UTC)
- Hmmm, that is quite a sophisticated module. I'll have to look at it later, thanks. Johnuniq (talk) 09:15, 11 February 2016 (UTC)
- You could consider using Module:TemplatePar in each. I'm not sure if that could solve the question. -DePiep (talk) 08:10, 11 February 2016 (UTC)
- No, the grandparent frame isn't available, and that's by design. There was a patch to expose all of the ancestor frames, but it hasn't been deployed due to worries that it might lead to hacky code. The only way of doing this at the moment is to have {{America Football Club managers}} pass in its title as a parameter. You could use
frame:getParent():getTitle()
in a special module in the {{America Football Club managers}} template invocation to pass the title to such a parameter, and this would avoid having the wrong template name after page moves, etc., but personally I think that is hackier than allowing multiple ancestor frames. — Mr. Stradivarius ♪ talk ♪ 08:53, 11 February 2016 (UTC)- Thanks. I would have thought that at least the titles of items in the call stack could be made available for a case like this. I have to edit the navboxes anyway, so I was thinking of adding
|caller = {{FULLPAGENAME}}
so the module can use the parameter (if given) to link to a navbox with an error. Johnuniq (talk) 09:15, 11 February 2016 (UTC)- Ah, I didn't mean template invocation, sorry. I meant in the actual template code itself. That is, {{America Football Club managers}} would look something like this:
- Thanks. I would have thought that at least the titles of items in the call stack could be made available for a case like this. I have to edit the navboxes anyway, so I was thinking of adding
{{Football manager history/sandbox |name = {{#invoke:Title of this template|main}} ... }}
- The module invoked by
{{#invoke:Title of this template|main}}
would return the result offrame:getParent():getTitle()
, which would produce "Template:American Football Club managers" whatever page the template is transcluded on. This would give you a more useful result than{{FULLPAGENAME}}
, but it feels like too much of a hack for me to try and use it myself. — Mr. Stradivarius ♪ talk ♪ 09:53, 11 February 2016 (UTC)- I was suppressing a worry at the back of mind about what FULLPAGENAME might be referring to. I guess you are saying that it's useless for my purpose as it shows the page where the error is occurring, not the title of the template which contains FULLPAGENAME. That's sounding obvious now that I spell it out. Your fix is ingenious but, like you, I probably won't want to try it, but thanks for the guidance. Johnuniq (talk) 10:42, 11 February 2016 (UTC)
- Yes, that's right. FULLPAGENAME always refers to the page that the user is viewing, which isn't what you want here. — Mr. Stradivarius ♪ talk ♪ 11:36, 11 February 2016 (UTC)
- I was suppressing a worry at the back of mind about what FULLPAGENAME might be referring to. I guess you are saying that it's useless for my purpose as it shows the page where the error is occurring, not the title of the template which contains FULLPAGENAME. That's sounding obvious now that I spell it out. Your fix is ingenious but, like you, I probably won't want to try it, but thanks for the guidance. Johnuniq (talk) 10:42, 11 February 2016 (UTC)
- The module invoked by
OK, I'm an idiot. It turns out that the navboxes I'm working on already have a "name" field, and it is the name of the template. I found an example where that was not the case and assumed that "name" was some option that could be anything. I have now found it is not optional because it is passed to {{navbox}} to make the V·T·E links. The case where the name did not match the template title was due to the template having been moved. However, it's only good luck that such a field was available, and in general I think mw should provide a function to get the title of the grandparent. Johnuniq (talk) 11:15, 12 February 2016 (UTC)
or
- or. So you want to 'report' the name of the broken navbox by its template name. Is that report a message on the (article) page? Or does it categorise? Anyway, this is a different route and skipping the problem:
- 1. Navboxes that are broken (i.e., have structural encoded parameter error) are listed in say "Category:Navboxes with wrong application of Template:Football manager history". Of course a namespace-check is used for this; it's reporting navbox pages in their template-space. (Could be extended to all templates using Template:Football manager history).
- 2. Articles that have bad input for parameters are listed in "Category:Articles that have bad input for Football manager history in navbox".
- To consider: when reporting the navbox name by categorising, the offending article pagename is not in sight (not even clickable or by label). -DePiep (talk) 12:16, 12 February 2016 (UTC)
- The problem is that there are many articles where a lot of "history" navboxes appear, for example, Vanderlei Luxemburgo#External links. My module parses the input and displays a navbox if it is valid, or an error if not. A simulated example of how the error appears is here (at bottom). The error has a link to the template with the problem which is very useful when there are a lot of navboxes on a page. As you know {{convert}} displays a subtle error message that is often missed when editors adjust converts. That's not a problem because someone fixes it from the tracking category. However I decided to display a big error for the navboxes to make it more likely that the editor will see and fix the problem. Almost all of the navboxes are collapsed so the error is usually not visible in articles. Johnuniq (talk) 23:44, 12 February 2016 (UTC)
- TL;DR. -DePiep (talk) 00:47, 13 February 2016 (UTC)
- Well I read it. :P That sounds like a good way of doing things. If the template name is available it will be useful to have in the error message, as it makes it more immediately obvious where the problem is so that the editor who caused the error can find and fix it more easily. — Mr. Stradivarius ♪ talk ♪ 11:36, 13 February 2016 (UTC)
- TL;DR. -DePiep (talk) 00:47, 13 February 2016 (UTC)
- The problem is that there are many articles where a lot of "history" navboxes appear, for example, Vanderlei Luxemburgo#External links. My module parses the input and displays a navbox if it is valid, or an error if not. A simulated example of how the error appears is here (at bottom). The error has a link to the template with the problem which is very useful when there are a lot of navboxes on a page. As you know {{convert}} displays a subtle error message that is often missed when editors adjust converts. That's not a problem because someone fixes it from the tracking category. However I decided to display a big error for the navboxes to make it more likely that the editor will see and fix the problem. Almost all of the navboxes are collapsed so the error is usually not visible in articles. Johnuniq (talk) 23:44, 12 February 2016 (UTC)
Question: how to determine if template is lua-based Navbox?
I'm writing a script that searches for any Navbox templates (eg. {{Protestant missions to Africa}}). It's trivial to check in this case since https://en.wikipedia.org/wiki/Protestant_missions_to_Africa?action=raw returns the script source which says "{{Navbox" at the top. The problem is if the template is written in Lua. Is there a way to identify a Lua script as being a Navbox? -- GreenC 15:59, 15 February 2016 (UTC)
- To answer my own question, it looks like Lua modules that are Navbox use Module:Navbox so it would be possible to check the source for that string. Assuming all Navbox (written in Lua) use Module:Navbox. -- GreenC 16:08, 15 February 2016 (UTC)
- seems like a very roundabout way of getting the information, which should be readily available via the API. look at Special:WhatLinksHere/Module:Navbox, and limit the output to "Template" namespace. the same information is available via the API. same goes for templates using Special:WhatLinksHere/Template:Navbox: use "whats links here" from the menu or via the API. קיפודנחש (aka kipod) (talk) 16:25, 15 February 2016 (UTC)
- Have you used the backlinks API? Transclusions for Module:Navbox:
- It has 2.1 million entries and would require 4500 API calls at 500 names each to pull the full list. I would probably set a high maxlag and let it run overnight to be polite. You said it's possible to only pull template namespace but it doesn't seem to work using &einamespace=template - but what I am trying to find is other Modules that use Module:Navbox - without pulling the full 2.1 million list. In any case I've simply solved the problem by pulling the module source when my script comes across it and caching the results (and only in certain cases eg. "^{{[^}]*}}" -- it's not grabbing the source of every template on the page). -- GreenC 23:03, 15 February 2016 (UTC)
- seems like a very roundabout way of getting the information, which should be readily available via the API. look at Special:WhatLinksHere/Module:Navbox, and limit the output to "Template" namespace. the same information is available via the API. same goes for templates using Special:WhatLinksHere/Template:Navbox: use "whats links here" from the menu or via the API. קיפודנחש (aka kipod) (talk) 16:25, 15 February 2016 (UTC)
- I don't think a list of navbox templates would be useful because there are far too many for comprehension. If you try something, a useful check would be Template:America Football Club managers which uses Template:Football manager history which invokes Module:Football manager history which calls Module:Navbox. Johnuniq (talk) 21:58, 15 February 2016 (UTC)
- The purpose of the script is not to make a list of Navtemplates, that's one piece if information it needs to know (specifically concerning where to place new External links sections which need to be above Navboxes). -- GreenC 23:03, 15 February 2016 (UTC)
- I did not mean a list that people would read—my point is that the number of templates is enormous and is unlikely to be useful for any process. Why would there be a need to place new external links sections using an automated process? They generally are not a good idea as they attract spam, and should only be used if there good information is available. Johnuniq (talk) 23:18, 15 February 2016 (UTC)
- Green Cardamom, from your 23:03 post I understand you want to know: "This is template. Is it a navbox?" (specifically to determine whether to put some addition by requirement above or below any navbox, fine). But, your OP asks for determination whether any navbox is Lua-based. That would exclude any parser-composed (=non-Lua) navbox for consideration (while that belongs within the proposed usage). Are parsed-navboxes already solved differently?
- re #2: On the whole, isn't being a navbox set by one thing only:
class="navbox"
? (note: that would include like {{Authority control}}). -DePiep (talk) 10:16, 16 February 2016 (UTC)- For #1 wikisource has "Navbox" (eg. {{BaltimoreMayors}}) which I presume is a universal usage. For #2 (when the template has a #include) I hadn't thought of looking at the HTML source that would work and get it all done in a single search without concern of the template's source language. A better solution. Thanks! -- GreenC 18:43, 16 February 2016 (UTC)
- I did not mean a list that people would read—my point is that the number of templates is enormous and is unlikely to be useful for any process. Why would there be a need to place new external links sections using an automated process? They generally are not a good idea as they attract spam, and should only be used if there good information is available. Johnuniq (talk) 23:18, 15 February 2016 (UTC)
- The purpose of the script is not to make a list of Navtemplates, that's one piece if information it needs to know (specifically concerning where to place new External links sections which need to be above Navboxes). -- GreenC 23:03, 15 February 2016 (UTC)
- It sounds like Parsoid will do what you want. In your script you could grab the parsoid-formatted HTML DOM, search for templates containing
class="navbox"
, add the external links as HTML elements after those templates, and then convert the whole lot back to wikitext. This "grab the DOM, process it, and convert to wikitext" process is similar to what VisualEditor does when you edit a page. Unfortunately, I'm not aware of any good documentation for how to do it from a user script. (If anyone knows of any, please share!) — Mr. Stradivarius ♪ talk ♪ 10:46, 16 February 2016 (UTC)
- There might be an API to access HTML DOM. There is the TextExtract extension:
- I can regex the HTML source to determine if it contains
class="navbox"
- the actual writing of the wikisource is a different process it just reads the original source line by line, writes it back out with the new code inserted at a predetermined line number. Not doing anything complex enough to need Parsoid conversion process. -- GreenC 20:15, 16 February 2016 (UTC)- @Green Cardamom: tl;dr - just one thing: you asked "You said it's possible to only pull template namespace but it doesn't seem to work using &einamespace=template". i believe the "&einamespace=" expects namespace IDs, not names, so you probably want to try with &einamespace=10. you can ask for more than one namespace, in which case you delimit the IDs with vertical bars. you probably want to play at Special:ApiSandbox to play with the input and output of the API. HTH - קיפודנחש (aka kipod) (talk) 21:34, 16 February 2016 (UTC)
- @קיפודנחש: Ok good to know. Found the list of codes. I tried this API call ie. find backlinks for Module:Navbox in the Module namespace - and got a few results but not expected ones:
- https://en.wikipedia.org/w/api.php?action=query&list=backlinks&bltitle=Module:Navbox&blredirect&bllimit=250&continue=&blfilterredir=nonredirects&blnamespace=828&format=json&utf8=1&maxlag=5
- (transclusions) https://en.wikipedia.org/w/api.php?action=query&list=embeddedin&einamespace=828&eititle=Module:Navbox&continue=&eilimit=500&format=json&utf8=1&maxlag=5
- I'm guessing because when a module is used within Lua source it is not included in the backlink database. -- GreenC 01:14, 17 February 2016 (UTC)
- @קיפודנחש: Ok good to know. Found the list of codes. I tried this API call ie. find backlinks for Module:Navbox in the Module namespace - and got a few results but not expected ones:
- @Green Cardamom: tl;dr - just one thing: you asked "You said it's possible to only pull template namespace but it doesn't seem to work using &einamespace=template". i believe the "&einamespace=" expects namespace IDs, not names, so you probably want to try with &einamespace=10. you can ask for more than one namespace, in which case you delimit the IDs with vertical bars. you probably want to play at Special:ApiSandbox to play with the input and output of the API. HTH - קיפודנחש (aka kipod) (talk) 21:34, 16 February 2016 (UTC)
Would you agree to become French users' idol?
Hello there! Manpower is lacking on the French Wikipedia to intervene on Lua-based templates. Some requests that seem quite simple to deal with lay unanswered because the single person who designed most of them is now mostly active on Wikidata, is busy and does not always answer all our messages there. Is there someone here who would like to help? One simple thing we may like, for instance, is getting fr:Modèle:Infobox Biographie2 to display the data extracted from Wikidata with capital first letters instead of only small ones! This problem has been there for months and I think it's time to call someone from outside! Thierry Caro (talk) 12:44, 16 February 2016 (UTC)
- Can you give me an example? All the best: Rich Farmbrough, 15:17, 22 February 2016 (UTC).
- Do you mean how Fr:Jacques Derrida has "Nationalité française" instead of Nationalité Française"? All the best: Rich Farmbrough, 15:27, 22 February 2016 (UTC).
- Yes, this was what I meant. But suddenly we have two skilled users who are back and we have manpower again! So I guess we won't need you as badly as I was suggesting, even if of course any help would be appreciated! Thank you Rich. I'll come back to you if we are left alone again! Thierry Caro (talk) 19:52, 26 February 2016 (UTC)
External links
Hi guys! I have written one small module External link ID, that should help to ease some things.
- As there is a lot of crap in those external link templates (like this one) out there, we should do some format validation, which I attempted to do in this module
- We should centralise and simplify, how values from Wikidata are taken. In module, I tried to accomplish two things: retrieving value from Wikidata and value comparing here and on Wikidata. Value comparing currently is done here.
As I'm not a Lua coder and programmer (of any language), the module most probably contains some logic and other type of errors. And it can be simplified. And of course it can be expanded, I have some other ideas (like ranking values from Wikidata and getting the best one), but my knowleadge is a little bit limited. I did some basic testing here, almost everything is working, but maybe the approach isn't the best. Those checkWD
and checkF
are meant to be categories, but currently I left them as strings for simplier testing.
I'm looking at you Lua coders to probably develop the module, so that eventually we could have less 404s. If the module itself is too bad and it would be better to write it from scratch, I'm OK with that, but for learning purposes I would like to see how I should have done. You could get extra points for loading Wikidata entity once per page, not once per module invocation. I assume, it is possible. --Edgars2007 (talk/contribs) 11:05, 23 February 2016 (UTC)
- I've had a go at improving it a bit - let me know if you have any questions about what I've done. Also, I think we should think of a clearer parameter name than "param" - maybe "link" would be better? Or maybe allow both "link" and the first positional parameter. Best — Mr. Stradivarius ♪ talk ♪ 02:31, 24 February 2016 (UTC)
- Is that the same module? :) rhetorical question, of course Thanks for the changes. Yes, we can give a better name to
|param=
, I'm pretty bad at naming things. Don't think "link" would be the best choice, because the final value for|param=
is the ID itself, not the whole URL. - Things to include:
- namespace detection. By default, categories should be added only for articles, but maybe some template will want to add it for other namespaces
- would be nice to include rank (getRank at Module:Official website)
- we would also need something like
|catbase=
from Module:WikidataCheck for WD-related categories - category for case, when no ID is provided in Wikipedia or Wikidata
- --Edgars2007 (talk/contribs) 18:02, 26 February 2016 (UTC)
- Is that the same module? :) rhetorical question, of course Thanks for the changes. Yes, we can give a better name to
Extra line
Hi guys! I adapted authority control template for films, but I have one small problem. It generates extra new line before it. Yes, it is very minor issue, but I would like to resolve it. Can't find anything in code, that could cause it. Can somebody take a look? Oh, you can see extra blank line at ExpandTemplates with such input:
one {{Filmu ārējās saites|imdb=12345}} two
--Edgars2007 (talk/contribs) 08:26, 5 March 2016 (UTC)
- @Edgars2007: This is due to phab:T14974, a notorious bug that's been open since 2008. It affects output from all templates and parser functions, including #invoke. Unfortunately, there's nothing you can do to prevent it, except by not outputting a string beginning with
*
,#
,:
,;
or{|
. — Mr. Stradivarius ♪ talk ♪ 08:36, 5 March 2016 (UTC)- OK, thanks, Mr. Stradivarius. --Edgars2007 (talk/contribs) 08:39, 5 March 2016 (UTC)
- So the problem is from an opening * (asterisk). I don't know if it helps in here, but for a color-numbering template I made (that should return like
#0B22AF
; the tricky opening character being #), I applied: template returns#0B22AF
. Ends up OK in the browser. -DePiep (talk) 18:42, 5 March 2016 (UTC)
- So the problem is from an opening * (asterisk). I don't know if it helps in here, but for a color-numbering template I made (that should return like
- OK, thanks, Mr. Stradivarius. --Edgars2007 (talk/contribs) 08:39, 5 March 2016 (UTC)
Lua? or mw.html parsing of nowiki tags?
I got a question about Template:Photomontage and Module:Photo montage: is it possible to make this Template automatically adjust the heigh of images by cropping the highest to the level of lowest one? I primaly use this template to make rich city-related collages. This template tries to render all images with equal width of all images in row. Sometimes aspect ratio of different images is not the same and as a Result I got an empty space around the lower image which makes the whole collage not so attractive as it could be.
--Orange-kun (talk) 15:18, 12 March 2016 (UTC)
- @Orange-kun and Frietjes: You can't crop images from templates or from Lua, but you can adjust the size. Normally size is specified by a number of pixels followed by "px" in the file link, e.g.
[[File:Example.png|150px]]
. This specifies the image width. However, if you usex150px
rather than150px
then it specifies that the image should be 150 pixels high, rather than 150 pixels wide. This is core MediaWiki functionality, and doesn't require Lua. (More details at Wikipedia:Extended image syntax#Size.) However, if you want to get fancy, you could find the width and height of each of the images from the file metadata in the images' title objects, and use that as the input for an image-sizing algorithm. — Mr. Stradivarius ♪ talk ♪ 15:50, 12 March 2016 (UTC)- Mr. Stradivarius, Orange-kun, for an example of the fancy option, see Template:Multiple image. for an example of cropping images, see Template:CSS image crop. of course, neither of these has been implemented in module:photo montage yet. I could see porting the method used by template:multiple image, but haven't had time to do so (yet) since it seems like we could just use template:multiple image instead in those cases. Frietjes (talk) 15:55, 12 March 2016 (UTC)
Module:Authority control
I am not sure if this is the right place to post such a request but I recently did some work on some sandbox changes for this module and after testing, requested the changes be applied to the protected module and an admin requested I "get someone else familiar with the module to double-check your code". If you are familiar with this module and are so inclined, please weigh in on this here: Template talk:Authority control#Switch WorldCat links to using VIAF over LCCN. Thank you. 15.65.244.12 (talk) 00:29, 15 March 2016 (UTC)
- It looks like my changes were already deployed. Thanks anyway. 15.65.244.12 (talk) 00:36, 15 March 2016 (UTC)
Help using sandbox
This is my first attempt at creating a Lua module.
I created a module, Module:Zodiac date after debugging in my user sandbox. I created a sandbox version of an infobox, Template:Infobox zodiac/sandbox. In that infobox, I modified the lines that gets the dates as shown:
Before:|data2 = {{zodiac date|{{{nr|1}}}}} ({{CURRENTYEAR}}, [[UTC]])
After: |data2 = {{#invoke:Zodiac date|main|{{{nr|1}}}}} ({{CURRENTYEAR}}, [[UT1]])<ref>{{citation|publisher = US Naval
I placed copies of all the infobox instances from the astrological sign articles in my main sandbox and it works great.
But I also wanted to check it out with the special sandbox invocation page. So, I put an exact copy of the module in User:Jc3s5h/sandbox/Module:Zodiac date. Then back on the the special sandbox invocation page page I filled in "User:Jc3s5h/sandbox" for the sandbox prefix, "Module:Zodiac date" for the Renderer page, and {{#invoke:Zodiac date|main|11}} for the Render wikitext. I get an error message, "Script error: Lua error at line 1: unexpected symbol near '{'. "
Can someone explain why it works with the sandbox infoboxes but not from the special sandbox invocation page?
The module seems ready to go, but I'd like to clear up this discrepancy before I make it live. Jc3s5h (talk) 19:32, 23 March 2016 (UTC)
- Is it not true that modules can only run in the Module: namespace? If that's true then attempting to
{{#invoke:}}
a module that lives in your User: namespace won't work. I've never used the Special:TemplateSandbox so have no experience with it. Could you create special templates that live in your User: namespace and that{{#invoke:}}
the main (or a sandbox version) of the module in Module: namespace? - —Trappist the monk (talk) 01:07, 24 March 2016 (UTC)
- As TTM says, a module can only be invoked if it is in the Module namespace. See Module:Sandbox/... for examples of what people do. I made a bold edit (diff). Revert it if you like but it's best to get used to Lua's "a or b" style which is a very convenient way of handling nil values. The edit corrected a glitch in that signNumber might have been nil in the original, which would have been a run-time error when it was used for arithmetic. I didn't see a page where I could check I hadn't broken anything (and failed to properly read the OP!). I'll add some quick tests here, although I do not know what the results should be.
{{#invoke:Zodiac date|main}}
→ March 20 – April 19{{#invoke:Zodiac date|main||2016}}
→ March 20 – April 19{{#invoke:Zodiac date|main|1}}
→ March 20 – April 19{{#invoke:Zodiac date|main|1|2016}}
→ March 20 – April 19{{#invoke:Zodiac date|main|3|2015}}
→ May 21 – June 21{{#invoke:Zodiac date|main|3|2001}}
→ Error: Only 2015-2050 (except Capricorn 2050) are supported.
- When editing the module, you can put a title in the box under "Preview page with this module" at the bottom. For example, put
Wikipedia talk:Lua
in that box, then click Preview. That will show the results of the edit on the examples above. Johnuniq (talk) 02:07, 24 March 2016 (UTC)- Thanks. I'll look at some of the links later. The values generated in Johnuniq's post are correct. Jc3s5h (talk) 02:28, 24 March 2016 (UTC)
Template:Infobox needs formatting tweak
[I first reported this at Template_talk:Infobox#Minor_bug but that page is always drowning in content-related RfCs and other disputes, and it's gone unnoticed, so I'll try here.]
If you add |bodyclass=mw-collapsible
to Template:Infobox or any infobox derived from it (or have your user JavaScript inject that class), the "[hide]" tool is run directly up against the heading text; there needs to be some spacing in there with padding
or margin
. The "[hide]" should also be made notably smaller. I've provided a demo to the right. — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼ 09:32, 6 March 2016 (UTC)
- Hmm, I suppose we could add some default padding, but I suspect the best way may be to add a rule for "[hide]" links inside infoboxes in MediaWiki:Common.css. @Edokter: perhaps you have an opinion on this? And SMcCandlish, do you have any examples of this being used in the wild? — Mr. Stradivarius ♪ talk ♪ 13:06, 24 March 2016 (UTC)
- Not in templates themselves, but it's a chicken-and-egg problem. It looks so terrible at the moment that no one would turn it on as an option rendered by the template right now. I, and surely a lot of people who don't always or ever want to see infoboxes (in my case, I want to make them go away on mobile when I'm done skimming them or don't want to) enable this feature with user JS & CSS. While I'm competent to futz my own CSS around to compensate for the problem, most are not, so it should be fixed on the outbound side. — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼ 16:59, 24 March 2016 (UTC)
- Some options: I can add some space; pushing the caption slightly to the left, or I can make it float right (my preference); the caption would stay off-centre as it is now. I think most templates needs some minor tweaking to handle mw-collapsible.
-- [[User:Edokter]] {{talk}}
18:03, 24 March 2016 (UTC)- Float right, and some size reduction (see, e.g., size at Template:Cue sports nav) works for me, though the "[hide]"/"[show]" thing itself will need a small bit of left padding or margin to prevent it mashing up against the real content in cases where the content is just long enough that the browser wants to fit them both on the same line without any space between them. Re: "I think most templates need some minor tweaking to handle mw-collapsible" – definitely, and I started with this one. :-) When it works really well I want to propose that this be a feature added by default like we do on navboxes and various other things, to help bring an end to "the Infobox Wars" (people fighting to keep them out of entire large categories of articles, a years-long drama that's alerady spawned ARBCOM cases and despite the rulings in them has continued unabated). — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼ 18:15, 24 March 2016 (UTC)
- Some options: I can add some space; pushing the caption slightly to the left, or I can make it float right (my preference); the caption would stay off-centre as it is now. I think most templates needs some minor tweaking to handle mw-collapsible.
- Not in templates themselves, but it's a chicken-and-egg problem. It looks so terrible at the moment that no one would turn it on as an option rendered by the template right now. I, and surely a lot of people who don't always or ever want to see infoboxes (in my case, I want to make them go away on mobile when I'm done skimming them or don't want to) enable this feature with user JS & CSS. While I'm competent to futz my own CSS around to compensate for the problem, most are not, so it should be fixed on the outbound side. — SMcCandlish ☺ ☏ ¢ ≽ʌⱷ҅ᴥⱷʌ≼ 16:59, 24 March 2016 (UTC)
mw.title.new(id)
This url points to an old version of Aristotle:
I want to get the unparsed contents of that old version.
I can read the unparsed contents of the current version of Aristotle with this:
page_title_object = mw.title.new(frame.args[1]); text = page_title_object:getContent();
- where
frame.args[1]
is 'Aristotle' – this is what{{ref info}}
is doing
If I take the id number from the url above and do this:
page_title_object = mw.title.new(frame.args[2]); text = page_title_object:getContent();
- where
frame.args[2]
is '437984170'
or hardcode the id:
page_title_object = mw.title.new('437984170'); text = page_title_object:getContent();
then, in both cases, page_title_object
is not nil
but text
is nil
. If, as a test, I write text = page_title_object:fullUrl()
to get the full url of the title object I get:
//en.wikipedia.org/wiki/437984170
which explains why page_title_object:getContent()
returns nil
: no article by that title.
If I write page_title_object = mw.title.new(tonumber(frame.args[2]))
or mw.title.new(437984170)
(both cases now, id as a number) page_title_object
is nil
.
TLDR: I want to get the unparsed contents of older version of an article. Can I? How?
—Trappist the monk (talk) 19:03, 29 March 2016 (UTC)
- i think the problem here is misunderstanding what "id" means. you seem to assign to it a meaning of "revision id", and i think it really means "page id". the page id (as shown in the "page information" box), does not pertain to any specific revision, and creating a title using ID will not give you any advantage over creating it with the page name - in both cases you'll get the "title" object, which is not tied to any specific revision, and calling getContent() will always return latest version of the page. specifically, enwiki does not have a page with id of 437984170 ( //en.wikipedia.org/w/index.php?curid=437984170 links to "bad title"), and per the spec, when a title object points to a non-existing page, getContent() returns nil. if you try it with some existing page, i'm sure you'll get non-nil results (tbh, i didn't try it...), but from your description, this is probably not what you really need...
- it may be possible to get specific version of a page using some tricks, e.g., asking to parse some special page, e.g. Special:Diff (which let's you compare revisions of two different pages - all you have to do is find one revision of of one page which is completely empty, ad diff anything else against this revision, or maybe there's special page for specific page revision - i vaguely remember something like this, but i can't find it anywhere), but i think the result will probably be parsed and not raw content.
- my shoot-from-the-hip response is that if you need to do anything with specific revisions, maybe lua/scribunto is the wrong tool, and you'd be better off using something else to achieve your goal (btw: what _is_ your goal here?) peace - קיפודנחש (aka kipod) (talk) 22:58, 29 March 2016 (UTC)
- There is a 'discussion' going on at WT:CITE (actually more than one) where editors are having it out over the meaning of CITEVAR. It occurred to me that there isn't a tool that can give editors a quick overview of the state of an article's referencing. I hacked together Module:Ref info and
{{ref info}}
which together extract counts of various objects related to referencing: named, unnamed, self-closed<ref>...</ref>
tags, cs1|2 templates, harv and sfn templates, and the like. An editor in one of those discussions suggested that the ability to compare past versions of an article to the current version would be beneficial. So that's why I want to do it.
- There is a 'discussion' going on at WT:CITE (actually more than one) where editors are having it out over the meaning of CITEVAR. It occurred to me that there isn't a tool that can give editors a quick overview of the state of an article's referencing. I hacked together Module:Ref info and
- I too remember a Special oldid page or at least I think I do.
- —Trappist the monk (talk) 23:24, 29 March 2016 (UTC)
- The ability to get parsed content from special pages was removed a while back, and if there are any ways left of getting stuff like that, it is likely to be considered a bug, so I wouldn't rely on it. And there's no official way to fetch information about old revisions using Scribunto. This is by design, as the Scribunto creators wanted to keep page parsing as fast as possible, and allowing people to include information about old revisions could slow that down considerably. It sounds like this project might be best implemented as a JavaScript gadget, as users will still be able to run it from their browsers, and with JavaScript you can easily fetch old revisions through the API. You can even use the API to call your module, so if you adapt it to export a function that accepts arbitrary wikitext as an argument then you can use your existing code to parse the references. — Mr. Stradivarius ♪ talk ♪ 00:10, 30 March 2016 (UTC)
- The special page is
[[Special:Permalink/RevId]]
according to Help:Permanent_link but it sounds as though that is not useful here. DES (talk) 00:17, 30 March 2016 (UTC) - I just tried executing
mw.title.new('Special:PermanentLink/437984170')
and it returns nil, so the bad news from Mr. Stradivarius is confirmed. Johnuniq (talk) 01:01, 30 March 2016 (UTC)
Well, bother! Ok, thank you all. —Trappist the monk (talk) 11:02, 30 March 2016 (UTC)
Template parameters validation
One of the issues plaguing media-wiki, is the sub-optimal template design. i estimate that maybe 30% of discussions in WP:VPT are questions, answers, and problems in and around templates.
One of the deficiencies with the template system is lack of any "syntax check": when editors fill in parameters, there is no control that the parameters they feed into the template are the ones the template actually needs: for instance, if a template uses parameter "Face width", and the editor fills in "Face Width", or "Face wide", or any other mistake, there is no indication. Errors around extra or missing "=" and "|" characters are all over the place, and so on.
With the introduction of Visual Editor, a new (optional) feature was added, called "templatedata". This extension provides, for the first time, a way to define meta-data related to the template, including listing the parameters, with some attributes, such as "required" and "deprecated".
In hewiki we built, and in the process of testing and integrating, a system that utilizes the templatedata metadata via scribunto, to add parameter validation.
This system is a 2nd generation of another system, created by User:IKhitron, which used special subpages created to provide the metadata, before we figured out how to consume templatedata in a Lua module. You can read the code of the first-generation system in he:Module:פרמטרים history. The metadata required for this system is contained in subpages of this modul - one subpage per template.
I will describe the 2nd-generation system here, with links to the lua modules involved:
- A module for reading tempaltedata: he:Module:ReadTd. It's main function returns the tempaltedata as a lua structure, utilizing title:getContent() and mw.text.jsonDecode(). This module is short and sweet (most of its work is accomplished by the above scribunto functions). If nothing else, I'd suggest either copying it here, or rolling an independent one providing the functionality.
- A module that validates the parameters passed to the template, using templtedata obtained using the previous module: he:Module:ParamValidator.
Templates are not validated by default: in order to start validating a template, it must contain correct templatedata, and one has to place
{{#invoke:ParamValidator | validateParams }}
somewhere in the template page, in the included part (usually under "includeonly" tag).
The validateParams() function obtains the metadata, and gains access to the parent (i.e., the template) frame. it then validates the parameters, generating separate lists, for each of the following error conditions:
- Failure to obtain templatedata (obviously, when this error occurs, none of the next conditions can be tested)
- Named undeclared parameter, with value ("undeclared" means does not appear in TD)
- Named undeclared parameter, with empty value
- Numeric ("ordered") undeclared parameter, with value
- Numeric ("ordered") undeclared parameter, with empty value
- Parameter marked as "required" in TD is missing or has empty value
- Parameter marked as "deprecated" in TD, with value
- Parameter marked as "deprecated" in TD, with empty value
- More than one of the above errors occurred
- At least one of the above errors occurred
For each of these error condition, we define a string. typically, this string can be an message to be displayed on the page, a maintenance category or categories, both, or none.
When any of these errors detected in an invocation or the template, validateParams() takes the corresponding string, replaces 2 macros in it ("templatename" is replaced with the actual template name, and "paramname" is replaced with comma-separated list of the parameters violating this rule)
There are a few more small values governing the operation.
Because of scribunto's deliberate limitation of not allowing "grandparent" access, we can't wrap it in a template - we must place the #invoke directly in the template to be controlled. In order to save us the need to pass this many parameters every time, validateParams() accepts a single parameter, named "options", which is a json-encoded structure packing all the parameters. we pack it in a template, which we pass to the function like so:
{{#invoke:ParamValidator | validateParams | options = {{Options}} }}
You can see a working example in he:Template:Pv-options (note that "קטגוריה:" means "Category:". the stuff in doubel-square brackets is categories, except [[templatename]] which is replaced by to a link to the actual template).
peace - קיפודנחש (aka kipod) (talk) 21:26, 24 March 2016 (UTC)
- An alternative: I have added module:TemplatePar to several templates. It allows for subtle management, including error-message-in-preview, and various checks. It uses a whitelist of parameters, not tempatedata. -DePiep (talk) 10:46, 30 March 2016 (UTC)
- @DePiep: i will be grateful if you can review this module (as well as the helper module - ReadTd) on hewiki. you can leave feedback in the talkpage of the module, or here. will appreciate a ping, but it's not necessary. peace. [sign: User:קיפודנחש|קיפודנחש (aka kipod), io guess]
- I'm sorry, I don't have the Lua level for this. Just saying: good luck on your road. -DePiep (talk) 19:16, 30 March 2016 (UTC)
- @DePiep: i will be grateful if you can review this module (as well as the helper module - ReadTd) on hewiki. you can leave feedback in the talkpage of the module, or here. will appreciate a ping, but it's not necessary. peace. [sign: User:קיפודנחש|קיפודנחש (aka kipod), io guess]
- An alternative: I have added module:TemplatePar to several templates. It allows for subtle management, including error-message-in-preview, and various checks. It uses a whitelist of parameters, not tempatedata. -DePiep (talk) 10:46, 30 March 2016 (UTC)
Currency and inflation templates
It could be very helpful to convert and possibly even combine the several templates/datasets which currently exist for handling currency into more easily and reliably maintainable Lua modules which use easily updated CSV datasets. Note that this is not a proposal for real-time data.
Currency symbols:
- Template:Currency is very extensive, with datasets for currency symbols, currency names, and links to articles about these currencies. Keeping a central repository of Wikipedia's currency styles is very helpful if any change needs to be made. This data could probably also be supplemented with optional formatting conventions such as subunits, rounding, commas, etc.
- Many in Category:Currency templates provide the basic shortcut functionality of pre-formatting a number with a currency symbol and link. Most of these statically code their symbols, and thus contradictions of Template:Currency probably exist. Some provide additional functions.
Inflation:
- Template:Inflation contains about a dozen inflation indexes of varying coverage. Overall it's a very good starting point and should be quite easy to write code and compile data for.
- Templates related to this, including Template:Inflation-year and Template:Inflation-fn are critical to its functionality and/or to ensuring articles do not abuse its functionality.
- A few in Category:Currency templates used Template:Inflation, and I extended this feature to the rest for which datasets exist. (Except for Template:ZAR, which already had a currency conversion, and I got frustrated trying to code both inflation and conversion just for a single-currency shortcut template.)
- Inflation is easily abused and must be given the proper context in articles. The template currently encourages, at a bare minimum, the inflated value to be described as "equivalent to" the original value, and "today" or {{CURRENTYEAR}} should never be used to refer to its calculation which may be outdated but Template:Inflation-year used instead.
- It might be desirable to consider the use of not only index codes but additionally index types mostly as a way to track whether editors know what they're doing when they added the template.
- It should be possible to replace Template:Inflation-year and the various "Template:Inflation/index/startyear" pages with a function that simply checks a dataset to see what years are covered and what the latest year is. It might not even be necessary for the available years to be consecutive, only that both desired years have data.
Currency conversion:
- Template:BDTConvert, Template:INRConvert and Template:PKRConvert offer a number of currencies to convert between, but they're fundamentally flawed. Each exchange has only a single, ahistorical data value. (These templates also appear to use Template:Inflation to calculate inflation, but since I changed Template:Inflation to not falsely provide {{CURRENTYEAR}} many uses of this are now visibly broken rather than silently broken.)
- Template:To USD and especially Template:International dollars manage to do it right as far as I can tell. Many currency exchange rates cataloged by year. However, a very limited selection of years.
- Wherever the data comes from, it's important that exchange rates are not just chosen based on whenever an editor did a Google search for "exchange rates X to Y", but on reliably sourced, annual average exchange rates.
Combining these: This might get confusing to code due to the number of variables and options. With all options enabled, a value provided, an index code provided, a start and end currency provided, and a start and specific end year provided, the template/module could inflate the value from startyear to endyear, convert based on exchange rates based on endyear, and format both the original value and the calculated inflated values in both currencies with wikilinks and convenient statements and citations to make it clear what the data is. And then there's any number of more limited uses like only requesting a currency symbol, only requesting a currency link, only requesting inflation or conversion, only requesting the latest year possible for inflation or conversion for a given index or pair of currencies. This probably sounds harder than it is, because most of this can be very modular, especially since Lua allows separating data and calculation from presentation.
Please ping me with any questions or comments. djr13 (talk) 17:24, 4 April 2016 (UTC)
- @djr13: So do it. I recently created
{{time/new}}
which, compared to this task, is relatively modest but consolidates a template,{{time}}
and a bunch of small subtemplates into a single Module:Time.
- There is a Module:CSV which may be helpful.
- —Trappist the monk (talk) 17:38, 4 April 2016 (UTC)
- Well yes, there is that, but after just rewriting Template:Inflation and digging through all these currency templates and their problems, I'm seeking comments and help rather than trying to immediately dive head first into this complicated area with essentially zero existing knowledge of wiki lua programming. djr13 (talk) 17:55, 4 April 2016 (UTC)
- I don't have an economics background so most of this is jibberish to me but it seems that a fine place to start is
{{currency}}
isn't it? Start with just the ISO 4217 codes, figure out formatting, ... Once that's done, translate non-standardized names to the 4217 codes, and then attack other templates which can use the currency code for rendering and so build from there.
- I don't have an economics background so most of this is jibberish to me but it seems that a fine place to start is
- Well yes, there is that, but after just rewriting Template:Inflation and digging through all these currency templates and their problems, I'm seeking comments and help rather than trying to immediately dive head first into this complicated area with essentially zero existing knowledge of wiki lua programming. djr13 (talk) 17:55, 4 April 2016 (UTC)
- I'm not doing much right now so if I can be of assistance let me know.
- I think it would be best to start from the data. If we work out what data we need and how we should store it, then writing templates using that data would not be hard. However, if we write a module to e.g. convert currency names to currency symbols, and we only store the currency name and the currency symbol in the module's data table, then that data would not be usable by a module that, e.g., calculates interest. In fact, I think a three-tier architecture is called for. At the data tier, we could have a data module or modules that contain all the data needed by all currency-related templates. At the logic tier, we could have a module or series of modules that provide interfaces to do things like calculate a compound interest rate over a given number of years, or find an exchange rate between a given pair of currencies in a given year. And in the presentation tier, we would link these interfaces to parameters specified by users in individual templates. The advantage of having the logic tier is that all the complicated code for things like Template:BDTConvert, Template:INRConvert and Template:PKRConvert can be done in one place, rather than being duplicated in each of the templates. And it also makes it possible to completely change the data structure without breaking templates for end users - as long as the interface in the logic tier works the same way, the way the templates work won't change. (This also implies that we should be careful when choosing our interfaces, as we won't be able to change them later on.) — Mr. Stradivarius ♪ talk ♪ 10:02, 5 April 2016 (UTC)
- I said nothing about confining currency symbol data to its own module and in fact agree that the architecture that you suggest is best. I offered
{{currency}}
as a relatively simple place for a Lua newby to start. - —Trappist the monk (talk) 10:31, 5 April 2016 (UTC)
- The currency name/symbol/linking template is indeed the easiest. It's pretty much mostly just a couple of long #switches containing precisely the data being requested from the template. Converting it to a Lua module would just mean further abstracting the template and very easily adding more currency-related datasets and basic text/number presentation options into one place.
- I'd be happy to convert these datasets to CSV if that'd be useful. Maybe even wikitables. If so, where should I put them? djr13 (talk) 05:24, 6 April 2016 (UTC)
- I've made a start at it at Module:Currency and Module:Currency/Presentation:
- Limited error handling and doesn't yet support
|first=
or any other named parameters. There are three tables in /Presentation: The first is the list of codes taken from ISO 4217 where the data were taken from{{Currency/Page}}
,{{Currency/Position}}
, and{{Currency/Symbol}}
. The second is for non-standard codes that can be translated into standard codes, and the third is non-standard codes.
-
- Perhaps discussion should continue at Module talk:Currency.
- —Trappist the monk (talk) 11:48, 6 April 2016 (UTC)
- I am very charmed by the tree tier setup Stradivarius describes. It is ambitious, but very rewarding (all in the background). -DePiep (talk) 06:52, 6 April 2016 (UTC)
- @Trappist the monk: Sorry, I didn't mean to imply that you would write the module in the way I described - that part of my comment was just intended as an example of problems that I thought might crop up if we just started converting some templates without thinking about how to convert the others. Actually, thinking about it, doing things incrementally is very likely to be a better approach than trying to convert all of the templates at once. As long as we keep the general architecture in mind while we convert new templates, we can gradually add new interfaces in the logic layer and change the data tier as necessary without breaking any of the existing templates. — Mr. Stradivarius ♪ talk ♪ 11:27, 6 April 2016 (UTC)
- Yep, we agree.
- —Trappist the monk (talk) 11:48, 6 April 2016 (UTC)
- small suggestion: you might not want to use tonumber() to test for numberness, and instead call mw.language.getContentLanguage():parseFormattedNumber(). peace.— Preceding unsigned comment added by קיפודנחש (talk • contribs) 03:54, 7 April 2016 (UTC)
- The notion that
mw.language.getContentLanguage():parseFormattedNumber()
is a ' language-aware version oftonumber()
is somewhat misleading. Apparently what it does is simply strip grouping characters (for en.wiki the comma) so these 'work': - Not really helpful if the template blithely accepts malformed input. But, I did find
mw.language.getContentLanguage():formatNum()
. - —Trappist the monk (talk) 10:09, 7 April 2016 (UTC)
- i am well aware of this deficiency - see Phabricator:T131387 - and notice "author"... this is still better than "tonumber", b/c refusing to accept $123,000.47 as legal tender, is worse than accepting $123,,,,4,5.20 . hopefully "they" will decide to fix this stupid bug eventually. peace - קיפודנחש (aka kipod) (talk) 22:17, 7 April 2016 (UTC)
- The notion that
- small suggestion: you might not want to use tonumber() to test for numberness, and instead call mw.language.getContentLanguage():parseFormattedNumber(). peace.— Preceding unsigned comment added by קיפודנחש (talk • contribs) 03:54, 7 April 2016 (UTC)
- I said nothing about confining currency symbol data to its own module and in fact agree that the architecture that you suggest is best. I offered
- I think it would be best to start from the data. If we work out what data we need and how we should store it, then writing templates using that data would not be hard. However, if we write a module to e.g. convert currency names to currency symbols, and we only store the currency name and the currency symbol in the module's data table, then that data would not be usable by a module that, e.g., calculates interest. In fact, I think a three-tier architecture is called for. At the data tier, we could have a data module or modules that contain all the data needed by all currency-related templates. At the logic tier, we could have a module or series of modules that provide interfaces to do things like calculate a compound interest rate over a given number of years, or find an exchange rate between a given pair of currencies in a given year. And in the presentation tier, we would link these interfaces to parameters specified by users in individual templates. The advantage of having the logic tier is that all the complicated code for things like Template:BDTConvert, Template:INRConvert and Template:PKRConvert can be done in one place, rather than being duplicated in each of the templates. And it also makes it possible to completely change the data structure without breaking templates for end users - as long as the interface in the logic tier works the same way, the way the templates work won't change. (This also implies that we should be careful when choosing our interfaces, as we won't be able to change them later on.) — Mr. Stradivarius ♪ talk ♪ 10:02, 5 April 2016 (UTC)
{{Transclude}}
and {{First character}}
We want to identify strings beginning with ":" - {{Transclude}}
currently does this by prepending a namespace and checking if it parses correctly.
I created {{First character}}
which works nicely, except for strings starting with ":" (and ;,#,=) - so I tried a Lua solution {{First character/sandbox}}
- this fails even more spectacularly.
Suggestions?
All the best: Rich Farmbrough, 15:17, 22 February 2016 (UTC).
- Although it does seem to function in
{{Transclude/sandbox}}
, implying this is a rendering issue. All the best: Rich Farmbrough, 15:46, 22 February 2016 (UTC).
- I can't take the time to get my head around that at the moment, but a couple of points: As you know, if "=" is possible, the parameter must be given as "1=parameter". That matters for the first example which has "=string" and which will assign the value "string" (no equals) to a named parameter where the name is an empty string. Also, plugging
"{{First character|1=:string}}"
(with quotes) in Special:ExpandTemplates shows that it is outputting a newline then the ":". Something is needed to kill the newline. Johnuniq (talk) 21:33, 22 February 2016 (UTC)- The rendering problems are caused by phab:T14974, which is one of the most notorious bugs in MediaWiki. (I am guessing that you were both aware of it already?) Both Lua and templates like {{first character}} can identify strings beginning with
:
without any trouble, but when they are output from a template or a parser function (including #invoke), the parser adds an extra newline. So you can do things like{{#ifeq: {{first character|:string}} | : | yes | no }}
(output: {{#ifeq: {{first character|:string}} | : | yes | no }}), but if you do{{first character|:string}}foo
you get the unwanted newline. The standard (and kludgy) way to suppress the newline is to add<nowiki />
before the colon, although this has some unwanted effects such as breaking links. — Mr. Stradivarius ♪ talk ♪ 06:09, 23 February 2016 (UTC)- Thanks both, no I wasn't aware of that bug. I'm not sure how much time I wasted, but it's not insignificant, and when you add all the other people's wasted time too, this should have been fixed years ago. All the best: Rich Farmbrough, 14:46, 23 February 2016 (UTC).
- Thanks both, no I wasn't aware of that bug. I'm not sure how much time I wasted, but it's not insignificant, and when you add all the other people's wasted time too, this should have been fixed years ago. All the best: Rich Farmbrough, 14:46, 23 February 2016 (UTC).
- The rendering problems are caused by phab:T14974, which is one of the most notorious bugs in MediaWiki. (I am guessing that you were both aware of it already?) Both Lua and templates like {{first character}} can identify strings beginning with
- I can't take the time to get my head around that at the moment, but a couple of points: As you know, if "=" is possible, the parameter must be given as "1=parameter". That matters for the first example which has "=string" and which will assign the value "string" (no equals) to a named parameter where the name is an empty string. Also, plugging
Full regular expressions?
One thing I find somewhat disappointing is that Lua doesn't support full regular expressions. It does have patterns and they do come close, but they lack a lot of the features of proper regexps (like bracketing). I'm wondering if there are any metamodules or extensions that introduce full functionality, the way for example mw.ustring adds Unicode-compliant string libraries. Are there any workarounds? I'm ending up writing long and unmaintainably convoluted procedures to do a job that could easily be dealt with in a one-line regexp. Uanfala (talk) 01:45, 29 March 2016 (UTC)
- I'm pretty sure no regex engines are available for use on Wikipedia. If you link to an example (and quote some text so a search can find it), I'll have a look and may have a suggestion. Johnuniq (talk) 02:24, 29 March 2016 (UTC)
- I'm not sure I understand what kind of example I should link to. An example of what? On an unrelated note, I realise that there's a mediawiki extension that apparently provides some regex functions, but I can't seem to be able to find out whether it's installed on wikipedia or what kind of regex it supports (even if it did support them fully, it would be weird to have to call parser functions from within Lua). Uanfala (talk) 10:34, 29 March 2016 (UTC)
- Special:Version lists what extensions are available, and mw:Extension:RegexFunctions is not there. By example, I meant that if you are currently working on something where a complex regex would help, and if you were to link to where I could see it, I might have a suggestion regarding how the problem could be approached in Lua. For an eye-watering example of complex substitution where Lua works quite well, see the strftime function in Module:Date—I was astonished to see that it wasn't too hard to implement something as ugly as strftime. By the way, I have a much better version which I'm working on but have not yet uploaded, so the module is very much at the alpha stage. Johnuniq (talk) 11:14, 29 March 2016 (UTC)
- Ah, yes, I've been trying to find this Special:Version for some time. Well, I've got an example but it's not readable enough at the moment. Basically, what it tries to do is take a string like
<b><abbr>foo</abbr>bar</b>
and output some kind of table where each text node will be paired with the html tags it appears within, something likefoo: b,abbr; bar: b
. Currently, I have a function that iterates over the string getting the indexes of any tags it can find. Now that I've had a look at other modules I realise that my original concern about length might have been unnecessary. Maybe it's because I'm not a programmer that the 30 or so lines needed to do this job seem like a lot. Uanfala (talk) 18:56, 29 March 2016 (UTC) - We do use regex in edit filters.
- I'll suggest that reg-ex is unlikely to be released as part of Wiki-Lua. Robet Ierusalimschy says the reason it's not in Lua "as she is wrote" is the size: >4000 lines for the POSIX implementation vs <600 for the pattern matching in Lua.
- The issue I see with regex is that subtle bugs can consume huge amounts of processing time. While, compared with the hundreds and maybe thousands of template editors there are relatively few Lua editors, and most of them seem very experienced software folk, I suspect that the devs would balk at the perceived risk.
- However if wish the phab issue good luck!
- All the best: Rich Farmbrough, 12:29, 8 April 2016 (UTC).
- Ah, yes, I've been trying to find this Special:Version for some time. Well, I've got an example but it's not readable enough at the moment. Basically, what it tries to do is take a string like
- Special:Version lists what extensions are available, and mw:Extension:RegexFunctions is not there. By example, I meant that if you are currently working on something where a complex regex would help, and if you were to link to where I could see it, I might have a suggestion regarding how the problem could be approached in Lua. For an eye-watering example of complex substitution where Lua works quite well, see the strftime function in Module:Date—I was astonished to see that it wasn't too hard to implement something as ugly as strftime. By the way, I have a much better version which I'm working on but have not yet uploaded, so the module is very much at the alpha stage. Johnuniq (talk) 11:14, 29 March 2016 (UTC)
- I'm not sure I understand what kind of example I should link to. An example of what? On an unrelated note, I realise that there's a mediawiki extension that apparently provides some regex functions, but I can't seem to be able to find out whether it's installed on wikipedia or what kind of regex it supports (even if it did support them fully, it would be weird to have to call parser functions from within Lua). Uanfala (talk) 10:34, 29 March 2016 (UTC)
Descending order
I have a module, which displays a simple string in some order (and does some other things). I have one problem. In short. I put values in table in such order: "1, 2, 3, 4, 5". How to display them in descending order: "5, 4, 3, 2, 1"? Real life example: lv:Moduļa diskusija:Vieta#Secība (second table), where I need to have "Parīze, Francija" in output. table.sort(out, function(a, b) return a > b end)
returns table in descending order, but alphabetically. Module: lv:Modulis:Vieta, some tests: lv:Moduļa diskusija:Vieta. P.S. I'm just starting to play with Lua to convert some templates, so any comments are appreciated about the module itself. This is the template, I'm triyng to lua-lize. --Edgars2007 (talk/contribs) 21:19, 15 April 2016 (UTC)
- @Edgars2007: Probably the easiest way is to loop over the nums table in reverse order. See if this works for you:
for i = #nums, 1, -1 do
local num = nums[i]
local link = args[num .. 's'] or args[num]
local text = args[num]
out[#out+1] = makeLink(link,text)
end
- Best — Mr. Stradivarius ♪ talk ♪ 02:22, 16 April 2016 (UTC)
- Thanks, that was going to be my next suggestion, after saving an edit to do what I think the current code (lv:Module:Vieta) is doing. If the arguments are wanted in reverse order as above, and if my edit is wanted, the next step would be to use #args which I think works. One point of minor interest is that args['td'] can be written as the very convenient args.td (providing the key is not numeric and uses only characters that work in Lua variable names). It is best if all variables are declared local to avoid typo mistakes. You need some off-wiki tool to identify problems or there is Module:No globals if desperate. I added "local" for result and tagad. Johnuniq (talk) 02:49, 16 April 2016 (UTC)
- Thank you, guys (also for comments)! Johnuniq, may I ask to include that loop with #args? I have been playing around with #args in preview mode, but what I usually get (if not error message) is blank text (except of course the flag and "(tagad ...)" part). Edgars2007 (talk/contribs) 07:04, 16 April 2016 (UTC)
- Thanks, that was going to be my next suggestion, after saving an edit to do what I think the current code (lv:Module:Vieta) is doing. If the arguments are wanted in reverse order as above, and if my edit is wanted, the next step would be to use #args which I think works. One point of minor interest is that args['td'] can be written as the very convenient args.td (providing the key is not numeric and uses only characters that work in Lua variable names). It is best if all variables are declared local to avoid typo mistakes. You need some off-wiki tool to identify problems or there is Module:No globals if desperate. I added "local" for result and tagad. Johnuniq (talk) 02:49, 16 April 2016 (UTC)
@Edgars2007: I was intending to use the following but it failed:
for i = #args, 1, -1 do out[#out+1] = makeLink(args[i .. 's'], args[i]) end
With a normal table, #args gives the number of items with ascending numeric keys, and I somehow thought Module:Arguments returned such a table, but it appears to fetch items on demand, so #args fails. The code above from Mr. Stradivarius would work because in the original module nums is a normal table and #nums would work. At any rate I put in a fix, although I am not sure that it is what you wanted. Do you really want the items reversed like that? The reason the sort was not working is that sort operates on the table values whereas I think you wanted it to operate on the table keys (1, 2, 3, ...). If my edit is not what was wanted, let me know. Johnuniq (talk) 08:00, 16 April 2016 (UTC)
- Thank you! At least I don't look like an idiot, as it wasn't a trivial change :) Yes, now everyting is how it should be. The template/module logic is to input values from largest entity (usually country) to the smallest one (usually city), as with parser functions it is easier to set flag for first parameter, not the last one (which can be second, third, or fourth). And then output them in reversed order (from smallest to largest one). Yes, I probably should have said that in first place, sorry. And as the template is used very widely, I don't want to change, how it's working, so colleagues doesn't get confused :) --Edgars2007 (talk/contribs) 08:54, 16 April 2016 (UTC)
This template would benefit greatly from being converted to Lua. Its function in short, return a random selection of 5 articles from a list, checking that each is non-existent. — Martin (MSGJ · talk) 21:31, 18 April 2016 (UTC)
- @MSGJ: This template only has one transclusion, on its own /testcases subpage. I see that it was used on Special:RecentChanges in the past, but that was removed in Special:Diff/544057720 as a result of this TfD. I do see a discussion about adding it to the community portal, but that doesn't seem to have resulted in any action yet. My instinct is to wait until we know it will actually be used somewhere before converting it. Do you know of any other places it is being used or where people might use it? — Mr. Stradivarius ♪ talk ♪ 00:36, 19 April 2016 (UTC)
- Didn't know it wasn't being used actually. I see frequent edits by User:RekishiEJ on Template:Recent changes article requests/list, which is on my watchlist, so I assumed it was used somewhere. Perhaps RekishiEJ can give us some information? Otherwise I totally agree that it is not worth anyone's time converting it. — Martin (MSGJ · talk) 07:50, 19 April 2016 (UTC)
- We shouldn't spend time discussing whether to convert this template or not before transcluding it to the community portal, since it is currently not used. The reason that I have frequently edited it is because I sometimes encounter blue links inside it, or that some links in it should be replaced as they either have wrong name or are in fact not notable enough to be included.--RekishiEJ (talk) 09:26, 19 April 2016 (UTC)
- Didn't know it wasn't being used actually. I see frequent edits by User:RekishiEJ on Template:Recent changes article requests/list, which is on my watchlist, so I assumed it was used somewhere. Perhaps RekishiEJ can give us some information? Otherwise I totally agree that it is not worth anyone's time converting it. — Martin (MSGJ · talk) 07:50, 19 April 2016 (UTC)
Replace certain characters
Would it be possible for me to create a module that looks for certain characters and turns them into other character? Specifically, I'd like a module that takes Wikidata's output for coordinates (which looks like this: 53°31'4.44"N, 113°29'46.90"W
) and replaces degree/minute/second symbols with pipes (giving an output like this: 53|31|4.44|N|113|29|46.90|W
). —Arctic Gnome (talk • contribs) 20:07, 6 May 2016 (UTC)
- Yes. You can use Module:String to do that:
{{#invoke:String|replace|source=53°31'4.44"N, 113°29'46.90"W |pattern=[°'",]|replace=||plain=false}}
→ 53|31|4.44|N| 113|29|46.90|W
- —Trappist the monk (talk) 20:41, 6 May 2016 (UTC)
- @Trappist the monk: Excellent! But do you know why it doesn't work on the minute and second symbols when I apply it to a real Wikidata quantity?
{{#invoke:String|replace|source= {{#property:P625|from=Q24012602}} |pattern=[°'",]|replace=||plain=false}}
→ 53|40'36"N| 112|49'43"W
- —Arctic Gnome (talk • contribs) 21:37, 6 May 2016 (UTC)
- Apparently, the #property output uses numeric references for the
'
and"
symbols—{{subst:#property:P625|from=Q24012602}}
returns53°40'36"N, 112°49'43"W
. To replace those too you'd need a separate pattern:{{#invoke:String|replace|source={{#property:P625|from=Q24012602}}|pattern=[49];|replace=||plain=false}}
→ 53°40|36|N, 112°49|43|W. Combining the two (and adding?
to remove the space between the longitude and latitude) results in 53|40|36|N|112|49|43|W. SiBr4 (talk) 22:47, 6 May 2016 (UTC)
- Apparently, the #property output uses numeric references for the
- @Trappist the monk: Excellent! But do you know why it doesn't work on the minute and second symbols when I apply it to a real Wikidata quantity?
Question about mw.wikibase functions
I'm working with a MediaWiki 1.25alpha installation with Extension:Scribunto and Extension:Wikibase Client + Repository .5 alpha installed (& Wikibase Library), and Lua 5.1.5.
I'm having trouble implementing some of the functions in the mw.wikibase library, listed on this page: Wikibase Client Lua Functions
Specifically, I am having problems with these functions:
- mw.wikibase.getEntity
- formatPropertyValues
- mw.wikibase.resolvePropertyId
- mw.wikibase.entity:getProperties
For Example: within my Lua Module, code:
-- Return the label of a given data item, or of connected page -- if no argument is provided to this method. function p.label(frame) return mw.wikibase.label( frame.args[1] ) end --return a property Id for given label or ID function p.property(frame) return mw.wikibase.resolvePropertyId( frame.args[1] ) end
Template:
#invoke:sandbox/wikibase|label|Q4940 #invoke:sandbox/wikibase|property|property label here
Problem: Label function works fine. Property function returns error:
Lua error in Module:sandbox/wikibase at line 28: attempt to call field 'resolvePropertyId' (a nil value).
Another Example:
In this function, I was having so much trouble with nil value error that I've tried hard-coding the values. But I'm still getting the error.
function p.getItem(frame) local item = mw.wikibase.getEntity( "Q1996" ) local instance_of = item.formatPropertyValues( "P3" ) return instance_of.value end
Returns Error:
Lua error in Module:wikibase-test at line 43: attempt to index local 'item' (a nil value).
Can anyone advise about this error, or what I'm doing wrong with passing values into these frames? Thanks for your help. Wikipersistence (talk) 13:32, 11 May 2016 (UTC)
- I have very little experience with Wikidata so won't comment directly. You might want to look at Module:Wikidata. Perhaps the code there will answer your questions.
- —Trappist the monk (talk) 14:06, 11 May 2016 (UTC)
- Thanks for this suggestion. I have looked at these Wikidata modules, but I'll take another look. Wikipersistence (talk) 23:37, 11 May 2016 (UTC)
- I have done a little work on similar issues recently (search for "wikidata" here—I'll probably be moving it to a separate module soon), and have successfully used getEntity. The problem is that every call to wikibase can and will fail and that requires a lot of mucking around. One problem in the last snippet above is that the dot should be a colon. That is, it should be
item:formatPropertyValues( "P3" )
. Using the colon like that makesitem
appear as the first parameter toformatPropertyValues
. The above code is using "P3" as its first parameter which will fail. However, the error says thatitem
is nil which suggests there is a problem with Q1996 (does it exist?). I can't look at that now but may get a chance later. Post again if still a problem. Johnuniq (talk) 07:57, 12 May 2016 (UTC)- It's P3 that doesn't exist:
[[d:Q1996]]
→ d:Q1996{{#property:P3|from=Q1996}}
→Failed to render property P3: P3 property not found.
- Changing P3 to P585 (date) to prove that the form is correct (should return 2009):
{{#property:P585|from=Q1996}}
→ 2009
- These work in the debug console:
=mw.wikibase.getEntity( "Q1996" ):formatPropertyValues( "P585" ).value
→ 2009=mw.wikibase.getEntity( "Q1996" ):formatPropertyValues( "P585" ).label
→ point in time
- —Trappist the monk (talk) 09:40, 12 May 2016 (UTC)
- It's P3 that doesn't exist:
- I have done a little work on similar issues recently (search for "wikidata" here—I'll probably be moving it to a separate module soon), and have successfully used getEntity. The problem is that every call to wikibase can and will fail and that requires a lot of mucking around. One problem in the last snippet above is that the dot should be a colon. That is, it should be
- Thanks for this suggestion. I have looked at these Wikidata modules, but I'll take another look. Wikipersistence (talk) 23:37, 11 May 2016 (UTC)
Invoke Taxobox on cy-wiki
I'm trying to enable the automatic taxobox on cy-wiki here, but there's an error. Could someone take a look at it, and fix it please? Llywelyn2000 (talk) 13:21, 12 May 2016 (UTC)
- Did it work before the significant changes you made to it?
- For the error:
- Lua error in Modiwl:Wikidata at line 85: bad argument #1 to 'pairs' (table expected, got nil).
- It appears that the second variable in the function call
tableMerge(i18n, res.i18n)
is not a table. At cy:Modiwl:Wikidata-i18n, there isn't a table calledi18n
.
- As a test, I changed the function call to
tableMerge(i18n, res)
. By doing that, this particular error message went away. And revealed another... - —Trappist the monk (talk) 13:57, 12 May 2016 (UTC)
- Many thanks! The template is new, therefore no articles are attached to it, so far. So, please feel free to create any needed codes eg
i18n
. There was an old (different) template with the same name (the one on en-wiki), but all changes made by me in the last few weeks. Hasn't worked at all! Llywelyn2000 (talk) 14:19, 12 May 2016 (UTC)- I don't think I will. Were the changes you made well documented with your intent and much, much less extensive then perhaps. If Module:Taxobox here at en.wiki doesn't work for you at cy.wiki, start with Module:Taxobox and make small testable changes to get it to where you want it to be.
- —Trappist the monk (talk) 14:48, 12 May 2016 (UTC)
- What do you mean with 'changes you made'? I don't understand, or you have viewed the history of the pages, which is irrelevant. These are all new. All species on cywiki now rely on Template:Blwch tacson NOT Template:Taxobox. That releases Template:Taxobox for a new Wikidata / Wikispecies Template:Taxobox (with a family of templates and modules) which hasn't been implemented on en-wiki, but is on many other wikis. This left me with a blank page, to start afresh. I then copied the templates from Wikispecies (not enwiki!). But if it's a Luna problem then why is the history of the page relevant? I'm sure I'm wrong (Little knowledge...) but I should have thought that copying a family of templates (and modules) from one wiki to another would work? If not, then isn't there a fault in the modules/luna? Llywelyn2000 (talk) 16:32, 12 May 2016 (UTC)
- Many thanks! The template is new, therefore no articles are attached to it, so far. So, please feel free to create any needed codes eg
- i.e. Template:Taxobox on enwiki is totally different to Template:Taxobox on Wikispecies, which is the one I'm after. Llywelyn2000 (talk) 16:39, 12 May 2016 (UTC)
- The title of this discussion is 'Invoke Taxobox on cy-wiki'; the seventh word in your first post is 'taxobox'; at cy:Defnyddiwr:Llywelyn2000/rhywogaethau the error message results from:
{{#invoke: Taxobox | taxobox | qid=Q464424 | config[count]=10 |config[lang]=fr }}
- the first version of cy:Module:Taxobox is a copy of the en.wiki Module:Taxobox translated to Welsh; after which significant changes were made by you without edit summary.
- The title of this discussion is 'Invoke Taxobox on cy-wiki'; the seventh word in your first post is 'taxobox'; at cy:Defnyddiwr:Llywelyn2000/rhywogaethau the error message results from:
-
- Errors can often be revealed by looking at a previous version or versions of the code; especially when working with code with which one in not familiar. That is why history is relevant. And, until your last posts, there had been no mention of WikiData or WikiSpecies; just taxobox.
-
- If the modules and templates work at WikiData and WikiSpecies or wherever you got them, it is reasonable to expect that they should work at cy.wiki – or at least they would not fail like that function call described above. That suggests, perhaps, that cy.wiki does not have current versions of all the necessary modules/templates or that something is missing. Have you discussed this problem with the authors of the original Wikidata/WikiSpecies modules/templates?
- —Trappist the monk (talk) 17:25, 12 May 2016 (UTC)
- i.e. Template:Taxobox on enwiki is totally different to Template:Taxobox on Wikispecies, which is the one I'm after. Llywelyn2000 (talk) 16:39, 12 May 2016 (UTC)
- The words 'automatic taxobox' (word 6 and 7) referred to the code which followed two words later in a link:
{{#invoke: Taxobox | taxobox | qid=Q464424 | config[count]=10 |config[lang]=fr }}
- which is very different to the Taxobox used on enwiki, so I didn't think I needed to explain that it gathered info from Wikidata. I think your right, a few modules have been left out, uncopied, but there's no clue as to which ones. That's why I thought lua could point to the problem. Yes, discussed with User:Pigsonthewing, but came to a dead-end. Sorry for troubling you. Llywelyn2000 (talk) 06:14, 13 May 2016 (UTC)
- In case you are not aware, it is possible to determine what templates/modules are used when something is executed. For example, paste the above #invoke line into a sandbox (replace all the contents), and preview the edit. See "Templates used in this preview" at the bottom. At enwiki, each item may be a blue link, while possibly there are red links elsewhere. Johnuniq (talk) 07:41, 13 May 2016 (UTC)
- Yes, I am; but many thanks! It would be nice if modules had the same info! Llywelyn2000 (talk) 14:06, 13 May 2016 (UTC)
- In case you are not aware, it is possible to determine what templates/modules are used when something is executed. For example, paste the above #invoke line into a sandbox (replace all the contents), and preview the edit. See "Templates used in this preview" at the bottom. At enwiki, each item may be a blue link, while possibly there are red links elsewhere. Johnuniq (talk) 07:41, 13 May 2016 (UTC)
I overlooked the fact that the first link in the OP shows the problem! On investigating, I fixed the first problem with an edit to cy:Module:Wikidata-i18n. The next problem is "Tried to write global getItemLabel". That is a message from cy:Module:No globals. It occurs because the coding style in cy:Module:Taxobox is not quite right. Line 193 is:
function getItemLabel(item, lang)
That is equivalent to:
getItemLabel = function (item, lang)
In other words, it attempts to set the global variable getItemLabel
. An unusual fix would be to put L:
in front of the name. The real fix is to insert local
in front of the function and get rid of all the L usage. I don't want to jump in and do a bunch of edits without understanding what is going on, and where the module came from. What is L for? Ask again if more is wanted. Johnuniq (talk) 00:36, 14 May 2016 (UTC)
- @Succu, Pigsonthewing, Trappist the monk, Jura1, and PhiLiP: Overview: I'm trying to bring in the new auto taxobox from Wikidata to cywiki. This page on WD shows an infobox with a snake, which is very different to the auto taxobox used in enwiki. I'm trying to enable this new auto taxobox in cywiki. cy:Modiwl:Taxobox was copied (I hope!) from Wikidata:Module:Taxobox. Thanks you! Llywelyn2000 (talk) 06:16, 15 May 2016 (UTC)
- I fixed a bunch of global problems in cy:Module:Taxobox but the whole thing needs careful attention because I had to guess what might have been intended at a couple of places. I noticed several obviously broken pieces (e.g. config, and see "TODO" which I inserted at a couple of places). Currently, it is complaining because cy:Module:Cite is trying to execute
wikidata.getClaims
, but Module:Wikidata does not havegetClaims
(at enwiki and at cywiki). The next step would be to find out why Module:Cite tried to do that. I have to work on some of my stuff now and I think attempts to use Module:Taxobox should be abandoned until someone can thoroughly work through all the code. Johnuniq (talk) 08:28, 15 May 2016 (UTC)
- I fixed a bunch of global problems in cy:Module:Taxobox but the whole thing needs careful attention because I had to guess what might have been intended at a couple of places. I noticed several obviously broken pieces (e.g. config, and see "TODO" which I inserted at a couple of places). Currently, it is complaining because cy:Module:Cite is trying to execute
- @Succu, Pigsonthewing, Trappist the monk, Jura1, and PhiLiP: Overview: I'm trying to bring in the new auto taxobox from Wikidata to cywiki. This page on WD shows an infobox with a snake, which is very different to the auto taxobox used in enwiki. I'm trying to enable this new auto taxobox in cywiki. cy:Modiwl:Taxobox was copied (I hope!) from Wikidata:Module:Taxobox. Thanks you! Llywelyn2000 (talk) 06:16, 15 May 2016 (UTC)
Module:Dump
Module:Dump is new. It provides an alternative to mw.dumpObject()
for module developers who want to examine a complex table. Its main purpose is to view Wikidata entities to determine how a module should process the data. A demonstration is at my sandbox (permalink). Johnuniq (talk) 12:19, 23 May 2016 (UTC)
I added the ability to dump the _G
table of globals:
{{#invoke:dump|testcase|G}}
AddTranslations.js
Hello everyone, I just create this js page to test if I can get the gadget for adding a translation, much as this template it has, but something went wrong. I test it here, but I don't get the gadet below the template trans-top. Am I doing something wrong? -- DenisWasRight (talk) 10:27, 24 May 2016 (UTC)
- Lua and JavaScript are different languages and have very different applications on MediaWiki. You could try asking at WP:VPT or WT:User scripts instead. SiBr4 (talk) 11:21, 24 May 2016 (UTC)
- He has
{{#invoke:langs
in js. I assume, that's the reason, he's asking here. But I'm not sure, Lua is meant to be used in this way :) --Edgars2007 (talk/contribs) 11:50, 24 May 2016 (UTC)- I will, thanks. I just thought there maybe a Lua file that's not yet created. But I wil ask the same question on WT:User scripts. -- DenisWasRight (talk) 12:04, 24 May 2016 (UTC)
- He has
Date manipulation
Can someone write me a little module to convert a date written in the format 2016 May 26
into the more usual 26 May 2016
? The template {{MRVdiscuss}} is using a hack to make the time parser function recognise this properly. Thanks — Martin (MSGJ · talk) 08:29, 26 May 2016 (UTC)
- Ideally the module would not baulk if the date is in the correct format, but should return the same date unchanged. — Martin (MSGJ · talk) 08:33, 26 May 2016 (UTC)
- You might use
{{#iferror:}}
. Something like this should return the date unmolested if the date is malformed, misspelled, etc:{{#iferror:{{#time:Y F|{{{date}}}}}|{{{date}}}|{{#time:Y F|{{{date}}}}}}}
- —Trappist the monk (talk) 10:02, 26 May 2016 (UTC)
- No I want it "unmolested" if the date is correct. Currently I have no way to manipulate
2016 May 26
because #time won't accept it. — Martin (MSGJ · talk) 10:08, 26 May 2016 (UTC) - According to strtotime
2016-May-26
should be okay, so perhaps I can just {{replace}} spaces with dsahes? — Martin (MSGJ · talk) 10:15, 26 May 2016 (UTC)- With a hyphen:
{{#time:Y F|2016-May-26}}
→ 2016 May
- —Trappist the monk (talk) 10:26, 26 May 2016 (UTC)
- With a hyphen:
- I think it would be better to just fix all of the pages that use non-standard date formats. {{MRVdiscuss}} only has 132 transclusions, so it shouldn't take long with AWB or similar. — Mr. Stradivarius ♪ talk ♪ 10:18, 26 May 2016 (UTC)
- I've gone ahead and fixed all of them. Now we don't need any Lua logic, and new pages added with non-standard dates will display a big red "invalid date" error. — Mr. Stradivarius ♪ talk ♪ 12:13, 26 May 2016 (UTC)
- No I want it "unmolested" if the date is correct. Currently I have no way to manipulate
- You might use
Spec-style testing
For those interested I have started on a portal about spec-style testing at mw:Help:Spec. I've written some code to verify that such testing are possible given the current Lua-setup, and so far it seems doable.
Often tests are divided in how to make the right thing, vs how to make the thing right. Spec-style tests are about the later, that is how to make the right thing. The other tests, how to make the right thing is often handled by step-style tests. Several programming languages have some form of spec-style tests, but the RSpec framework in Ruby is among the most well-known. In Lua there is a library "Busted", but the proposed implementation is not using that due to security concerns.
If there are questions on the on-going work, I'll try to answer as best I can, but note that this is work in progress! Jeblad (talk) 16:29, 26 May 2016 (UTC)
Posting to external websites
I am trying to find out if it is possible to post (edit) to wikidata from a lua script in wikipedia? Julialturner (talk) 06:28, 31 May 2016 (UTC)
- @Julialturner: No, it's not possible to edit pages from Scribunto modules (Scribunto is the name of Wikipedia's Lua implementation). Lua modules have roughly the same functionality as templates do. To edit a page, you would need to use a script that accesses the API. — Mr. Stradivarius ♪ talk ♪ 06:38, 31 May 2016 (UTC)
Lua error
Hello everyone! What is this error Lua error in Module:appellatio at line 55: attempt to concatenate local 'page_pron' (a nil value)
saying? -- DenisWasRight (talk) 14:25, 1 June 2016 (UTC)
- The code at line 55 of the Module:appellatio (not on en.wiki), is attempting to concatenate two or more strings into a single string. Commonly, something like:
result = string_one .. ' ' .. string_two;
- where either of
string_one
orstring_two
has anil
value. You can concatenate empty strings:string_one = 'Some text';
string_two = ''; -- empty string
result = string_one .. ' ' .. string_two;
- which gives the result:
- "Some text "
- If you identify where the module is and how you got the error message, someone here can probably provide more specific help.
- —Trappist the monk (talk) 14:48, 1 June 2016 (UTC)
- The error is part of this module. -- DenisWasRight (talk) 16:28, 1 June 2016 (UTC)
- The variable
page_pron
in that module is defined asOne issue (there may be more) is thatlocal page_pron = p.page_pron(lang_code) or p.radix_pron
p.radix_pron
is never defined, and thus always nil. It was defined in the original revision (with a different name), but removed here. SiBr4 (talk) 16:33, 1 June 2016 (UTC)- I change the names because it's in french. Will this solve my problem. -- DenisWasRight (talk) 16:37, 1 June 2016 (UTC)
- It's ok now. Thanksss. -- DenisWasRight (talk) 16:53, 1 June 2016 (UTC)
- I change the names because it's in french. Will this solve my problem. -- DenisWasRight (talk) 16:37, 1 June 2016 (UTC)
- The variable
- The error is part of this module. -- DenisWasRight (talk) 16:28, 1 June 2016 (UTC)
- How can I move the audio template behind the IPA pronunciation. Like in this picture? -- DenisWasRight (talk) 17:26, 1 June 2016 (UTC)