Wikipedia:Lua/Requests/Archive 2

Archive 1 Archive 2 Archive 3 Archive 4 Archive 5

Module:Age

For anyone interested in working with dates, I have created Module:Age. See Module talk:Age. I couldn't find a Scribunto library that implements date functions, but it would probably be desirable for one to be created eventually (or is there something I have overlooked?). Johnuniq (talk) 10:16, 2 April 2013 (UTC)

It looks like it's supposed to be mw.language:formatDate. I haven't had any luck in getting the command to work, though; if I call it as lang:formatDate(U) I get the error "attempt to index global 'lang' (a nil value)", and if I call it as mw.language:formatDate(U) I get the error "attempt to call method 'formatDate' (a nil value)". Is the language library not available on the English Wikipedia yet? I've had a similar lack of success with other functions in the library. — Mr. Stradivarius ♪ talk ♪ 11:00, 2 April 2013 (UTC)
mw.getContentLanguage():formatDate("d M Y") will work. -- WOSlinker (talk) 12:38, 2 April 2013 (UTC)
D'oh... it would definitely help if I read the documentation the whole way through. Thanks! — Mr. Stradivarius ♪ talk ♪ 13:13, 2 April 2013 (UTC)

Need a delink function

Has anyone written a tedious function to delink multi-linked text of several external links or interwiki wikilinks, such as:

wikitext: [[Travel|Gone]] [http://acmeprepositions.com with] [[English articles|the]] [[wikt:Wind]]
delinked: Gone with the Wind

Note the need to delink several simple wikilinks, or interwiki links (such as "wikt:" for Wiktionary), plus external links with "http*". That delinking function would be copied into another Lua module. Thanks. -Wikid77 (talk) 07:30, 30 March 2013 (UTC)

Removing links is easy to do by previewing the text passage and then copying what you see into the edit buffer. It will be copied with no links. EdJohnston (talk) 00:28, 1 April 2013 (UTC). Never mind. I now see the discussion above. EdJohnston (talk) 18:43, 1 April 2013 (UTC)
Um, that's all well and good if you were just editing a page, but if you are getting parameters through a template call, a way of automatically sanitizing inputs is a lot more critical. VanIsaacWS Vexcontribs 09:28, 1 April 2013 (UTC)
Something related has been already done in Template:Unlink, but in very limited scope. --DixonD (talk) 12:25, 1 April 2013 (UTC)
Others probably outskill me, but this isn't something that is easy to do correctly and completely in the presence of comments, nowiki sections and possible sensible (I can't think of any) and pathalogical (I can think of many) cases with brackets within pieces of wikitext which are not to be interpreted as links. Martijn Hoekstra (talk) 16:36, 1 April 2013 (UTC)
This may be hard to do perfectly but it should be easy to do somewhat badly. :) Perfection might involve a good replacement for mw.ustring.gsub that accepts a "plain" parameter, so we can easily pull out all the nowiki texts, comments, etc., process them specially, then gsub-plain them back into the main string again without having to worry that some part of their content will be interpreted as a pattern. (I'm not quite sure how hard that is - I've observed some weirdness like that a captured section header can't be found in the string it came from) Wnt (talk) 21:02, 1 April 2013 (UTC)
I'm more afraid of such pathological cases as "blabla<ref name="[[">urgh</ref>nasty]]" and its many variations. Defining when the template acts the same as the parser, and when it does something else may be hard. I for one can't predict the parser without seeing the preview in many cases. I'm not sure if perfection is the enemy of good in this case. Martijn Hoekstra (talk) 21:12, 1 April 2013 (UTC)
not sure i understand the usecase. can someone give an example where such a functiom will be useful? peace - קיפודנחש (aka kipod) (talk) 21:24, 1 April 2013 (UTC)
I should note the original example gives an example for wikt:Wind - the problem here is that if this is to be changed to "Wind", then the link 4:20 will be changed to 20 (unless we have a table of all the funny wiki prefixes and assume none of them overlap real content items). I tend to hope maybe the OP would be satisfied not to change links like wikt:Wind unless they are written as Wind, i.e. to display that way before unlinking? Wnt (talk) 21:30, 1 April 2013 (UTC) -- actually I should note that this edit written as [[wikt:Wind|]] saved as [[wikt:Wind|Wind]]. Do we really need a special feature for this at all? Wnt (talk) 21:32, 1 April 2013 (UTC)
N.B. I'm presently working on this as functions in my Module:WikiLinkEverything, which badly needs a rewrite and renameModule:WikiLink, which is being adapted to be a general linker/delinker. Wnt (talk) 21:34, 1 April 2013 (UTC)
sorry to be difficult, but i still do not see the usecase. you describe the desired functionality (input is wikt:Wind, output is Wind), but i already understood the functionality, and this is not what i asked: the question was, what is the usecase? what kind of template you see where it makes sense to pass wikt:Wind as parameter and at some point get "Wind" - please note that i'm not challenging the need to do so, and not trying to argue that this should not be done - i am genuinly asking about the usecase. often times when the usecase is understood, better solutions can happen. peace - קיפודנחש (aka kipod) (talk) 22:09, 1 April 2013 (UTC)
In a comment he made over at Module talk:Citation/CS1/Archive 12#COinS genre on 30 March Wikid77 mentioned this request. So my assumption is that the possible presence of links in some argument fields used by COinS was what motivated his idea. In the COinS example there doesn't appear to be a standard regarding the presence of links. EdJohnston (talk) 22:34, 1 April 2013 (UTC)
  • Based on the discussion above, that should have been written as "[[wikt:Wind|]]" to show "Wind". A usecase might be an unsual link of a book title, where just some words were linked, such as "Too Late the [[wikt:Phalarope|]]" linking only some words ("Phalarope") in the famous title "Too Late the Phalarope". We never know how citation titles, or chapter titles, or page numbers might be wikilinked to one or more other webpages. -Wikid77 (talk) 23:45, 1 April 2013 (UTC)
  • Thanks for discussion and no hurry with such complexity: Now that the difficulty has been better explained, even to show the left-side link text for trailing "|" in "[[wikt:Wind|]]", perhaps we should plan about 5 weeks to work on this capability, and definitely allow for HTML-style comments, possibly incorrect comments, where the text would truncate at "<--" as an attempted comment. As for any nowiki-tags, we know they escape inspection as just the internal markers, and so any "[...]" in nowiki-tags will not be scannable with Lua and will become "forced" into the output text. More later. -Wikid77 (talk) 23:45, 1 April 2013 (UTC)
Note presently {{#invoke:WikiLink|main|function=delink dewiki|[[Travel|Gone]] [http://acmeprepositions.com with] [[English articles|the]] [[wikt:Wind]]}} generates "Script error: No such module "WikiLink".". ('wikt:Wind' per my comment above; {{#invoke:WikiLink|main|function=delink dewiki|[[Travel|Gone]] [http://acmeprepositions.com with] [[English articles|the]] [[wikt:Wind|Wind]]}} generates Script error: No such module "WikiLink".) It doesn't presently do anything to Martijn Hoekstra's example .. actually I don't think it's supposed to, but actually, I'm not sure why it doesn't. ;) Wnt (talk) 23:46, 1 April 2013 (UTC)
Before I go to sleep I'd like to note that unit tests are your friend (both to work to a proper implementation, and have a clear picture what is, and what isn't supported). Martijn Hoekstra (talk) 23:51, 1 April 2013 (UTC)
  • Examples: Some other examples:
  • {{#invoke:WikiLink|main|function=delink dewiki|All [[Gone]] [[wikt:to|]] [[Bed]] [[Now]]}} gives "Script error: No such module "WikiLink"."
  • {{#invoke:WikiLink|main|function=delink dewiki|[[A]] [[B|be]] [[C]] [[DDDD]] [[:es:Ahora mismo|]] [[EeE]]}} gives "Script error: No such module "WikiLink"."
  • {{#invoke:WikiLink|main|function=delink dewiki|[[A]] [[B|be]] [[C]] [[DDDD]] [[EeE]]}} gives "Script error: No such module "WikiLink"."
  • {{#invoke:WikiLink|main|function=delink dewiki|[[Survey]] of [http://books.google.com Google Books] on [[UK|Britain]]}} gives "Script error: No such module "WikiLink"."
There have been problems where an interwiki link with a vertical-bar pipe ("|" or "wikt:_|" or ":es:_|") would hide the prior links in the text. -Wikid77 (talk) 15:08, 2 April 2013 (UTC)
Hmm. How about doing a first parse over the sentence to find the word boundaries, and then storing each of the words as items in an array so that they can be processed individually? — Mr. Stradivarius ♪ talk ♪ 15:35, 2 April 2013 (UTC)
I had a look into this, but the deeper I went, the more I realised that I was just rewriting the parser from scratch, badly... it was the part where I realised that you need to keep track of which links can't be parsed, in order to stop trying to parse them again, where I gave up. :/ Probably the easiest way to write a de-linker would be get the devs to write a hook from Lua to the parser itself, so that we could de-link things without duplicating the dev team's efforts. — Mr. Stradivarius ♪ talk ♪ 18:41, 2 April 2013 (UTC)
I was already afraid of that. A regex based approach may be catch something, but like a said, complete and correct may be a bridge too far. Would defining that the template only works in the presence of no tags be sufficient? Is the code you have so far on-wiki? Martijn Hoekstra (talk) 18:58, 2 April 2013 (UTC)
I just finished coding up what I'd been working on. It's at Module:User:Mr. Stradivarius/sandbox2, and at the moment it can de-link one internal wikilink, as long as it doesn't use the pipe trick, and as long as it's not a bad link. (The bad link detection still needs work - it only detects square brackets at the moment.) It should be usable as a function inside Module:WikiLink if anyone wants to try that out. Bed time for me though. — Mr. Stradivarius ♪ talk ♪ 19:21, 2 April 2013 (UTC)
Well, you have a succeeding unit test! Onward! I would suggest starting out with accepting that there will not be a complete implementation, but narrowly defining the cases where you expect success. I would suggest for a start: only text containing well-formed links, not containing any other markup. Martijn Hoekstra (talk) 19:52, 2 April 2013 (UTC)
Thanks for catching the bug in WikiLink - I had one .- that I hadn't changed to a [^%[]- and that's what did it. Wnt (talk) 04:30, 3 April 2013 (UTC)
  • I've been busy, and despite what I said before, I have coded up Module:Delink which de-links almost all wikitext, including the pipe trick and nested links. There are still some unit tests that don't succeed, but the vast majority do - see Module talk:Delink/testcases. That said, it could do with a lot more input being thrown at it as there are bound to be things that I haven't thought of. Please try and break it if you can. :) — Mr. Stradivarius ♪ talk ♪ 00:31, 4 April 2013 (UTC)

Need automatic formatters

I think we should have a module that converts templates like that Albumchart and modules like (any one of my own written before the style guide) automatically into standard format.

I remember having some trouble with templates improperly expanded with "[[:Template:]]" showing up, though {{#invoke:Page|getContent|Albumchart}} (I won't include the whole mass here) seems to handle the current template fairly accurately to a glance. If we can reliably import the unparsed template code, we could write a module to put it all in a standard format with indents and colors that would make it much easier to read and understand, which would help with quickly coding Lua equivalents.

I'm thinking that it should be named something simple like Module:Format and have functions "lua" and "template" to handle the two kinds of code.

Of course, it would be necessary to come up with the full specification of how the Lua should be formatted first, which words to indent and unindent on, whether "else if x then" still gets a four+four-character indent beneath it rather than five+four, all the tricky little things, to make sure it does it right. (And it should be able to do tabs if/when the editor supports them)

It would be even more necessary with templates to be really careful that every added newline or space was safe for its operation! (Presumably this could be done with comments, even comments written in white font for purposes of display).

I feel like I could do this, eventually, but I don't think I'll get to programming it until after the holiday. Meanwhile, any suggestions? Wnt (talk) 17:41, 27 March 2013 (UTC)

there is lua style guide somewhere - methinks on mw:. the short of it is: no tabs, one-line "if" and "for" are ok, but not if they contain many operations. i.e.:
if condition then someAction() end is perfectly fine, but
if condition then action1(); action2(); action3(); end is not.
one space between1 () or {} and their content, but 1no1 space for []
i.e.: callFunc( param1, param2, { item1, item2 } )
but a[i] and not a[ i ].
as to elseif: see my miniature module above for danish diactritics - this is the standard.
the rules are as similar as possible to the javascript style guide. personally i do not like the extra spaces inside () and {}, and i prefer tabs to spaces, but i try to adhere to the guide for WP work. if someone finds a link to the style guide it would be nice - we should probably link to it from one of the pages linked from the tabs at the top of this page. peace - קיפודנחש (aka kipod) (talk) 17:59, 27 March 2013 (UTC)
One style guide is Wikipedia:Lua style guide and it's listed under the Help tab. But I don't think it's comprehensive. Wnt (talk) 18:18, 27 March 2013 (UTC)
Oh, wow - I hadn't even noticed "elseif" was valid in Lua. I'll have to fix a few... or maybe I'll leave it to a module :) Wnt (talk) 18:20, 27 March 2013 (UTC)
the idea is to share code as much as possible among wikis, so any style guide shoul be in mw or meta, not enwiki, IMO. peace. קיפודנחש (aka kipod) (talk) 12:45, 30 March 2013 (UTC)
I implemented a simple formatter at Module:FormatTemplate, but it is processor-heavy and I don't think it can handle the entire Albumchart template, unfortunately. There are likely ways to optimize it much further, but it might require rewriting it from scratch with some very creative usage of mw.string commands. Wnt (talk) 04:17, 3 April 2013 (UTC)
I've since sped it up a little and implemented a crude continuation feature, but another problem is that table formatting commands use pipe characters and can't readily be distinguished unless tables are also parsed - but table parsing is a vast morass of alternate strategies with th, td tags, tags like "|}" that can appear in multiple contexts, even templates used to assemble them. There is no easy way to indent text at pipes and not end up screwing up the tables. Without some inspiration the module may be relegated to displaying template format rather than actually doing it. Wnt (talk) 16:26, 3 April 2013 (UTC)
IMO this does not make any sense at all. there is no justification to create these formatters in Lua. it makes much more sense to do this formatting in JS, and integrate it in the editor (as a gadget or usaer script, of course). i can go on and explain why i think so in details, but i'm not sure it's needed. 5 minutes of thought will show anyone why it's obvious. peace - קיפודנחש (aka kipod) (talk) 18:29, 3 April 2013 (UTC)
I'm afraid it is needed. I only started learning Lua right before the roll-out, and I still don't really know what it's good and bad for. I tend to jump into whatever idea I think up for it and see what happens. I had hazily imagined that a module like this might even end up directly transcluded into the template documentation template, so that a readable, colorized format of every template would be a click away from any user. I understand Javascript can do the same things, but... my feeling is that, whatever idea a person comes up with for JS, the reality is, nobody is going to change their JS preferences to actually use it. Javascript comes with a security warning that deters them even if they want to, but Lua is supposed to be guaranteed safe for use by all. Wnt (talk) 23:51, 3 April 2013 (UTC)
I used this recently to add the expansion of the module and submodule to Template:Pie chart/doc. Using this I was better able to appreciate the structure of the template for purposes of translating it. I won't claim it was a tremendous improvement, but with something like that every little bit helps. Wnt (talk) 20:45, 5 April 2013 (UTC)

ISBN validator

Anyone want to try their hand at taking an ISBN string and determining if it is valid (has the correct check digit)? Dragons flight (talk) 06:30, 9 April 2013 (UTC)

Nevermind, I seem to have already figured it out, Module:ISBN. Dragons flight (talk) 08:50, 9 April 2013 (UTC)

UrlToWiki

For those of you who like to properly format their wikilinks, but who dislike separately copying and pasting page name and section name -- I have created Module:UrlToWiki, which takes URLs of pages from most Wikimedia wikis and outputs wikilinks with appropriate interwiki prefixes for the local wiki. So {{#invoke:UrlToWiki|urlToWiki|1=https://en.wikipedia.org/wiki/Wikipedia:Village_pump_%28policy%29/Archive_102#Using_.7B.7BComment.7D.7D_on_articles}} gives Script error: No such module "UrlToWiki".. Have a look at Template:Urltowiki for usage instructions and more examples. — Mr. Stradivarius ♪ talk ♪ 22:43, 9 April 2013 (UTC)

See also User:js/urldecoder for a similar functionality in Javascript. EdJohnston (talk) 01:34, 10 April 2013 (UTC)
Hmm, I didn't know about that! Ah well, having more choices can only be a good thing, right? Also, I should mention that in the course of creating this module I have also created Module:InterwikiTable, which can be accessed with mw.loadData(). If anyone writes any functions that process interwiki links, it could come in handy. (Feel free to add to it if you need to, as well.) — Mr. Stradivarius ♪ talk ♪ 13:08, 10 April 2013 (UTC)

Autocount

I want to use a template without any arguments that evaluates to an autoincremented number something like this: "text {{inc}} more text, {{inc}}, {{inc}} {{inc}}{{inc}}... {{inc}}". And I want the result to be like this: "text 1 more text, 2, 3 45... 6". I have tried to call a template that calls some Lua script but all I can get is ones since the scripts resets for every instance it runs. It is to be used in a wikibook to number the exercises so it is possible to add one in the beginning and have all the rest automagically adjust their numbering. - Averater (talk) 16:57, 7 April 2013 (UTC)

One of the design goals for Scribunto was that each #invoke call should be independent, so no communication between instances. Which means that this is not possible, and if you figure out a way it's a bug and should be fixed. BJorsch (WMF) (talk) 17:23, 7 April 2013 (UTC)
This can be done. The idea is that you have a tag <inc> that your Lua module processes by importing the entire title=mw.title.currentTitle();text=title.getContent(title) - then you do a string find and replace on the <inc>, and return the output as frame.preprocess(frame,text). A trailing <span style="display:none"> can prevent the actual page contents from showing, so you can put the #invoke in the very beginning and still affect the whole page. Mostly easy, except... when I fool around with this, I tend to get out of date versions of the page somehow. If you make a small page somewhere else that reads in your page and does this to it, it seems to stay up to date properly. I think. Wnt (talk) 17:40, 7 April 2013 (UTC)
Oh yeah, I forgot about crazy hacks like "pass the entire page through Lua for a global search-and-replace"... That's not a bug, of course. ;) Anomie 20:22, 7 April 2013 (UTC)
OK, at least your instance works at Module talk:TextMarkup. Wnt (talk) 18:24, 7 April 2013 (UTC)
Thank you! Sorry it took so long for me to reply but I had some problems adjusting it more to my needs and there is still some problems... (Module: Modul:Numrering used in Template: Mall:Uppgifter which in turn is used to include content into for example this page 3D-Geometri) - Averater (talk) 16:53, 9 April 2013 (UTC)
Seriously, this looks more like a task for HTML than for a module. For example:
  1. Line item 1 is enclosed in a span which encompasses several paragraphs but is parsed as one line
    unless you use br / that is!
  2. Item #2 is

    in a big div

    and should therefore respect the double-return though I'm not sure why

  3. #3 etc.

Wnt (talk) 23:51, 17 April 2013 (UTC)

Article history

Can someone convert Template:Article history to Lua? The code would be made a lot more comprehensible. (By the way, I already suggested this a few weeks ago, but it got archived without a single response.)Ypnypn (talk) 23:43, 16 April 2013 (UTC)

This looks like a long, slow, tedious task, made the harder by the protected status requiring everything be sandboxed... I've taken the liberty of adding one of my templates, even though it isn't really ready, to the documentation page [1] so people can look over the template's structure more easily... Wnt (talk) 23:45, 17 April 2013 (UTC)
Actually, I just found this, which is just what we need. -- Ypnypn (talk) 23:59, 17 April 2013 (UTC)

Dates

It would be great to have a module for converting dates between different calendars. We have a lot of templates that may use it in Category:Time, date and calendar templates and its subcategories (Category:Calendar templates, Category:Date-computing templates and so on). --DixonD (talk) 09:18, 17 April 2013 (UTC)

Where would you suggest would be a good place to start? For example, what is an example of "converting dates between different calendars", and is it used often? See #Module:Age above for an announcement of a module which is a small start towards implementing date functions. Johnuniq (talk) 10:08, 17 April 2013 (UTC)
I would suggest to start from implementation of conversion functions from some "standard" date/time (Julian day seems to be a good candidate for standard date) to date/time in the Gregorian and Julian calendars, and back. Later it can be extended to all other calendars. An example of conversion usage are templates Template:Year in other calendars, Template:JULIANDAY and a bunch of others in the mentioned categories. --DixonD (talk) 10:47, 17 April 2013 (UTC)

I have the following idea in my mind - to have a general module, let's say Module:Datetime, which would contain general functions that take a desired calendar option as an extra parameter. And then we create a separate submodule for each calendar. Thus adding new calendars wouldn't require to do big changes to the main module. So, for instance, in the beginning of Module:Datetime we load submodules Module:Datetime/Gregorian, Module:Datetime/Julian etc into some table, and then let's say we have function toStandardTime. This function would take an extra parameter ("calendar" or the first unnamed) and then we just call toStandardTime of a proper submodule judging on that extra parameter "calendar". Does it make any sense? Maybe I will try to do some stuff by myself, but I don't know when I have a chance for that. --DixonD (talk) 08:49, 18 April 2013 (UTC)

Likewise I'm not sure when I would get around to another project like this, however I am interested and feel free to contact me on my talk page if ever wanted. I'm still not sure what the main usage would be—assuming everything you said was implemented, what is an example of how it would be used? Module:Age implements {{Gregorian serial date}}, but that starts at 1 AD. Further, it makes no allowance for the missing days in 1582. The gsd code in Module:Age is very short, so if it is correct I'm not sure it would be worth having it in a separate module. If you have a good understanding of the algorithms but are not yet up to speed with Lua, we might make a good team. Johnuniq (talk) 09:53, 18 April 2013 (UTC)

There are templates de:Vorlage:JULGREGDATUM or pl:Szablon:Data, which are localized variants of Template:OldStyleDate. Currently the DE and PL versions took onlyI'm lying but it is enough for explanation here. gregorian time (the standard one) as parameter and produce output in both the old (julian) and the new (gregorian) format calculating the proper julian date automatically. As I am the author of Polish version of the template, which is based on the German source, I was asked by one of wikipedians to expand the template with an argument to select the calendar type. In that case it was French Republican Calendar. However I rejected the request, explaining that it could make the template source too complicated. Introducing LUA gives an opportunity to create module that make such functionality for different historical calendars with better error checking for different variants. Different countries accepted gregorian calendar on different dates, and as I remember the New Year in the Old Style was not on 1st January. BTW The template is mostly used to format born dates of people i.e. George Washington. There is only a few events requiring it, maybe October Revolution however due to timezone shift the calculation might be still broken. Paweł Ziemian (talk) 12:54, 22 April 2013 (UTC)

For those who are interested, some work is already done by some fellow Wikipedians in these modules: Module:Sandbox/DixonD/DateTemplates, Module:Sandbox/DixonD/Datetime, Module:Sandbox/DixonD/Datetime/Gregorian and Module:Sandbox/DixonD/Datetime/Julian. The testcases show the current state of development: Module talk:Sandbox/DixonD/DateTemplates/testcases Feel free to join and help finish this stuff. --DixonD (talk) 07:24, 25 April 2013 (UTC)

It should be also a good candidate for converting into Lua as inner templates are quite expensive and have limitations. --DixonD (talk) 07:11, 25 April 2013 (UTC)

Template:Loop15 has over 530,000 transclusions. It can probably be rewritten using a Lua module (or rather Template:Loop can probably be rewritten and Template:Loop15 can be turned into a redirect). --MZMcBride (talk) 21:25, 24 April 2013 (UTC)

it does not make sense to create a new module - we already have Module:String. unfortunately, this module is protected (only sysops can edit it), but it's a one-liner (lua string object has a "rep" function) maybe something like
function str.rep( frame )
    return string.rep( frame.args[1] or '', tonumber( frame.args[2] ) or 0 )
end
and then Template:Loop becomes something like {{#invoke:String|rep|{{{2|}}}|{{{1|0}}}}} (100% untested, but modulo bugs, this illustrate how difficult the task is). i do not think creating a new module just because one function was forgotten outside of Module:String makes sense.
one can get slightly more fancy, by actually firing an error message if param #1 is not a number instead of using "0". strangely enough, this would actually make the code 5 chars shorter (just remove the " or 0")... peace - קיפודנחש (aka kipod) (talk) 21:49, 24 April 2013 (UTC)
Well, if you put that code in Module:String/sandbox and make some test cases then I'll update the module for you. Or you can use {{edit protected}}. The module being protected isn't such a big barrier to having it edited if you know what you're doing. :) — Mr. Stradivarius ♪ talk ♪ 09:30, 25 April 2013 (UTC)
There is Module:String/sandbox which is available to edit. -- WOSlinker (talk) 09:31, 25 April 2013 (UTC)
i created User:קיפודנחש/sandbox/Module:String which is a copy of Module:String with one added function, namely "rep". I also added some testcases for this function. for some mysterious reason, one of the testcases (one that's intentionally generate an error message) fails on the "compare" of actual and expected results. could not fathom it, so for now, there is one "failure", however, the expected and actual look the same to me, and the failure is only when passing bad parameters (non-numeric value for the number of repetitions). anyone with appropriate rights is welcome to copy User:קיפודנחש/sandbox/Module:String back to Module:String. (i also added "source" tag, in lua comment, of course, so it displays nicer when copied outside "module" space, but this is practically meaningless). once it's copied onto existing module, the templates can be changed to use it (this will also have to be done by a sysop). peace - קיפודנחש (aka kipod) (talk) 19:14, 25 April 2013 (UTC)
The html was identical for both error messages, so I'm forced to conclude that the reason it wasn't passed is a limitation in Module:UnitTests or in the MediaWiki software. I've updated Module:String for you. So, the next step is the templates, but these will need to be sandboxed and tested as well. It's pretty easy to make a slip with the #invoke command, so we shouldn't take any chances. Same deal - if you set the test cases up and everything works, I'll update the templates for you. — Mr. Stradivarius ♪ talk ♪ 10:57, 26 April 2013 (UTC)
Most of the uses of {{Loop15}} were through the use in {{Spaces}}. I've updated Spaces to use the String function. -- WOSlinker (talk) 18:42, 26 April 2013 (UTC)

Can anything be done there with Lua in order to 1) improve performance 2) simplify the syntax and usage somehow? --DixonD (talk) 19:35, 11 April 2013 (UTC)

It is about this for example. It is very suitable for Luaification I'd say.
For example putting the nested templates into one (basically it is three levels, for the template editor that is), and having the "number of scheme columns" as a parameter, instead of variant templates {{BS1}} ... {{BS9}}. On the other side, the WP:ROUTE community could help by being rigourous, consistent and systematical in defining (re-defining?, documenting & legend-ising) scheme dimensions like color meanings, orientation/direction, meaning, &tc &tc. For example, in the Lua-ified single template I'd like to note once that I need 5 columns, that all routes by default should be Red-for-Rail, and that all metro station logos in my template are Berlin's. At the moment, many much of these independent properties are folded into a single code for a very short imagename like File:uAKRZu.svg (this is a highway on a bridge).
For those new to this topic: it originates from the German WP (icon BS=Bahnstrecke: stretch of rail; icon BHF=Bahnhoff: railway station). All icons, small elementary svg images, and their templates are on commons.
I do not mean to diminsh the contributions that build the whole: great! (I could build this and this); I just want to say that we can do systematically better with Lua. -DePiep (talk) 18:22, 14 April 2013 (UTC)
  • Improving markup speed but maps need graphics editor: I am working to make those templates run 3x times faster. Typically, a diagram or map would be generated using a computer-graphics editor, where lines were drawn, curved and moved by cursor motions, and map symbols would be selected from point-and-click symbol menus. Then the whole map would be stored as a rapid, composite image, rather than re-generated live from tiny map-square pictograms, each resized to fit within the overall image. Instead, the route-map editors have created enormous sets of thousands of map-square icons (more than 8,000 named symbols), where editors can copy parts of other route-map templates to create or expand various maps. The current maps, used in over 11,000 pages, are based on those 8,000 Kanji-like, pictogram symbols to display the "routenese" language as map squares joined together, to appear as lines, curves, and map markers. The first phase should focus on merely making those current templates run much faster. Also, there could be documentation expanded to help search for symbols, where the icon-pictogram names are likely to mystify new users, but who would then search for related words in descriptions about those pictograms ("parallel rails turning right"). Because of the prior 11,000 pages using the route-maps, the current templates, as {{BS}} to {{BS12}} (12 lanes wide), should be retained, and hopefully, the ability to copy/paste from the related maps will help new users cope with the routenese symbol language. Meanwhile, new maps could be generated in a graphics editor, with various labels hard-coded into the image, for users who do not want to cope with the limitations of the 8,000 icon-pictogram symbols (hundreds still undrawn as redlink images). There need to be a variety of technologies for creating the route-map boxes. However, it would be a massive task to redesign as multi-lane Lua map functions, particularly for people not familiar with the current 8,000 pictograms. -Wikid77 (talk) 19:34, 27 April 2013 (UTC)
  • Route maps quickened 3x faster by {BS-overlap}: Today, at 09:12, 28 April 2013‎, the route-map formatter Template:BS-overlap was updated (for the first time in 3 years) to use quick icon-overlay by {Template:Superimpose5} and omit {BS-alt} which was setting alt-text for each pictogram. Those changes have allowed many route-map diagrams to reformat about 3x faster. Unfortunately, the update also dropped the image-links (to each pictogram image-description page), which is likely improper handling of artwork-attribution links. Anyway, that update allows testing to confirm how the route diagrams can be edit-previewed 3x times faster now, and further updates can be discussed at WT:Route_diagram_template. -Wikid77 (talk) 10:13, 28 April 2013 (UTC)

Total newbie can't get a basic script to work

Hi everyone,

See:Module:Sandbox/Yaris678 and User:Yaris678/Sandbox

I am just trying to write a script that concatenates the word "test:" in front of the string that is input but I can't get it to work. I would really appreciate a pointer.

Yaris678 (talk) 20:51, 1 May 2013 (UTC)

Seems to be working fine now I'm on a different machine. I guess it was either a caching issue or the really old browser that was on the previous machine. Yaris678 (talk) 22:37, 1 May 2013 (UTC)
Oh... It was because of this change! Thank you Dragons Flight! Yaris678 (talk) 06:23, 2 May 2013 (UTC)
Your problems were due to the way the interface between Lua and MediaWiki works. I also had problems understanding it at first, as it is quite a jump from doing template coding. Basically, Lua modules on Wikipedia have to be set up in a very specific way for them to be accessible from normal wiki pages. First, the modules have to return a table. This is the part of the module that goes:
local z = {}
-- Module code
return z
Next, that table has to contain a function. This is the part of the module that goes:
function z.test( frame )
    -- Function code
end
Note that you can have functions that aren't items in the table, but that those functions aren't directly accessible from normal wiki pages. Now, if you have a function that is a member of the table that the module returns, and you give that function a parameter (in this case, the text "frame" inside the brackets), then the software does some magic that lets you interface between Lua and MediaWiki. The software makes your parameter a frame object, which is a Lua table that contains information about the #invoke command used to call the module, as well as a few other things. It doesn't matter what you call the parameter, whether it is "frame", "n", or "monkeys" - it will always be a frame object. So your previous parameter "n" was actually a table, not the value of "ABC" that you thought it was. Because you tried to concatenate a table to a string value, you got an error. The usual way of doing this is as Dragons flight showed you:
local z = {}

function z.test( frame )
    return "test:" .. frame.args[1]
end

return z
Here, frame.args is a sub-table of the frame object that contains the arguments passed to #invoke, and frame.args[1] is the first field in that table. (Or in other words, frame.args[1] is the first positional argument passed to #invoke.) This could also work with your parameter "n", like this:
local z = {}

function z.test(n)
    return "test:" .. n.args[1]
end

return z
And finally, if you passed a named argument to #invoke, e.g. {{#invoke:Sandbox/Yaris678|test|foo="ABC"}}, then you would need to use frame.args.foo instead of frame.args[1]. Hope all of this sheds some light on the situation. :) — Mr. Stradivarius ♪ talk ♪ 10:31, 2 May 2013 (UTC)
That's really helpful. Thanks.
I am currently trying to work out the order that MediaWiki does stuff. See my sandbox.
It seems that MediaWiki will mostly parse the output from the Lua script but the <nowiki> tag is left as is.
Is this sort of stuff explained somewhere? I notice that mw:Extension:Scribunto/Lua reference manual#Returning text indicates that curly brackets aren't processed but it doesn't mention <nowiki>.
Is there a way to get MediaWiki to process the <nowiki> tag?
Yaris678 (talk) 12:50, 2 May 2013 (UTC)
<nowiki> tags are a special case. They can't be used as-is in Lua because that would break the software, so instead they (and their content) are converted to a "strip marker". Strip markers are mentioned here in the manual and you can see a little bit more detail at Wikipedia:Strip markers. — Mr. Stradivarius ♪ talk ♪ 13:28, 2 May 2013 (UTC)
Interesting. Thanks. I was hoping to use Lua to create a version of {{Nowiki}} that could be transcluded, rather than substituted. But maybe that's not possible. Ultimately, what I want is to be able to put a nowiki on the input to a template. This would allow us to remove an input to {{markup}} that is basically a repeat of another input. Yaris678 (talk) 17:15, 2 May 2013 (UTC)
The Lua function mw.text.nowiki( string ) should give visually the same results as &lt;nowiki&gt;string</nowiki> in most cases. One issue is that template and tag expansion happens before Lua is called, so one can't use Lua to nowiki a block that contains templates or tags (e.g. &lt;ref&gt;). Dragons flight (talk) 17:28, 2 May 2013 (UTC)
Awesome! That's exactly what I need. See below. Yaris678 (talk) 08:12, 3 May 2013 (UTC)
Markup Renders as
[markup]

[rendering]

If anyone is interested, I have documented some cases where this does and doesn't work. It can be seen at User:Yaris678/Markup. There is also some discussion at User talk:Yaris678/Markup. Yaris678 (talk) 00:19, 8 May 2013 (UTC)

Json

Is there any native support for json?Smallman12q (talk) 02:14, 3 May 2013 (UTC)

Not that I know off, but why would you want to do that? The only things I can think off is pulling in external data through some API, and - if that is even possible - sounds like a terrible idea to me, or to create on-wiki pseudo-databases with json content, which, if they are even reachable, sounds equally horrible to me. Martijn Hoekstra (talk) 17:05, 8 May 2013 (UTC)
No. See mw:Module:JSON and d:Module:JSON for possible workarounds. Legoktm (talk) 12:19, 12 May 2013 (UTC)

Hello. Is it possible, to add a new function to this module, which counts the list items? This could be used in templates where before or behind the list appears an information about the number of list items. The function "count" could return the number of items. Greetings --Tlustulimu (talk) 11:57, 11 May 2013 (UTC)

I copied the message from the template discussion page. --Tlustulimu (talk) 13:19, 11 May 2013 (UTC)
Hello. I just created a sandbox.
{{#invoke:listify/sandbox|input|;|what is this; i don't even}}
{{#invoke:listify/sandbox|count|;|what is this; i don't even}}

{{#invoke:listify/sandbox|input| .. |1 .. 2 .. 3 .. 4 ..}}
{{#invoke:listify/sandbox|count| .. |1 .. 2 .. 3 .. 4 ..}}
returns

Script error: No such module "listify/sandbox". Script error: No such module "listify/sandbox".

Script error: No such module "listify/sandbox". Script error: No such module "listify/sandbox".

It works! --Tlustulimu (talk) 21:45, 12 May 2013 (UTC)

License templates

Is it feasible to create a Lua module that will judge (the best it can) a copyright status in different countries according to some parameters fed: the date of the first publication, the date of the author's death, the country of the first publication? --DixonD (talk) 13:58, 14 May 2013 (UTC)

I would say that this is possible. I am looking at this matter from an copyright standpoint and whether there is an possibility to calculate whether an work an possible copyright infringement or not. I am thinking about calculating that then from an standard copyright term, when possible. For most countries the following formula can be used:
death of author + x years = copyright expiry date
Those x years depend on the country where the work was first published. I assume that could be pulled from an list, an lua switch, maybe. Then, when we have the copyright expiry date, it´s just a matter of comparing it with the current date. If the copyright expiry date is in the future, then the file is an possible copyright infringement, else it is perfectly legal.--Snaevar (talk) 14:36, 17 May 2013 (UTC)
I'm trying now to implement this on Ukrainian Wikisource: s:uk:Module:PD-auto. The idea is that for each country of the original publication we can have a separate submodule which would calculate if it is in public domain or not in this country and if it was in public domain before URAA date which may vary for each country. Then basing on this information we can calculate the copyright status in the United States and produce the final message. I have some tests here: s:uk:Обговорення модуля:PD-auto/тести. Sorry, messages are in Ukrainian but I think it would help you to get the design idea. If you are willing to join, I can port existing code somewhere here, on English Wikipedia. --DixonD (talk) 04:42, 22 May 2013 (UTC)

Parameter input: separate value from reference

Please see {{infobox californium}}, using {{infobox element}}. The input parameter requires the value (measure), the unit is added (like "K" for Kelvin). |boiling point K=1743<ref>...</ref>Boiling point | 1743[3] K. Not, as intended: 1743 K[3]. Is it possible to distinguish and separate the <ref></ref> from the value, so that we can set the sequence right (value -- unit -- reflink)? I guess separation (recognition) should happen for all possible ref forms (like {{cite web}} too). Secondary, also <span> tags could be catched, to allow text additions same way: 1743 K (estimated). -DePiep (talk) 08:38, 14 May 2013 (UTC) (fixes -DePiep (talk) 09:16, 14 May 2013 (UTC))

The ref tags are converted to strip markers before they enter Lua. You can process the strip markers using a search and replace (search for "Remove any [[Help:Strip markers]] representing ref tags" in Module:Delink for an example where I remove them). You should be able to move the strip markers around without affecting the reference content, so I don't think you should have any problems with what you want to do. I've not tested it myself, though. You can also remove the strip markers, which removes the superscript link but doesn't remove the reference from the reference section. It is also possible to filter out strip markers that represent references from strip markers that represent other kinds of content by searching for the "-ref-" text in the middle. (Module:Delink does this.) Hope this helps. — Mr. Stradivarius ♪ talk ♪ 09:08, 14 May 2013 (UTC)
Thanks. Will research this route. -DePiep (talk) 09:16, 14 May 2013 (UTC)
Will sandbox this, to remove the ref (keep the value) and, mirrored, to extract the ref (to add in the end of the output). Anything on alpha-stability of the module? -DePiep (talk) 08:13, 15 May 2013 (UTC)
The module still needs a lot of testing, although the basics are there. There are a ton of edge cases that I need to get handled correctly, and I still have to add support for stripping file links. I also want to remove the expensive parser functions so that it can be used in more performance-critical applications, e.g. for citation templates. I've been tied up with mediation stuff lately, but that is set to finish very soon, so I might look into making it more stable in the next few weeks. — Mr. Stradivarius ♪ talk ♪ 15:48, 23 May 2013 (UTC)
  • Hide reftags in div-tags then {choptext}: Hopefully, the Lua module can be written to exclude the reftags, but meanwhile, using a div-tag, to encapsulate a reftag, will enable Template:Choptext to remove the tag, leaving a valid number for calculations, while also allowing the footnote to appear:
  • For value 45 with div-tag, 45<div><ref>xx</ref></div> → 45
  • Choptext value 45 with reftag:   {{choptext|45<ref>xx</ref>|<}} → 45[2]
  • Choptext value 45 with div-tag: {{choptext|45<div><ref>xx</ref></div>|<}} → 45
The peculiar encoding of reftags with strip-markers causes many bizarre problems which will confuse most editors, and so such parsing of reftags is an unfortunate nightmare in the design of the wiki-markup text. -Wikid77 (talk) 08:17, 17 May 2013 (UTC)
So far I'm able to catch the well-formend refs at end of text, using the delink module. Problems arise when there are more tags like <span> in the string. to be continued. -DePiep (talk) 08:52, 17 May 2013 (UTC)

Charts

I was thinking about a module that will allow creation of charts from templates. Currently, I can only think of a way to implement bar charts (e.g., using <div> elements, with absolute position, background color and forced dimensions). I thought of three types of graphs: one with a single data type (say, population in 1970, 1972, 1974...), and multiple data types: e.g. population of 4 different towns in 1972, 1974, 1976...

The 2nd case also divides into two sub-cases: whether all the data uses the same scale, or different scales: for instance, one may want to display a chart that will show population and phosphor concentration in the water, so two (or more?) separate Y-scales will be needed.

Implementation is not that difficult, the hard part is selecting a reasonable syntax that will be sane and convenient to use, yet powerful enough to allow creating useful charts.

RFC: bar-chart syntax

This is what I have now. The idea is to use keys in the form of "Key n" or "Key n m" where n and m represent numbers.

So here goes:

{{ bar chart
| width = 
| height =
| value 1 1 = 
| value 1 2 =
| value 1 3 =
| value 2 1 =
| value 2 2 =
| value 2 3 =
| color 1 = 
| color 2 = 
| title 2 1 =
| x legend 1 =
| x legend 2 =
| x legend 3 =
| y legend 1 =
| y legend 2 =
}}

so this example is for two different groups, with 3 data points each. each group has a color and y-legend, and each data-point has x-legend. mapping to the example above, the groups represent town A and town B, and the data points represent 1972, 1974 and 1976. in the 2nd example the groups represent population and phosphor concentration.

each bar has a tooltip. if there is a "title x y =" for this bar, this will be the tooltip. otherwise, the tooltip will be the numerical value of the bar.

I do not like the proposed syntax all that much, I just could not think of a better one. will love to hear a better proposal.

Bar-chart Comments

I would suggest that it would be much more friendly to editors to consolidate values as lists rather than adding a new key for each value. For example:

{{ bar chart
| width = 
| height =
| group 1 = value1, value2, value3
| group 2 = value1, value2, value3 
| color 1 = 
| color 2 = 
| x legend = label1, label2, label3
| y legend = label1, label2
}}

That would require the module to parse the comma separated (or otherwise delimited) lists, but Lua is certainly capable of that, and it should be less of a pain for editors. Dragons flight (talk) 18:35, 21 March 2013 (UTC)

this makes sense. 2 comments though: the first is that comma is not a good delimiter: we should allow people to feed values in "language formatted numbers", e,g, 13,542.44 i tend to go for a colon as delimiter, but senicolon will also do. the the reason i did not use this syntax to begin with (i did think of something similar) is the desire to allow skippage: some of the values may be available to some of the groups only. however, after seeing your comment i realized that this was just silly: we can easily provide for missing values by repeating the delimiter.
bottom line: i like your improvement, with the stipulation of changing the delimiter. (same reservation for the labels - we don't want to disallow commas or other punctuation marks in the labels. peace - קיפודנחש (aka kipod) (talk) 19:02, 21 March 2013 (UTC)
I like semicolons more than colons, but I don't think it is a big deal either way. More significantly, one could easily add a parameter that allows users to configure the delimiter, as long as the default value is something sensible. Dragons flight (talk) 19:16, 21 March 2013 (UTC)
Maybe allow for an escape character (traditionally the \)? then you can have Django\: Unchainded as a label. You know, when we want to use the wrong name for a movie. Martijn Hoekstra (talk) 20:19, 21 March 2013 (UTC)
I would very much enjoy building a prototype, but my html/css-fu is weak. Could someone whip up a fiddle with an example? If I try to align those bars one more time to the bottom of the div, I think I might start crying. Martijn Hoekstra (talk) 21:30, 21 March 2013 (UTC)

There are quite a few examples of bar charts made with HTML/CSS here. As for the data format, I think comma-separated values would be a good starting point, as an editor with a large dataset is likely to already have it in CSV format, or be able to easily export it as CSV. We could write a general CSV parser module a la Apache Commons CSV that can be configured with different delimiter characters, escape characters, fixed-width formats, etc., as it could come in handy with other templates for displaying rich data sets. Toohool (talk) 23:20, 21 March 2013 (UTC)

My Module:ImportProtein is sort of like a bar chart. The key is to have an outer div with position:relative and an inner div with position:absolute. Use top: and left: to position. I did mine with all absolute px values - I'm guessing % would work. Note that this is the reason why I suggested setting a forum for html help in coding above. Oh, and Module:Plotter was a really simple case (scatter, not bar). Wnt (talk) 01:06, 22 March 2013 (UTC)
I've now expanded Module:Plotter with a "bar" function. However, I haven't touched the labels yet, which are probably the most aggravating part of all. Wnt (talk) 03:30, 22 March 2013 (UTC)
Update: after an amazing number of blunders, I finally got simple legends working also. Wnt (talk) 23:18, 23 March 2013 (UTC)
Well, I had a fun run trying to get the basics to work, but still chocked on the HTML/Style: It's just not my thing. I'll get cracking on the general purpose CSV stuff though. Martijn Hoekstra (talk) 01:56, 24 March 2013 (UTC)
I'm not sure where you were doing this, so I can't comment specifically, but: the core aggravation with html styling is that with many kinds of error you don't see anything at all. It is good to add lots of bits of unique text wherever you can put them in your divs and spans, and look for them in the HTML source code when you load the page to see if you get them at all and what the style being output really is. We really should have a help forum for HTML - come to think of it, there might be something at Wikiversity - freelance website design is a skill, even an occupation that WMF should be teaching to large numbers of people. Wnt (talk) 14:39, 26 March 2013 (UTC)
The code I was using is at http://pastie.org/7130472 , which generates http://jsfiddle.net/rj7KC/1/ It probably already has way too much "I know, it needs another DIV as a container!" going on. Martijn Hoekstra (talk) 23:02, 26 March 2013 (UTC)
Hmmm... among other things, it seems like the scroll bar on jsfiddle hates me, and v.v. I think I'd have to play with the code here for a while; it seems fairly complex with some useful general functions (we definitely should have a transpose standard, shouldn't we). Meanwhile I'm being aggravated by "losing altitude" on my Module:ColorAlphabet ... seems like no matter how many times you think you are past some HTML bug it'll just be right back again next time. Wnt (talk) 23:45, 26 March 2013 (UTC)
I would certainly like a matrix library with among others transpose, but also the sort of 'scalar product' ( f({'s', {a, b, c}}) => {{'s', a}, {'s', b}, {'s', c}}), but actually also a functional library with at least map and reduce/fold (I'm lost without map). I'm not sure if that sort of stuff should be somewhere in mw.something or in a local Module on en.wiki. Also, this is the first time in my life I named a function bar without it being a placeholder name ;). Anyway, play with it as you please, consider it CC-0 for licensing purposes (which means, if you get it working and want to upload you don't need any attribution, which is a lot easier on the edit summaries). Martijn Hoekstra (talk) 00:16, 27 March 2013 (UTC)

Bar chart progress report

so i think i'm close to finish on processing the parameters and drawing the graph itself, i.e. the bars. still missing placing the scales, validating the input with reasonable error messages, and testing.

currently 2 main modes are supported: regular barchart, and "stack", in which the different groups are stacked on each other, which can be used, e.g., to show market share distribution _and_ market growth.
in the "normal" mode, three scale systems are provided: uniform (i.e., one scale for all values), or per-group (which makes sense when the different groups are in different units - let's say town population vs. town budget over time). per group scale can be automatic or "manual", where the editor enters the scales.

you can see a demonstration by opening Special:TemplateSandbox, and feeding "User:קיפודנחש/sandbox" as Sandbox prefix, and "User:קיפודנחש/sandbox/testbar" as Render page. Here is a link.

peace - קיפודנחש (aka kipod) (talk) 06:34, 27 March 2013 (UTC)

Stage 2: see Module:Chart

i think i'm pretty much done, modulo bugs. please see Module:Chart. peace - קיפודנחש (aka kipod) (talk) 21:05, 30 March 2013 (UTC)

What went wrong

So the thing is more-or-less written, but i just discovered this pretty powerful-and-difficult-to-work-with extension, called mw:Extension:Timeline.

This extension is pretty powerful on one hand, but uses a very difficult and cryptic syntax: to some extent, it feels like going back to write in Assembly language all over again.

So here is what i think now: The main task of this page, is to come up with the best (i.e., most convenient and easy for the editors) syntax possible for providing the parameters. once we do this, writing a lua module that will translate this to something "Timeline" can consume should be a breeze.

I suggest at least 2 if not 3 dfferent chart types. First off, we have line vs. bar. then, we have single-data vs. multiple data. not sure if the timeline extension can do area charts also, but if it can, i suggest we do this too. personally, i ma not crazy about what seems to be enwiki standard mode of operation, which is to create one gargantuan template that can handle all cases based on dozens and dozens (in some cases hundreds) of parameters. i much prefer having one template per each specific task, or at least for each close enough set of tasks, with much more limited set of parameters.

either way, as i said above, i think the purpose of this page is to define and come up with good, sane and simple "syntax", i.e. defining the parameters that this template should accept, and defining clearly what each means and how it behaves. once good definition of syntax is achieved, we can go on to program. i will take the first shot defining the basis for line graph:

{{#invoke:Chart | line graph 
| y legend = 50 : 100 : 150 : 200
| x legend = 1920 : 1940 : 1960 : 1980 : 2000 : 2020
| line 1 = color:blue, thickness:2, points:* (1920 : 70 : description ) (1925 : 77 ) (1930 : 88 : bla bla ) (1936 : 60) .....
| line 2 = ditto
}}

exaplain: data points appear in parenthesis, separated by colon (numbers can be given as 2000 or as 2,000, so separating the X and Y by a comma is unacceptable). each point is either a pair or a trinity, where the 3rd optional item is text to be either displayed or used as a hint (timeline graph is also an imagemap). optionally, we can allow separate definition for legend and tooltip: (xval : yval : legend : tooltip). enclosing the tupples in parenthesis seems very natural, with the added benefit that unlike brackets and braces, parens have no special role in wiki syntax.

this is not a full fledged proposal - more like a teaser, to get the ball rolling. if someone thinks it's appropriate, we can move this whole discussion elsewhere, as long as i'm not the only one blabbering in this "elsewhere".

peace - קיפודנחש (aka kipod) (talk) 19:29, 31 March 2013 (UTC)

Numerous prior templates

Other editors have created several, very fast chart templates, such as Template:Bar_chart, which formats a bar chart in 1/14 second, or 7 charts per 0.5 second, with 1 or 2 or 4 columns of bars. There is not much need for faster charts. See also:

Previously, the <timeline> tag has been used, for charts with hard-coded numbers (no data from parameters) in an article page (see: Help:Bar_chart). -Wikid77 16:16, 4 April 2013 (UTC)

you keep on harping on the "speed" issue. this is absolutely not the issue here. most articles are unlikely to have large enough number of charts that the speed will be meaningful. the source of this request has nothing to do with speed. the main problems with existing chart templates are:
  1. poor readability of the charts themselves - this is typical to charts based on "timeline extension".
  2. convoluted syntax that makes it difficult to actually use them. again, one can create a chart without vanilla "timeline extension", using no template whatsoever, but the syntax is so difficult and convoluted that it's not practical.
  3. limitations: because of wiki template limitations, each of these is limited with hardcoded "left1", "left2" "left3" parameters or somesuch, vs. lua's flexibility of interpreting its parameters, which allowed me to support "group n" with no hardcoding of the "n" values.
  4. convoluted, difficult to change and maintain template code. this is not the fault of the brilliant people who created these templates - it's the need to squeeze out of the very limited wiki template syntax some functionality it was not designed to have.
individual issues with the charts you pointed to:
  1. {{historical populations}} is not a chart. i do not know why you even included it in this discussion
  2. {{bar box}}: nice, but very limited.
  3. {{Pie chart}}: ingenious. i wish i had the html/css-fu to make something like that. this is exactly the kind of template that could and should be done in Lua. in addition to losing the artificial limitations (why 10 slices?), and the awkward coding. after seeing that it can actually be done, i'm almost tempted to create a "pie" function in Module:Chart. here is a list of _some_ if the limitations of this brilliant tool that would be very easy to overcome if it was done in lua:
    • only 10 values (more can be added even without lua, but some artificial limit will always exist, and every time you want to add another slice the template becomes more complex)
    • input must be in percentage, so the editor must calculate the total and the percentage of each slice, which is more difficult than desired
    • no control of chart size: it-s always 200x200
  4. {{brick chart}} - bizarre. maybe ingenious, but this is not a standard way to display numerical data in graphical form
  5. {{Vertical bar chart}}: this one uses the "timeline" extension, and falls short on several fronts: it's very limited, it is not very convenient to use (only 10 articles use it currently), and the result suffers from all of "timeline" limitations (poor aesthetics and readability).
none of the examples allow for stacked bars, which is a standard way to display data. just to illustrate, see if any of the existing chart templates you pointed to can show something like this. also, please open it in edit mode and see how convenient it is to create it. there might be some kinks and bugs, but thanks to the fact that is' a sane lua code of less than 300 lines (including comments), it's much more manageable than most of the templates you linked to.
Medal distribution in some imaginary Olympic games


25
50
75
100
125
150
again, focusing on speed alone show you did not get the point for this module. it's not about speed, it's about creating an easy to use and capable charting tool. if you, or anyone else, have suggestions to help make the syntax clearer and more convenient to use, or more capable, or just point to plain simple bugs - i'm eager to hear them. if you want to talk more about speed, please don't - it's completely besides the point here. קיפודנחש (aka kipod) (talk) 18:11, 4 April 2013 (UTC)
* The prior markup-based chart templates are tested to work on many browsers: More important than ignoring speed, is ignoring to support a wide range of browsers. In particular, Template:Brick_chart (which has horizontal "stacked bars") works on any browser, probably even IE 5 on archaic Windows 98. So, people might re-argue "what counts" but working on any browser is the main priority, and other features which also do not work on those browsers are a unfortunate side-show. However, the Lua chart could be used to write a markup-based chart for any browser, with similar parameters. -Wikid77 00:02, 25 May 2013 (UTC)
i really do not know how to relate to these nonsense. what do you mean "markup based"? you talk as if you do not actually understand how these things work. the lua code runs on the _server_. this is not javascript. there is absolutely no relations between the lua code and the browser. the browser receives pure markup, just like with any template. if you mean to say that it's my "job" to test with older browsers, this is equivalent to asserting that anyone who create a new template should test it with all browsers. if you have any evidence that this does not work with any specific browser, let's discuss it. otherwise, please stop with this nonsense. (and btw: is your claim that brick chart works with "any browser" based on any evidence? who tested it? can you ask them to test _this_ module with those browsers? קיפודנחש (aka kipod) (talk) 02:50, 25 May 2013 (UTC)
Obviously קיפודנחש is correct—the wikitext required to generate the above chart is stunningly simple, and that's what counts (it's also very fast and provides good results: a bonus). It might be helpful to point out any features that are provided by other templates which are not available in Module:Chart, but focusing on speed misses the point. One feature that might be difficult be to implement would be clickable wikilinks. I won't bother looking for examples at the moment, but I have seen some super-ugly charts with very useful information that includes lots of links, and it would be wonderful if they could be replaced with something simpler and more attractive. Johnuniq (talk) 23:40, 4 April 2013 (UTC)
Again, "what counts" is for the chart to show on any browser as the main priority. -Wikid77 00:02, 25 May 2013 (UTC)
i think that this can be done, by overlaying transparent images on top of the bars, and using the "link=" feature of the images. let me ponder it a little, but in the meantime, try to think of reasonable syntax. maybe the same syntax we use with "tooltip"? i.e., replicating the "group 1", "group 2" with "link 1" "link 2", where everything is optional? please come with some suggestions for syntax that will be most useful.
btw - i think that you can already use links for the x legends and group names, though i admit i did not test it. testing now... peace - קיפודנחש (aka kipod) (talk) 00:10, 5 April 2013 (UTC)
huh! now i just gave myself an answer for the question i asked down in this page - "give me a usecase for delinker"... i made the "group names" links, but now the toolips are screwed... peace - קיפודנחש (aka kipod) (talk) 00:17, 5 April 2013 (UTC)
ok, so i added the ability to make specific bars links. check Module:Chart/doc. קיפודנחש (aka kipod) (talk) 04:09, 5 April 2013 (UTC)
I've set up a Lua piechart function for Module:Plotter (though it still uses the Legend template and isn't yet resizable). At least it isn't limited to 10 items. Wnt (talk) 05:15, 5 April 2013 (UTC)
can you add some examples to the /doc page, so we can see what this can and can't do? thanks, peace - קיפודנחש (aka kipod) (talk) 14:01, 5 April 2013 (UTC)
I added two examples. In the one it looks like the limitations are showing - my browser renders a 1% slice with some blurring. Wnt (talk) 20:38, 5 April 2013 (UTC)

another progress report

So i added "pie chart" capability to Module:Chart. it is not all that different from the pie chart Wnt created in Module:Plotter (i actually appropriated his submodule that gives default colors, namely Module:Plotter/DefaultColors ). the main difference is that i think my code is clearer and more readable (although it is very possible that Wnt will think *his* code is clearer...), and the way my module takes its parameters: i used "tupples", that provide the slice value, the slice name, optional color (otherwise the default will be used, at least for up to 26 slices - after that there's no more defaults...) and finally a link, so the whole thing looks more or less so:

| slices =
( Val1 : Name1 : Color1 : Link1 )
( Val2 : Name2 : Color2 : Link2 )
( Val3 : Name3 : Color3 : Link3 )

"Color" and "Link" are optional. in the example above i placed one tupple per line for readability, but this is not required, so it can be

| slices = (Val1:Name1)(Val2:Name2)(Val3:Name3)...

of course, both Wnt and myself owe the idea and the solution to the brilliant people who created Template:Pie chart, but i think the module has several advantages over the template:

  1. not limited to 10 slices (10 is probably enough in most real world uses, but it's still good to remove artificial limitation)
  2. do not have to provide the numbers in percents (i.e., the numbers do not have to add up to 100 - adding up to five billion or to 0.001 is perfecly fine)
  3. can define the pie's radius - not hardcoded any more like in the template
  4. can provide the input in localized number format. this means that the values can be writter like so: 12,402.67 (note the comma), which makes the page more readable.
  5. utilizes "imagemap" to provide tooltips and optional links from the slices
  6. more convenient way to feed the parameters (at least i think it's more convenient)

The pie chart could use a bit more testing, but i think it is good to use. Currently this module is not used in the main space, but i think both the bar graph and the pie chart are now better than what's currently in use in enwiki, if i say so myself, both in appearance/functionality, and also in convenience and more sane syntax.

do you guys think it's ready for "big time", and if so, how do you suggest we can go about it?

regarding "what's next": i'm not sure i am interested in continuing with more charts, but i think it would be good if someone would create a nice horizontal bar-chart. the advantage of horizontal chart is that this makes room for large number of legends, and allows large number of bars - for some type of data it's very useful.


peace - קיפודנחש (aka kipod) (talk) 05:21, 13 April 2013 (UTC)

I think it's high time we have a "WP:Lua/Announcements" or something. We should have two sections - one where you can announce "beta versions" that seem ready to be tested in some articles to see if anything goes wrong, and one for "production versions" that have been reviewed by multiple editors, used in many of the target articles, have all their t's crossed and i's dotted (and spaces inside their parentheses, even if it seems silly). If several of us got together and made this page we might make a more effective periodic announcement at VPT, in the Signpost etc. by referencing it and reporting a few highlights. Wnt (talk) 15:58, 16 April 2013 (UTC)
+1 (i also think i forgot to mention that i appropriated the Module:Plotter/DefaultColors from Wnt's work). in the meantime, i translated Module:Chart to Hebrew - you can see the hebrew version in he:Module:גרפים, and some other users have improved on it a bit - specifically we taught "bar char" to (optionally) display the numerical value inside each bar, and we also taught it to (optionally) rotate the x-axis titles, to allow squeezing in more titles in a certain graph. peace - קיפודנחש (aka kipod) (talk) 16:54, 16 April 2013 (UTC)
How do you do the rotate? I was under the impression the rotate property was an HTML5 thing that Wikipedia doesn't support (or allow). Wnt (talk) 17:04, 16 April 2013 (UTC)
"html5" is not well defined. there are some features of html5 that are supported by most browsers (euphemism to "all but IE") for a long time now, such as "Canvas" (support was added to ie in ver.9) or lists in columns (which enwiki is using for several years now in footnotes, all sane browses support it for a long time now - even ie added support in ver. 10).
specifically, it's done with somewhat long incantation:
style='-webkit-transform:rotate(90deg);-moz-transform:rotate(90deg);-ms-transform:rotate(90deg);-o-transform:rotate(90deg);transform:rotate(90deg)'
wikipedia does not block it, and all browsers support it (including ie, though i do not know which versions. i believe 7 does, and i guess 6 does not). peace - קיפודנחש (aka kipod) (talk) 18:14, 16 April 2013 (UTC)
Excellent! I can think of a few uses for this... Wnt (talk) 21:15, 16 April 2013 (UTC)
http://caniuse.com/#search=transform can I use is nice. Martijn Hoekstra (talk) 22:34, 16 April 2013 (UTC)

File extension

What would be the easiest way to get the file extension into a template? "jpg" if you are in "file:foo.jpg", etc. I do not think we can do it with parser functions so the next thing to try would be Lua. It probably can be done with string functions, but may be it is already written somewhere. --Jarekt (talk) 02:46, 21 May 2013 (UTC)

{{#invoke:string|match|s=file:foo.jpg|pattern=%.([^.]+)$}} → jpg
I hope that is a satisfactory answer to the question. --darklama 14:54, 23 May 2013 (UTC)
Could also use a replacement (gsub) - str:gsub("^(.*)%.","") -- removes everything up to the last period and get remaining file extension jpg, png, svg etc. Matroc (talk) 05:26, 26 May 2013 (UTC)
Thanks, that worked great. I created Commons:Template:File extension. --Jarekt (talk) 11:32, 28 May 2013 (UTC)

Hi. If anyone is looking for a silly project to pass the time, Module:RFX report could use a lot of love. It's an attempt to largely replace the need for a bot to update User:Cyberpower678/RfX Report. --MZMcBride (talk) 15:30, 31 May 2013 (UTC)

Hi. If anyone is bored, I think Template:Loop could use a rewrite. :-) --MZMcBride (talk) 13:57, 31 May 2013 (UTC)

this was discussed in the past. i added a "rep" function to Module:String, which can easily be used to implement "loop": like mapping {{loop|25|test}} to {{#invoke:String|rep|test|25}} or somesuch. there is some work, of course (including some testing), but no new lua coding needs to be done - it's all in the realm of the template itself. peace - קיפודנחש (aka kipod) (talk) 14:16, 31 May 2013 (UTC)
Oh, right. So we just need to update the template. Okay, that's good to know. Thanks! --MZMcBride (talk) 15:28, 31 May 2013 (UTC)
I've done it. That was a pleasant 30 mins work. :) — Mr. Stradivarius ♪ talk ♪ 16:14, 31 May 2013 (UTC)
That's wonderful. Thanks! :-) --MZMcBride (talk) 06:20, 1 June 2013 (UTC)

Loop and count

Is there anyway to use a Loop template or a module inside of a template that calls other templates and knows what the loop counter is? I want to {{#expr:{{Loop|{{PAGESINCAT:Articles with a promotional tone from {{Months before now|<!-- current loop number -->}}|pages}} + |{{PAGESINCAT:Articles with a promotional tone|subcats}}}}0}} to give me a count of all of the subpages in that category. Can this be done? Technical 13 (talk) 15:39, 31 May 2013 (UTC)

Boxes graph

Purpose

building a template that will allow creating graphs of boxes, such as {{Family tree}}, with sane and convenient syntax

Challenge: define the syntax

Currently, to use "Family tree", the editor is required to define successive series of templates, preceded by {{Family tree/start}} and closed with {{Family tree/end}}. this is both brittle and inconvenient. I am not criticising the people who made it: creating this with the limited tools available for template designers is no small achievement, and i applaud the people who created this template. However, i think we can do much better with lua, which is much more capable tool.

The challenge is to define a sane syntax that will let editors create graphs using clear and concise description.


Ideally, this is done in such a way that will allow the editors as much freedom as possible in defining the different element's style: for the lines it will be nice to allow solid, dashed, color, width, if possible arrows, etc. for the boxes it will be nice to allow defining box border, background color, text color, text size, allow using image for boxe's background, make boxes clickable etc.

However, none of this styling should be required, and the template should automatically select reasonable defaults for everthing.

Challenge: Generate a visual graph out of the data

Extra points: teach it to squirt out invisible strings to be used by screen readers to describe the graph to vision impaired readers.

First draft of syntax

{{Box Graph
| globl param 1 = 
| global param 2 = 
| level 1 =
(Node name: <Name> ; Legend: <Legend> ; Parents: Paretn1 Parent2 ; 
        Pair: PairNode ; [more node attributes such as style] ) 
(Node ... )
(Node ... )
| level 2 =
etc. etc. etc.
}}

peace - קיפודנחש (aka kipod) (talk) 19:28, 1 June 2013 (UTC)

Table parse for particular cells

Hi there, I operate WP:STiki, and of particular interest here, its derivative "leaderboard". Would it be possible to author a Lua function(s) that takes as its input a username, and returns: (1) the positional ranking, and (2) number of uses, per that table? Users want a userbox that displays their relative rank. Absent a scripting language, I would have to individually report table cells to separate pages for transclusion. Thanks, West.andrew.g (talk) 16:37, 6 June 2013 (UTC)

Are you making the leaderboard table by hand or are you generating it by some program and pasting it on your page? I can only think that if you are automatically generating that table you could also then generate a smaller separate Lua table to be read by a Module that you would call with an "invoke" to search for the user and output some infobox with the ranking and number of uses... Will take a quick look in any event and let you know if I come up with anything... Best wishes! Matroc (talk) 08:45, 7 June 2013 (UTC)
Hi Matroc,
Yes, Wikipedia:STiki/leaderboard is generated once a day by machine.
Making the same machine export a Lua table sounds sensible. What format would this table have to be in? Would it be a snippet of Lua code? Would it be a module? (I don't know what the definition of a module is in Lua) Could it be saved at Wikipedia:STiki/leaderboard data module or something like that? And then you would have a Wikipedia:STiki/leaderboard output module to read it and return the required number as a string.
Yaris678 (talk) 13:49, 7 June 2013 (UTC)
I've done it at Module:STikiLeaderboard. The pattern matching is very precise, so it will probably break if you change the format of the table at all, but we can always work around that if it becomes necessary. Best — Mr. Stradivarius ♪ talk ♪ 15:14, 7 June 2013 (UTC)
Cool. That extracts the data from the leaderboard in its current form, without any additional programing of the STiki server required. That's perfect. Thanks. Yaris678 (talk) 21:35, 7 June 2013 (UTC)
That is great! My main concern was in parsing the table and should that format change. wjk - Matroc (talk) 04:18, 8 June 2013 (UTC)
Thanks so much! No, the table format should not change. Regardless, I am a pretty capable programmer if it does -- I just was not terribly familiar with Lua. Thanks, West.andrew.g (talk) 21:22, 9 June 2013 (UTC)
I thought it was a waste having the module only check for two data fields, so I just expanded it to check for all of them. See the updated documentation at Module:STikiLeaderboard. — Mr. Stradivarius on tour ♪ talk ♪ 06:56, 11 June 2013 (UTC)

File information

Is there a way to use Lua, or parser functions to access information about files like URL to the actual full resolution images or image width and height? For this file the URL would be [2] and size 8150 × 6978. I need this functionality for a template to simplify KML creation for overlaying map files in Google Earth. See commons:template:Map. --Jarekt (talk) 03:00, 10 June 2013 (UTC)

There's no way to do this with Lua or magic words, as far as I know. I suspect that it may be possible by using the API, but you would have to ask someone who knows more about that kind of thing than me. Perhaps leave a message at WP:Bot requests? — Mr. Stradivarius ♪ talk ♪ 08:25, 12 June 2013 (UTC)
Thanks, I just needed a second opinion, since I could not figure it out. I know of javascript that looks up image dimensions, so at least that can be looked up (in javascript). --Jarekt (talk) 04:03, 13 June 2013 (UTC)

Hi. If someone is looking for a fun activity, {{user}} is used a lot and could definitely use a rewrite. For pages where it's called more than 1,000 times, it's painfully slow (e.g., Wikipedia:WikiProject Military history/Members/Active). --MZMcBride (talk) 03:14, 11 June 2013 (UTC)

I've created Module:Toolbar which has sped things up a bit. {{user-multi}} could do with a rewrite as well though. — Mr. Stradivarius ♪ talk ♪ 15:56, 11 June 2013 (UTC)
it doesn't seem to me that what {{user}} needs has anything to do with Lua. i opened the template in "edit" mode (the sandbox, really - i can't open the template itself in edit mode) and pressed "View templates used in this page". holy smoke! does this make any sense? total count of the list is 151. really? i'm sure this can be cleaned up big time, but i do not think it has anything to do with lua, and it's hard to imagine test that will be thorough enough to show that the lua module indeed does everything this template-gone-wild does. peace - קיפודנחש (aka kipod) (talk) 16:45, 11 June 2013 (UTC)
Two reasons why Lua might be relevant: Using subtemplates may be done to prevent re-processing the same code repeatedly. Lua does not need such subtemplating.
Subtemplates may be used to add (lists of) options. Lua can handle that in a single page.
Probably the master template {{User-multi}} may be the one to look at. -DePiep (talk) 17:07, 11 June 2013 (UTC)
i'm sure this can be done, and seriously simplified using lua. my point was that i believe this can be done, and seriously simplified without lua just as well. i am not familiar with all the ins and outs of this template and what it does, but glancing at the documentation, i just can't imagine that 151 templates are really required. it is possible that 140 out of those 150 templates are really pulled in by a single template that's used here - in this case what you want to do is probably either avoid using this template, or fix it to not consume 140 other templates. doing it with lua is practically equivalent to doing it from scratch without lua - in both cases you'll probably end up with something better and faster, and in both cases testing that your new brainchild actually behaves exactly like the existing template will be a very serious undertaking. peace - קיפודנחש (aka kipod) (talk) 18:14, 11 June 2013 (UTC)
Standalone wikicode version done at Template:User/sandbox. The remaining templates used on that page are due to {{Documentation}}.--Snaevar (talk) 21:14, 11 June 2013 (UTC)
i think you are correct, and most of the 150 templates *are* due to documentation. so i ended up with an egg on my face... not the first time (and probably not the last, either). peace - קיפודנחש (aka kipod) (talk) 21:52, 11 June 2013 (UTC)

I've started work on Module:UserLinks and hope to have some working code by the end of the day. I'm letting people know here in the hope that it might avoid duplication of effort. — Mr. Stradivarius ♪ talk ♪ 08:20, 12 June 2013 (UTC)

The code is just about ready now. There are some test cases at Template:User-multi/testcases, but there need to be a lot more. I invite you all to try and break it. :) — Mr. Stradivarius ♪ talk ♪ 15:07, 13 June 2013 (UTC)
Ok, it's now up live. I made it quite complicated in the end, as it does magic like checking to see if interwiki prefixes are valid, etc., but hopefully it should still be quite a bit faster than the old version. — Mr. Stradivarius ♪ talk ♪ 06:00, 17 June 2013 (UTC)

I've just written Module:IncrementParams, for those of you who don't like manually renumbering infobox parameters. Enjoy! — Mr. Stradivarius ♪ talk ♪ 08:37, 13 June 2013 (UTC)

Hello, could somebody help with converting this template to Lua? sumone10154(talk) 20:04, 13 June 2013 (UTC)

{{Title without disambig}} which is {{#Invoke:String|replace|{{{1|}}}|%s%(.*%)||plain=false}} does the bit that removes any text at the end in brackets so just the other part to sort out. {{#Invoke:String|replace|{{{1|}}}|.*%/||plain=false}} should do that part, so combining gives:
{{#Invoke:String|replace|{{#Invoke:String|replace|{{{1|{{SUBPAGENAME}}}}}|%s%(.*%)||plain=false}}|.*%/||plain=false}}
So as long as the whole of module:string is copied over to wikivoyage, then you can use the code above in the template instead, although someone else may have an even better solution. -- WOSlinker (talk) 21:38, 13 June 2013 (UTC)
I've done a version without the use of module:string and it's now in voy:Template:BASICPAGENAME/sandbox -- WOSlinker (talk) 06:29, 14 June 2013 (UTC)

Bug 19412 - #time parser function can't read local language month names

Hi all, I am from Bengali Wikipedia. We need your help. in T21412 Pavel Selitskas said that it can be possible to fix or use Scribunto and parse strings and match their pieces against month names and convert the original timestamp. So we need a script or help/guide. How to use at the template.The followings are the Bengali names of each English month

  • January = জানুয়ারি
  • February= ফেব্রুয়ারি
  • March=মার্চ
  • April=এপ্রিল
  • May=মে
  • June=জুন
  • July=জুলাই
  • August=আগষ্ট
  • September=সেপ্টেম্বর
  • October=অক্টোবর
  • November=নভেম্বর
  • December=ডিসেম্বর

Thanks in Advance for your kind help.- Jayanta Nath (Talk|Contrb) 07:38, 17 June 2013 (UTC)

I've left a simple example at Module:User:Mr. Stradivarius/convertTime. You can use it with the following:
{{#invoke:User:Mr. Stradivarius/convertTime|main|<!-- your text here -->}}
For example, {{#invoke:User:Mr. Stradivarius/convertTime|main|১৬:২৫, ৩ এপ্রিল ২০১৩ (ইউটিসি)}} produces "16:25, 3 April 2013 (ইউটিসি)". Best — Mr. Stradivarius ♪ talk ♪ 09:31, 17 June 2013 (UTC)
Thank you Mr. Stradivarius for you great help for Bengali Wikipedia.I am trying impliment this module to our wiki.- Jayanta Nath (Talk|Contrb) 10:08, 17 June 2013 (UTC)

Feature brainstorm for Module:WikiProjectBanner

Hi everyone. I'm in the early stages of writing Module:WikiProjectBanner, and I'd appreciate everyone's ideas for possible features. Please add your ideas over at Template talk:WPBannerMeta. Thanks! — Mr. Stradivarius ♪ talk ♪ 12:51, 18 June 2013 (UTC)

Wrote Modules and Templates for "ASCII code" and its reverse "Code ASCII"

  1. I don't know the procedure exactly for doing this type of thing :( -- just got carried away a bit...
    • Revamped code - simpler solution - see my talk page Matroc (talk) 05:37, 23 June 2013 (UTC)
Did you know Lua has built-in functions for doing this? string.byte( "A" ) returns 65, and string.char( 65 ) returns "A". Scribunto also has functions that deal with UTF-8 codepoints in the same way: mw.ustring.codepoint( "á" ) returns 225, and mw.ustring.char( 225 ) returns "á". Anomie 19:38, 22 June 2013 (UTC)
Fantastic - excellent information I appreciate it - Thank you! -- I should check the String module to see if that is in there as well... Great learning experience for me... Matroc (talk) 03:18, 23 June 2013 (UTC) again Thanks!

Hi. Template:Italic title currently has a bug where if the page title contains a non-disambiguation parenthetical (e.g., "Foo v. Bar (Baz) Bing") the title will be improperly italicized. The template currently only checks for the existence of "(". I'd like to switch the template to italicize the full string if there's no ")" at the end of the page title. Is there an equivalent to rfind? Or maybe regular find can be used for this? I'll post some input/outputs below. --MZMcBride (talk) 01:17, 14 June 2013 (UTC)

Input
Film Title
Output
Film Title
Input
Book Title (disambiguation)
Output
Book Title (disambiguation)
Input
Foo v. Bar (1956)
Output
Foo v. Bar (1956)
Input
Foo v. Bar (Bing) Baz
Output
Foo v. Bar (Bing) Baz

  • A possible solution for Template:Italic title that I also posted on my talk page:
{{DISPLAYTITLE:{{#ifexpr: {{#invoke:String|find|{{PAGENAME}}|)}} = {{#invoke:String|len|{{PAGENAME}}}}
|{{#if:{{NAMESPACE}}|{{NAMESPACE}}: }}''{{#Invoke:String|replace|{{PAGENAME}}| (|'' (}}
|{{#if:{{NAMESPACE}}|{{NAMESPACE}}: }}''{{PAGENAME}}''
}}
}}<noinclude>
{{documentation}}<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
  • Someone would have to test/approve/and update it etc. to make sure it meets all the criteria -- Cheers! Matroc (talk) 07:33, 17 June 2013 (UTC)
  • Oops, it look like we template conflicted! I've just spent a little while coding together a pure Lua implementation, Module:Italic title, which I have just now put up live. The logic is a lot easier to read in Lua, so I don't think we should still use parser functions if we don't have to. The new module passed all of my tests earlier on, but let me know if you spot any issues with it. Best — Mr. Stradivarius ♪ talk ♪ 08:34, 17 June 2013 (UTC)
MZMcBride pointed to the issue in Everything You Always Wanted to Know About Sex (But Were Afraid to Ask). As the template works now (and in history), the brackets are untouched whatever their content. Maybe we could add a |italics all=yes parameter to cover this? Next issue then would be: Everything You Always Wanted to Know About Sex (But Were Afraid to Ask) (book). It is a feature request, not a bug. -DePiep (talk) 09:38, 17 June 2013 (UTC)
Ok, I'll add that in as an option. As for the second one, that should work already - the Lua version only matches one set of brackets, and only if they are at the right-most end of the title. — Mr. Stradivarius ♪ talk ♪ 09:51, 17 June 2013 (UTC)
It's now in, and Everything You Always Wanted to Know About Sex (But Were Afraid to Ask) is italicising properly. — Mr. Stradivarius ♪ talk ♪ 10:24, 17 June 2013 (UTC)
Great! -DePiep (talk) 11:44, 17 June 2013 (UTC)
Awesome! - was looking at this as a temporary solution until a Lua module was written (had started one as well-Cheers!) - fantastico! -- Matroc (talk) 14:32, 17 June 2013 (UTC)
Mr. Stradivarius: you are wonderful. Thank you! JPMorgan Chase Bank v. Traffic Stream (BVI) Infrastructure Ltd. now auto-italicizes as expected. :-) --MZMcBride (talk) 18:02, 19 June 2013 (UTC)
P.S. And thanks to Matroc as well for poking at this. Death to ParserFunctions!
Italic ship title

Maybe someone can find joy in Luafying this related one:

Need Lua version of urlencode

Has anyone created a Lua version of parser function {urlencode:} to retain slashes, ampersand, '?' and the '=' equals sign? The current bug in web-links ("[http:____]") always appends a slash after the URL when urlencode has encoded other slashes as "%2F" which the web-link bug does not realize is a slash, and so appends a slash at end-of-URL. Instead, we need a Lua urlencode which retains slashes, so that typical weblinks of the form "[http:____]" do not append an invalid slash "/" at end of URL. I have written Template:Encodelink to properly encode some URLs, but it skips encoding the first 43 characters so that WP URLs can be encoded while retaining slashes, plus the first '?' and '='. A full Lua urlencode is needed to simplify web links. -Wikid77 (talk) 12:40, 11 July 2013 (UTC)

I think it's just in the api: this one you mean? —TheDJ (talkcontribs) 13:14, 11 July 2013 (UTC)
That was my first thought too. Wikid, can you give an example of a link that causes the erroneous slash to appear? I think it will be easier for me to understand the problem with an example. — Mr. Stradivarius ♪ talk ♪ 13:19, 11 July 2013 (UTC)
Example of slash added: For "[http://{{urlencode: www.google.com/search?q=xyz}} googling xyz]" → googling xyz, the link fails due to extra slash "/" after "xyz" (as error "400: Your client has issued a malformed or illegal request."), because extra "/" is appended by parser not seeing 3rd "/" after "[ http://__]" when "/" is encoded as "%2F". I consider it a bug (for years) to auto-append slash in "[http:___]" but hey, some developers think edit-conflict is not a problem either, so we just work around wiki-bugs. -Wikid77 (talk) 05:33, 13 July 2013 (UTC)
Wikid77, you appear to be misusing the percent encoding. Per the HTTP spec, these are not the same:
In particular, the spec requires that control characters such as "/", "?", and "=" may never be percent encoded if you intend them to have their functional meaning. (If that is surprising, don't worry about it. I found it surprising too.) A HTTP server that strictly implements the HTTP spec will regard the former as a request for the literal page "search?q=xyz", while the latter is a request for the page "search" with a query having parameter "q" equal to "xyz". It is true that many web servers are actually permissive about this and treat those two requests as identical, but that is not formally consistent with what the HTTP spec requires. Similarly, encoding the the third slash as %2F is a violation of the HTTP spec so you shouldn't be horribly surprised if it doesn't behave as expected. If you want URLs that are compliant with the HTTP specification then you need to apply urlencode: only to those parts of the URL that are not expected to act as designated control characters, e.g. you can't apply it the "/", "?", "=", or "#" that define the parts of the URL itself. Dragons flight (talk) 06:05, 13 July 2013 (UTC)
Thank you for confirming what I said at top, in case people did not understand why I noted to retain slashes, "&" or "=" or "+" etc. -Wikid77 (talk) 22:53, 13 July 2013 (UTC)
Exactly, it is for url component encoding, not for entire urls. So: "[http://www.google.com/search?q={{urlencode:xyz}} googling xyz]" → googling xyz — Preceding unsigned comment added by TheDJ (talkcontribs) 07:43, 13 July 2013 (UTC)
Further, nothing in MediaWiki is even adding a slash. If you look at the generated source for your example above, Wikid77, it has
<a rel="nofollow" class="external text" href="http://www.google.com%2Fsearch%3Fq%3Dxyz">googling xyz</a>
No added slash. But it is linking to a nonexistent hostname "www.google.com/search?q=xyz", not any page on www.google.com at all. Anomie 18:21, 13 July 2013 (UTC)
  • Extra slash "/" when clicked: The extra slash is not in the generated page, but appended live in a browser when clicking the link which does not contain a 3rd "/" in the URL (try: http://www.google.com%2Fsearch?q=xyz). The slash is auto-appended before "?q" to form "/search/?q" as an invalid format, as an obscure bug in MediaWiki. URLs which contain a "/" do not auto-append another "/". -Wikid77 (talk) 22:53, 13 July 2013 (UTC)
    • You're doing it wrong: This isn't being done by MediaWiki, this is being done by your browser. If you want only part of the URL to be encoded than encode just that part. Arbitrarily skipping characters that need to be encoded when things are done right because you want to do it the wrong way is not the way to do things. Anomie 11:30, 14 July 2013 (UTC)
Some samples might help? I looked at this a little bit and took your example and created Module:Sandbox/Matroc/Testurlencode - Edit: 2+2=4 ... may still have issues with some characters, might be a possible avenue to investigate. Matroc (talk) 00:00, 12 July 2013 (UTC) -- This is for simple URL's -- more work required for doing mediawiki APIs.
Trying with Google: Matroc's Lua could allow {#invoke:Sandbox/Matroc/Testurlencode |encode| http://www.google.com/search?q=xyz |glink|x}, to generate "[glink x]" with slash "/" as valid inside the generated link "[http:__]". -Wikid77 (talk) 05:33, 13 July 2013 (UTC)
I faced the problem to implement in LUA {{FULLPAGENAMEE}} (with the extra E at the end). The {{FULLPAGENAME}} is available as fullText of the getCurrentTitle() described here. I tried various url enconding and nothing worked. I had to create a dedicated method to join optional namespace part with the title:partialUrl() to achieve the result. I think the uri.encode lacks some encoding and could be expanded with new enctype option for that purpose. Paweł Ziemian (talk) 11:20, 12 July 2013 (UTC)
uri.encode( title.nsText, "WIKI") . ":" . uri.encode( title.text, "WIKI" ) doesn't work for you ? —TheDJ (talkcontribs) 07:43, 13 July 2013 (UTC)
The problem here is apparently that {{FULLPAGENAMEE}} un-encodes various punctuation characters that technically should be encoded according to the relevant RFCs defining percent encoding. See wfUrlencode for the specific implementation. Anomie 18:21, 13 July 2013 (UTC)
Nice to know. Thank you. Paweł Ziemian (talk) 20:50, 13 July 2013 (UTC)
  • Re-focus on original issue, for encoding to retain slashes, etc.: Create a Lua-based template to link a URL which has been encoded, but retaining slashes, ampersands, the plus signs, etc. (keep: / ? & + = ). There's no hurry on this, as the "[http:__]" extra-slash bug has been in Wikipedia for years. -Wikid77 (talk) 22:53, 13 July 2013 (UTC)
    • Modified my test Lua module - Module:Sandbox/Matroc/Testurlencode - takes 2 arguments: the url and the link - it decodes 1st then encodes - does substitution in order to (keep: / ? & + = ) - Matroc (talk) 00:42, 14 July 2013 (UTC) Might be a solution...
      • Which will break if one of the query parameters needs to contain an actual '+' instead of a space, or for the links used by git.wikimedia.org that need both encoded and unencoded slashes to be used correctly. The bottom line here is that what Wikid77 is wanting to do is simply not the right way to do things, and any "solution" for him will be a hack of some sort. Anomie 11:30, 14 July 2013 (UTC)
  • Thinking to write smart template to encode parameters: The idea is to have "smart encoding" where the Lua logic would know when to encode "+" as a literal plus sign, but we can think about it a few weeks, then perhaps decide it is too complex to automate easily. As I said, there is no hurry on this, just a major problem in web links to discuss for possible ideas. -Wikid77 (talk) 16:39, 14 July 2013 (UTC)

File on commons vs simple string

There is property d:Property:P94 and d:Property:P281. the fist is name of image file on Commons and the second is just string. However both of them are identical in structure in LUA. I had to know what to do with the text i.e. whether to wrap it in [File:...] or display it as is. The wikidata knows something more, since there is difference in the property descriptions. Could be the database API expanded with function that provides the info? Paweł Ziemian (talk) 20:06, 14 July 2013 (UTC)

Wikidata is a frustrating and mysterious thing to me - any page where "edit" doesn't get me to a page source is something I don't know what to do with, nor is it very clear how to access them. I've generally written off the project in my mind entirely. If I use templates, {{subst:d:Property:P94}} and {{d:Property:P281}} get me... well, what you see here, nothing. So I can't edit it and I can't transclude it... Let's try {{#invoke:page|id|page=d:Property:P94}} --> 0 i.e. the data isn't available in a Lua title object. So what do you do with Wikidata anyway? Wnt (talk) 01:32, 18 July 2013 (UTC)
@Wnt: You can find more info here. As far as I know we have to access it by frame:preprocess() or similar in Lua. @Paweł Ziemian: I think your suggestion might be better suited for Bugzilla, as the developers need to hear it, and the only dev I'm aware of who watches this page is Anomie. — Mr. Stradivarius ♪ talk ♪ 08:45, 18 July 2013 (UTC)
  • Thanks for the response, however I missed to mention that I want to know the difference in the statements associated in the article pages (Q items) and not in the property definition. I had idea to create a module that display a property value in most pretty format as possible. That is, a link to article if available, a string if only label is available, a coordinates with proper precision that link to geohack, a date with proper precision (including time if possible), and finally a link to file on commons if the data is a type of 'file on commons'. If for example I list claims for Gdańsk there are:
[p94] = {
        [0] = {
                ["mainsnak"] = {
                        ["snaktype"] = "value"
                        ["property"] = "p94"
                        ["datavalue"] = {
                                ["value"] = "POL Gdańsk COA.svg"
                                ["type"] = "string"
                        }
                }
                ["type"] = "statement"
                ["id"] = "q1792$297F63DF-B20B-42BC-BFFB-D79BC2B42604"
                ["rank"] = "normal"
        }
...
[p281] = {
        [1] = {
                ["mainsnak"] = {
                        ["snaktype"] = "value"
                        ["property"] = "p281"
                        ["datavalue"] = {
                                ["value"] = "80-008"
                                ["type"] = "string"
                        }
                }
                ["type"] = "statement"
                ["id"] = "q1792$f14becf3-40ab-6ac1-469d-f53cee19b577"
                ["rank"] = "normal"
        }
        ...

There is not any hint telling that the [p94] is a file name on commons and [p281] is simple text. However I thought about it a while and realised that displaying pictures is rather complex process and needs additional attention due to many available properties formating the image. My conclusion is making the process automatically is hardly possible. So I revoke the requirement. Such properties shall never be displayed directly, rather formatted individually in target infobox according to their needs, and using only the raw property value as data reference. Paweł Ziemian (talk) 09:15, 18 July 2013 (UTC)

Hmmm, according to the link above, {{#property:p284}} would be the way to access this data, and furthermore, it can't be done from here, nor does {{#property:p284|of=Gdańsk}} actually work; however, playing with it in the page preview I've managed to see that when added at the article p281 delivers:
80-008 – 80-958, 80-008, 80-958
versus
POL Gdańsk COA.svg
for p94. I should note that the latter result is just a string as displayed in that page preview, not a link unless you'd put it in double brackets. Anyway, I see the data you posted above depicted in a cutesy form at [3] but where did you get that printout of the data structure with ids etc. that you pasted above?? Wnt (talk) 09:40, 18 July 2013 (UTC)
I have my private Lua script here [4] with method claims, which invoked in the article (in preview only of course) produces such list. Paweł Ziemian (talk) 11:36, 18 July 2013 (UTC)
Aha - I now see that we have mw:Extension:Wikibase Client/Lua. I didn't even know about that before. I might have a tinker around with it later on, but I don't really know enough about it now to answer your question, Paweł. — Mr. Stradivarius ♪ talk ♪ 12:07, 18 July 2013 (UTC)

Italics language dependent in Wikivoyage listings

If it's not kosher to add a request for a different project, please feel free to revert.

We are trying to get non-Latin scripts to show up without italics in the alt= and directions= fields of voy:Template:Listing, and the hunch is that a Lua module should be able to do this for us. But we don't have anyone with the expertise. If someone here is interested in helping, please see the discussion at voy:Template talk:Listing#Non-Latin scripts are italic. Thanks! --Peter Talk 19:21, 21 July 2013 (UTC)

Not sure if it's quite ready for prime time but I've done a function at voy:Module:IsLatin as a starting point. -- WOSlinker (talk) 22:10, 21 July 2013 (UTC)
I embedded Module:IsLatin in a test template - (Used an ifeq for a "yes" or "no" test condition. No issues so far. Matroc (talk) 02:13, 24 July 2013 (UTC)
{{#ifeq:no|{{#invoke:IsLatin|IsLatin|{{{param}}}}}| (''{{{param}}}'')| ({{{param|}}})}}
Thanks for testing. -- WOSlinker (talk) 06:34, 24 July 2013 (UTC)

Convert underscores to pipes for coordinates

At the Dutch Wikipedia we use nl:Sjabloon:Coördinaten for coordinates. The input is about the same as most Wikipedia's with one major difference: Underscores are used intead of pipes. So for example nl:Haarlem uses {{Coördinaten|52_22_49_N_4_38_26_E_type:city(146753)_region:NL-NH|52° 22′ 49″ N, 4° 38′ 26″ O}}. I would like to modify the coördinaten template to use #coordinates to fill nl:Special:Nearby. I'm trying at nl:Gebruiker:Multichill/Kladblok but I don't get it to work. Can someone assist me here or point me in the right direction? The problem seems to be in | as a special character and escaping it. Multichill (talk) 10:05, 6 July 2013 (UTC)

The problem is that you can't have the "|" for separating arguments to #coordinates be generated by the #invoke; this is also why {{!}} works to "escape" a | in template arguments. But you should be able to do this entirely within Lua with something like this:
function p.coordinates( frame )
    return frame:callParserFunction( '#coordinates', mw.text.split( frame.args[1], '_', true ) )
end
I haven't actually tested that, but it should give you the idea. Anomie 12:30, 6 July 2013 (UTC)
Thanks for the input. Looks like I missed the "true" part in mw.text.split: module update and template update. The table is now populating. Multichill (talk) 13:27, 6 July 2013 (UTC)
  • I was interested of using the method too, however it is very frigile method. It looks that the invalid arguments crashes the page rendering on server side if I created a simple call with invalid arguments.
function m.C(frame)
    return frame:callParserFunction('#coordinates', { '100', '200' } )
end

The result was a server error page with apologise and the following error details:

PHP fatal error in /usr/local/apache/common-local/php-1.22wmf8/includes/parser/Preprocessor_DOM.php line 955:
Argument 1 passed to DOMXPath::__construct() must be an instance of DOMDocument, null given, called in /usr/local/apache/common-local/php-1.22wmf8/extensions/Scribunto/engines/LuaCommon/LuaCommon.php on line 500 and defined 

However if I use {{#coordinates:...}} directly, a proper error is returned instead. So I give up of calling the coordinates directly from Lua until the method became more robust for invalid input. Paweł Ziemian (talk) 05:52, 7 July 2013 (UTC)

Ran into that too and opened T52863. Multichill (talk) 11:26, 7 July 2013 (UTC)

Image aspect ratio

It would be great to auto-detect the approximate aspect ratio of an image (width/height), especially for use in commons:Template:Assessments. Is this feasible? --Ricordisamoa 23:04, 3 August 2013 (UTC)

There's no way to do this in Lua at the moment that I'm aware of. I've filed a feature request in bugzilla - let's see if it generates any interest. — Mr. Stradivarius ♪ talk ♪ 10:51, 4 August 2013 (UTC)
Thanks a lot, let's stay tuned. --Ricordisamoa 13:14, 4 August 2013 (UTC)

Three-way parameter value

In wikicode, parameters can have three way input: 1. straight text, 2. a <blank> (whitespace), and 3. not-defined at all (=not present in the template call). How can we pass these through the #invoke: step (or: how can the module detect these three)?

In wikicode, I can detect all three using the {#if:} parser function. -DePiep (talk) 13:17, 26 July 2013 (UTC)

  • When needed encode blank parameters during #invoke processing: Do not be afraid to use {#if:_} to test for blank parameters and reset the blank values during the #invoke (such as to parameter value "#blank#" or such). Inside the #invoke, each {#if} runs at the rate of 800 per second, compared to the #invoke running 500 per second with 7 text parameters. In general, do not document templates with a "boilerplate" of 30 blank parameters, because I think 1/3 (33%) of all major template parameters are blank now in a million articles, due to promoting empty-parameter skeleton examples which list almost all parameters as blank. Plus extra blank parameters slow processing, exponentially, because each parameter must be compared to all prior parameters, in case it reuses one of the same names, to overwrite the prior parameter value, and re-process each prior parameter, over and over, for each next parameter passed, as extremely slow. So, 1,000 parameters is "four times" slower than 500 parameters, rather than twice as slow, roughly speaking. -Wikid77 18:27, 26 July 2013 (UTC)
i tried to read the last blob about 3 times, and did not understand either what you are saying, or how is it relevant to the request.
iiuc, the request is about a way to distinguish, inside the lua code itself, between a parameter given with no (=empty) value, and a parameter which is not given at all. i can see the value of a way to make such a distinction, but i think this request would probably be more appropriate in mw:Extension talk:Scribunto. peace - קיפודנחש (aka kipod) (talk) 19:15, 26 July 2013 (UTC)
I think they're suggesting to set the blank param to "#blank#" to then convert it to false/nil in Lua. — Lfdder (talk) 19:39, 26 July 2013 (UTC)
Those three input methods are detected in lua as follows. Below I used parameter one ({{{1}}} in wikicode) as an example. If you are planning to detect more than one parameter with the same value, then another aproach should be taken.
No. Wikitext Lua detection
1 {{template|some text}} if frame.args[1] == "some text" then
2a {{template|}} if frame.args[1] == "" then
2b {{template| }} if frame.args[1] == " " then
3 {{template}} if frame.args[1] == nil then
Now, what are you planning to do once you have detected those three inputs ?--Snaevar (talk) 21:50, 26 July 2013 (UTC)
simply said, I want to discern: 1. return text, 2. return <blank>, 3. return default error message (with class=error state). see {{IPAsym}} and module:IPA symbol, with their current developments. -DePiep (talk) 01:02, 27 July 2013 (UTC)
This has been answered, but if anyone wants to fiddle around, see test2. Feel free to edit anything there. By the way, the module is ten months old and uses the now obsolete frame:argumentPairs() which is the same as pairs(frame.args).
The page is a little baffling at first—read the "Explanation" at the top. Each test starts by showing the template used (example: {{Johnuniq/Testargs|}}), and that is followed by a table which includes "Parent (arguments passed to template)" that shows the template arguments as seen by the module (for this example, an empty string). Johnuniq (talk) 00:52, 27 July 2013 (UTC)

Thanks. I understand that Snaevar's table is defining. It could and should be in LUA help page. -DePiep (talk) 19:11, 27 July 2013 (UTC)

Wait wait. This works well when directly module-calling from template only: tplX #invoke:.... But how to pass when I call that template from page? -DePiep (talk) 21:35, 1 August 2013 (UTC)
See frame:getParent().args to access parameters of the template that directly calls function from Lua module. Paweł Ziemian (talk) 20:04, 2 August 2013 (UTC)
  Resolved
Thanks again. -DePiep (talk) 06:13, 8 August 2013 (UTC)

Make rowclass apply to headers in infoboxes

I'm trying to make the rowclass# parameters apply to header rows in infoboxes. Here was my attempt to do that. I modified the testcases page to see if it worked, and it appears that it didn't (I expected testclass to be on the tr in the sandbox one, and it wasn't), and I don't know why. Can someone take a look at it for me? Thanks, Jackmcbarn (talk) 18:02, 9 August 2013 (UTC)

I'm guessing you probably can't chain things between tag()s. Try using an lvar (like on line 56). — Lfdder (talk) 23:12, 9 August 2013 (UTC)
Still doesn't work. Jackmcbarn (talk) 00:12, 10 August 2013 (UTC)
rowclass depended on data...oddly. If I'm reading this correctly, it should be the other way around. — Lfdder (talk) 00:33, 10 August 2013 (UTC)

Module:Fixme

Hi everyone. I've just created Module:Fixme, which searches Lua modules for the text "FIXME" in comments, and if present adds the page to the as-yet-uncreated Category:Lua modules with fixme tags. I thought that this would be a good way to encourage people to check and fix each other's code. We could check all modules automatically by adding Module:Fixme to MediaWiki:Scribunto-doc-page-show and MediaWiki:Scribunto-doc-page-does-not-exist. Do people think this is a good idea? And would you prefer a different name for the category? Let me know what you think. — Mr. Stradivarius ♪ talk ♪ 12:03, 20 August 2013 (UTC)

this looks a bit convoluted. isn't this exactly the thing for which we have categories? if we want to mark some moduls as "needin` fixin`", why not create a new cat, say Category:Modules requiring modifications or somesuch, and add it to the document page of those modules? peace - קיפודנחש (aka kipod) (talk) 13:01, 20 August 2013 (UTC)
The idea is that it's easiest to explain things like this inline, in the actual code. With just a category, it's hard to know what needs fixing and how. And if it was done on the talk page, you would probably need to copy some of the code across to explain your point. As for being convoluted, I think it is the opposite. All you would need to do to add a page to the fixme category is add a comment with "FIXME" in it to your module. And if you want to remove the page from the category, all you need to do is remove the "FIXME" text. If we manually added categories to /doc pages, people would probably forget to add the category after adding a fixme comment, or would forget to remove the category after fixing whatever the problem was. Also, using fixme comments is a widespread programming practice, so it will already be familiar to coders. — Mr. Stradivarius ♪ talk ♪ 13:32, 20 August 2013 (UTC)

Hi I would like some help to create the module:documentation

I found these codes on fr wikipedia but translated some words here are the codes could someone help me change the words and to create a sillier copy of documentation but in lua scripting please I also need help translating and making the same version of Template:documentation but in lua scripting please this is some that have been done but I need help to do the rest like transformation template:documentation into module:documentation please

Extended content
--This module implements {{Documentation}}.
--TODO: Implement a class 'ConcatBuilder' to reduce redundancy
--'table.insert(<MyTable>, <MyString>)' and 'table.concat(<MyTable>)'
 
local p = {}
 
function p.corps(frame)
    args = frame:getParent().args
    local page = mw.title.getCurrentTitle()
    doc = p.docname(page)
    local corps = {}
 
    if page.subpageText == 'sandbox' then
        table.insert(corps, '<div style="clear:both />')
        table.insert(corps, frame:preprocess('{{Template sandbox notice}}'))
    end
 
    table.insert(corps, p.header(page))
    table.insert(corps, p.content(frame, page))
    table.insert(corps, p.footer(page))
 
    if args.raw then
        return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>\n:' .. os.clock())
    end
 
    return table.concat(corps)
end
 
function p.docname(page)
    if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/doc" end
 
    if page.subpageText == 'doc'
    or page.subpageText == 'sandbox'
    or page.subpageText == 'testcases' then
        return page.subjectNsText .. ":" .. page.baseText .. "/doc"
    else
        return page.subjectNsText .. ":" .. page.text .. "/doc"
    end
end
 
function p.ifexist(page)
    if not page then return false end
    if mw.title.new(page).exists then return true end
    return false
end
 
function p.header(page)
    local header = {'<div class="template-documentation"'}
 
    if args.color then
        table.insert(header, ' style="background:')
        table.insert(header, args.color .. '"')
    end
 
    table.insert(header, '><div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
    table.insert(header, '[[File:Template-info.png|50px|alt=Template documentation|link=]]')
    table.insert(header, '<span style="font-weight:bold; font-size:125%">&nbsp;')
 
    if args.heading then table.insert(header, args.heading)
    else table.insert(header, 'Template documentation') end
    table.insert(header, '</span>')
 
    if not args.content then
        table.insert(header, '<span class="mw-editsection plainlinks">&#91;[')
        local arg = mw.title.new(args[1] or doc)
 
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(header, arg:fullUrl('action=view') .. ' view]')
            table.insert(header, '&#93;&#32;&#91;[')
            table.insert(header, arg:fullUrl('action=edit') .. ' edit]')
            table.insert(header, '&#93;&#32;&#91;[')
            table.insert(header, arg:fullUrl('action=history') .. ' history]')
            table.insert(header, '&#93;&#32;&#91;[')
            table.insert(header, page:fullUrl('action=purge') .. ' purge]')
        else
            table.insert(header, arg:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload"}))
            table.insert(header, ' create]')
        end
        table.insert(header, '&#93;</span>')
    end
 
    table.insert(header, '</div>')
    return table.concat(header)
end
 
function p.content(frame, page)
    local content = {}
    local arg = args[1] or doc
    if args.content then
        table.insert(content, '\n')
        table.insert(content, args.content)
    else
        table.insert(content, frame:preprocess('<nowiki />'))
        table.insert(content, '\n')
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(content, frame:preprocess('{{' .. arg .. '}}'))
        end
    end
 
    table.insert(content, '\n')
    table.insert(content, frame:preprocess('<nowiki />'))
    table.insert(content, '<div style="clear:both" />\n')
    return table.concat(content)
end
 
function p.footer(page)
    local footer = {}
    local arg = mw.title.new(args[1] or doc)
 
    table.insert(footer, '</div><div class="template-documentation plainlinks" ')
    table.insert(footer, 'style="font-style:italic; margin:2px 0px 0px; padding: 0.35em 0.9em')
 
    if args.color then
        table.insert(footer, '; background:')
        table.insert(footer, args.color)
    end
    table.insert(footer, ';">\n')
 
    if args.content then
        if args["link box"] then
            table.insert(footer, args["link box"])
        else
            table.insert(footer, 'This documentation is directly included in this page.')
        end
    else
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(footer, 'The above [[Wikipedia:Template documentation|documentation]] is ')
            table.insert(footer, '[[Wikipedia:Transclusion|transcluded]] from [[')
            table.insert(footer, tostring(arg)) 
            table.insert(footer, ']]&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(footer, arg:fullUrl('action=edit'))
            table.insert(footer, ' edit]&nbsp;|&nbsp;[')
            table.insert(footer, arg:fullUrl('action=history') .. ' history])</span>.<br />')
        end
        table.insert(footer, 'Editors can experiment in this templates ')
 
        local sandbox = arg.subjectNsText .. ":" .. arg.baseText .. "/sandbox"
        local argsandbox = mw.title.new(sandbox)
        if p.ifexist(sandbox) then
            table.insert(footer, '[[' .. sandbox .. '|sandbox]]')
            table.insert(footer, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(footer, argsandbox:fullUrl('action=edit'))
            table.insert(footer, ' edit])</span>')
        else
            table.insert(footer, 'sandbox&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(footer, argsandbox:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload-sandbox"}))
            table.insert(footer, ' create])</span>')
        end
        table.insert(footer, ' and ')
 
        local test = arg.subjectNsText .. ":" .. arg.baseText .. "/testcases"
        local argtest = mw.title.new(test)
        if p.ifexist(test) then
            table.insert(footer, '[[' .. test .. '|testcases]]')
            table.insert(footer, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(footer, argtest:fullUrl('action=edit'))
            table.insert(footer, ' edit])</span>')
        else
            table.insert(footer, 'testcases&nbsp;<span style="font-size:89%; font-style:normal;">([')
            table.insert(footer, argtest:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload-testcases"}))
            table.insert(footer, ' create])</span>')
        end
 
        table.insert(footer, ' pages.<br />Please add categories to the ')
        table.insert(footer, '<span class="plainlinks">[')
 
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(footer, arg:fullUrl('action=edit'))
        else
            table.insert(footer, arg:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload"}))
        end
 
        table.insert(footer, ' /doc] subpage.')
    end
    table.insert(footer, '</div>')
    return table.concat(footer)
end
 
return p

Hi could some help me to get it to look like template:documentation/start box and template:documentation/end box you can have a look at my test of it at simple:template:documentation/sandbox I had help to do it because doint know how to script but thought it was a good idea and this is we're I am testing the module on simple wiki simple:Module:Documentation 109.151.161.64 (talk) 20:16, 29 July 2013 (UTC)

hi could someone please help me make template:documentation in lua scripting I am testing it at simple:module:documentation and please see the preview of it at simple:template:documentation/sandbox 86.159.74.81 (talk) 12:06, 4 August 2013 (UTC)
The simplewiki community hasn't actually discussed whether this would be worthwhile, and this request is from a block-evading sockpuppeteer. Anyone with the spare time is of course welcome to look into fulfilling it, but as I say the project has not even begun to discuss whether we'd actually use it. Osiris (talk) 14:12, 7 August 2013 (UTC)
Well, there's no question in my mind that this is a good idea, at least for enwiki's documentation template. It's one of the more complex ones, and could certainly stand to be simplified and speeded up through a Lua module if someone has the time to put one together. — Mr. Stradivarius ♪ talk ♪ 14:16, 7 August 2013 (UTC)
ok 86.159.26.136 (talk) 18:15, 7 August 2013 (UTC)
I did it on simple wiki because they allow you to create pages without needing an account 86.159.26.136 (talk) 18:16, 7 August 2013 (UTC)
Not if you're evading a block, though, so you need to log in to your original account on Meta and request an unblock before you resume editing. Osiris (talk) 23:01, 10 August 2013 (UTC)
Absolutely agree, it's a good idea. I'll leave the code on simplewiki if somebody needs it. It'd be better, though, if it was copied to this wiki where there are more users around with the expertise to help construction. Osiris (talk) 23:01, 10 August 2013 (UTC)
but I carnt login into my original account on meta if it is locked 86.141.190.129 (talk) 10:15, 11 August 2013 (UTC)
Then you email your request to stewards wikimedia.org. Osiris (talk) 05:56, 13 August 2013 (UTC)
ok how long do I wait to ask for the account to be unblock due to me editing wikipedia recently and because I am block so how long should I wait before asking them to unblock me 86.141.190.129 (talk) 16:35, 13 August 2013 (UTC)

How can I add special pages in module so I use Special:ComparePages for diff 86.159.26.136 (talk) 15:48, 10 August 2013 (UTC)

Importing squads from Wikidata

Currently it seems not to be possible to outsource squads to Wikidata and then to import them to (different language versions of) Wikipedia. There is currently a test quad at Wikidata that could be implemented to Template:FC Bayern Munich squad and FC Bayern Munich#Current squad in future. Sorting the players according to either the last name or the jersey no. is needed. See also WT:WPF#Outsourcing of squads to Wikidata. --Leyo 10:48, 6 September 2013 (UTC)

  1. ^ xx
  2. ^ xx
  3. ^ xx