Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
merge rellink into hatnote, use an options table to pass options to the hatnote function, and add a tracking category for errors
>Mr. Stradivarius (checkType will work in for loops as well, with the power of the i variable) |
>Mr. Stradivarius (merge rellink into hatnote, use an options table to pass options to the hatnote function, and add a tracking category for errors) |
||
Line 77: | Line 77: | ||
-- Formats an error message to be returned to wikitext. | -- Formats an error message to be returned to wikitext. | ||
checkType('_makeWikitextError', 1, msg, 'string') | checkType('_makeWikitextError', 1, msg, 'string') | ||
return string.format('<strong class="error">Error: %s.</strong>', msg) | local errorCategory = 'Hatnote templates with errors' | ||
local errorCategoryLink = errorCategory | |||
and string.format( | |||
'[[%s:%s]]', | |||
mw.site.namespaces[14].name, | |||
errorCategory | |||
) | |||
or '' | |||
return string.format( | |||
'<strong class="error">Error: %s.</strong>%s', | |||
msg, | |||
errorCategoryLink | |||
) | |||
end | end | ||
Line 138: | Line 150: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local s = args[1] | local s = args[1] | ||
local options = {} | |||
if not s then | if not s then | ||
return p._makeWikitextError('no text specified') | return p._makeWikitextError('no text specified') | ||
end | end | ||
return p._hatnote(s) | options.extraclasses = args.extraclasses | ||
options.selfref = args.selfref | |||
return p._hatnote(s, options) | |||
end | end | ||
function p._hatnote(s) | function p._hatnote(s, options) | ||
checkType('_hatnote', 1, s, 'string') | checkType('_hatnote', 1, s, 'string') | ||
checkType('_hatnote', 2, options, 'table', true) | |||
local classes = {'rellink'} | |||
local extraclasses = options.extraclasses | |||
local selfref = options.selfref | |||
if type(extraclasses) == 'string' then | |||
classes[#classes + 1] = extraclasses | |||
local | |||
local | |||
end | end | ||
if selfref then | |||
classes[#classes + 1] = 'selfref' | |||
if | |||
end | end | ||
return string.format('<div class=" | return string.format( | ||
'<div class="%s">%s</div>', | |||
table.concat(classes, ' '), | |||
s | |||
) | |||
end | end | ||
return p | return p |