Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(checkType will work in for loops as well, with the power of the i variable) |
(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') |
||
local errorCategory = 'Hatnote templates with errors' |
|||
⚫ | |||
local errorCategoryLink = errorCategory |
|||
and string.format( |
|||
'[[%s:%s]]', |
|||
mw.site.namespaces[14].name, |
|||
errorCategory |
|||
) |
|||
or '' |
|||
return string.format( |
|||
⚫ | |||
msg, |
|||
errorCategoryLink |
|||
) |
|||
end |
end |
||
Line 138: | Line 150: | ||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local s = args[1] |
local s = args[1] |
||
⚫ | |||
if not s then |
if not s then |
||
return p._makeWikitextError('no text specified') |
return p._makeWikitextError('no text specified') |
||
end |
end |
||
⚫ | |||
⚫ | |||
options.selfref = args.selfref |
|||
⚫ | |||
end |
end |
||
function p._hatnote(s) |
function p._hatnote(s, options) |
||
checkType('_hatnote', 1, s, 'string') |
checkType('_hatnote', 1, s, 'string') |
||
⚫ | |||
⚫ | |||
local classes = {'rellink'} |
|||
end |
|||
⚫ | |||
local selfref = options.selfref |
|||
-------------------------------------------------------------------------------- |
|||
⚫ | |||
-- Rellink |
|||
classes[#classes + 1] = extraclasses |
|||
-- |
|||
-- Produces a standard link to a related article. Implements the {{rellink}} |
|||
-- template. |
|||
-------------------------------------------------------------------------------- |
|||
function p.rellink(frame) |
|||
local args = getArgs(frame) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
return p._makeWikitextError('no text specified') |
|||
end |
end |
||
⚫ | |||
return p._rellink(s, extraclasses) |
|||
classes[#classes + 1] = 'selfref' |
|||
end |
|||
function p._rellink(s, extraclasses) |
|||
checkType('_rellink', 1, s, 'string') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
extraclasses = '' |
|||
end |
end |
||
return string.format( |
return string.format( |
||
⚫ | |||
table.concat(classes, ' '), |
|||
s |
|||
) |
|||
end |
end |
||