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
m>Mr. Stradivarius
(checkType will work in for loops as well, with the power of the i variable)
m>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')
return string.format('<div class="dablink">%s</div>', s)
checkType('_hatnote', 2, options, 'table', true)
end
local classes = {'rellink'}
 
local extraclasses = options.extraclasses
--------------------------------------------------------------------------------
local selfref = options.selfref
-- Rellink
if type(extraclasses) == 'string' then
--
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
end
return p._rellink(s, extraclasses)
if selfref then
end
classes[#classes + 1] = 'selfref'
 
function p._rellink(s, extraclasses)
checkType('_rellink', 1, s, 'string')
checkType('_rellink', 2, extraclasses, 'string', true)
if extraclasses then
extraclasses = ' ' .. extraclasses
else
extraclasses = ''
end
end
return string.format('<div class="rellink%s">%s</div>', extraclasses, s)
return string.format(
'<div class="%s">%s</div>',
table.concat(classes, ' '),
s
)
end
end


return p
return p
Anonymous user