Module:Hatnote: Difference between revisions

129 bytes removed ,  10 years ago
merge rellink into hatnote, use an options table to pass options to the hatnote function, and add a tracking category for errors
(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:
-- Formats an error message to be returned to wikitext.
checkType('_makeWikitextError', 1, msg, 'string')
local errorCategory = 'Hatnote templates with errors'
return string.format('<strong class="error">Error: %s.</strong>', msg)
local errorCategoryLink = errorCategory
and string.format(
'[[%s:%s]]',
mw.site.namespaces[14].name,
errorCategory
)
or ''
return string.format(
return string.format( '<strong class="error">Error: %s.</strong>%s', msg)
msg,
errorCategoryLink
)
end
 
Line 138 ⟶ 150:
local args = getArgs(frame)
local s = args[1]
local soptions = args[1]{}
if not s then
return p._makeWikitextError('no text specified')
end
local options.extraclasses = args.extraclasses
return p._hatnote(s)
options.selfref = args.selfref
return p._hatnote(s, options)
end
 
function p._hatnote(s, options)
checkType('_hatnote', 1, s, 'string')
checkType('_rellink_hatnote', 2, extraclassesoptions, 'stringtable', true)
return string.format('<div class="dablink">%s</div>', s)
local classes = {'rellink'}
end
local extraclasses = ' ' options.. extraclasses
 
local selfref = options.selfref
--------------------------------------------------------------------------------
if type(extraclasses) == 'string' then
-- 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)
local s = args[1]
local extraclasses = args.extraclasses
if not s then
return p._makeWikitextError('no text specified')
end
if not sselfref then
return p._rellink(s, extraclasses)
classes[#classes + 1] = 'selfref'
end
 
function p._rellink(s, extraclasses)
checkType('_rellink', 1, s, 'string')
checkType('_rellink', 2, extraclasses, 'string', true)
if extraclasses then
extraclasses = ' ' .. extraclasses
else
extraclasses = ''
end
return string.format('<div class="rellink%s">%s</div>', extraclasses, s)
return string.format( '<div class="dablink%s">%s</div>', s)
table.concat(classes, ' '),
s
)
end
 
Anonymous user