Jump to content

Module talk:OSM

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Polyglot (talk | contribs) at 12:48, 5 August 2015 (help). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Error with no linktext

@Polyglot: Nice module! This is a really interesting idea. I just noticed that the module will produce an error if you don't supply frame.args.linktext and the page also has a Wikidata entry. Should there be a default display value instead of a red error message? (Also, maybe "display" or something would be a more elegant parameter name than "linktext"?) Best — Mr. Stradivarius ♪ talk ♪ 06:27, 5 August 2015 (UTC)[reply]

I just saw the error appearing myself. Yesterday all tests were fine, because the Module was only present on nl.WP. I'll have to find a better way to simulate a page with no link to a wikidata entry.
Oops, you're talking about something else. I considered the linktext parameter as mandatory. This means it can't be used in templates for references though. I guess I'll have some more coding to do... Maybe simply text? I'll add a parameter to have it return simply text without link as well. --Polyglot (talk) 08:59, 5 August 2015 (UTC)[reply]
@Polyglot: If linktext is really compulsory, then you could output a more informative error message, e.g.:
if not frame.args.linktext then
	error('No "linktext" argument provided', 2)
end
Or if you would rather that the error didn't show up in Category:Pages with script errors then you could do the same thing with wikitext:
if not frame.args.linktext then
	return '<strong class="wikitext">No "linktext" argument provided</strong>'
end
Or alternatively you could make the subpage name the default display text:
local display = frame.args.linktext or mw.title.getCurrentTitle().subpageText
Whichever you think works the best. :) — Mr. Stradivarius ♪ talk ♪ 09:14, 5 August 2015 (UTC)[reply]
Also, I like "linktext" better than "text", although I think "display" is better than both. (That's just my personal preference, though.) — Mr. Stradivarius ♪ talk ♪ 09:24, 5 August 2015 (UTC)[reply]
@Mr. Stradivarius: I'll start changing it to display. You seem to be the goto guy if it comes to Lua scripts! :-) I was wondering. I copied the code to test the scripts from Module:Wikidata on nl.WP, but it has an incredible amount of duplication, which makes it error prone to work with. Isn't there a more elegant way to accomplish testing? I would have written more tests if it were more practical to do so. I'm a big believer in TDD. --Polyglot (talk) 10:16, 5 August 2015 (UTC)[reply]

Unit testing

@Mr. Stradivarius: I tried to create a module to ease unit testing, but it doesn't get transcluded. Do you see a way to make that work?--Polyglot (talk) 12:48, 5 August 2015 (UTC)[reply]