Module:Hatnote: Difference between revisions

we templatestyles now
m (1 revision imported)
(we templatestyles now)
Line 94: Line 94:
-- Make the category text.
-- Make the category text.
local category
local category
if not title.isTalkPage and yesno(addTrackingCategory) ~= false then
if not title.isTalkPage -- Don't categorise talk pages
and title.namespace ~= 2 -- Don't categorise userspace
and yesno(addTrackingCategory) ~= false -- Allow opting out
then
category = 'Hatnote templates with errors'
category = 'Hatnote templates with errors'
category = string.format(
category = string.format(
Line 127: Line 130:
-- with colons if necessary, and links to sections are detected and displayed
-- with colons if necessary, and links to sections are detected and displayed
-- with " § " as a separator rather than the standard MediaWiki "#". Used in
-- with " § " as a separator rather than the standard MediaWiki "#". Used in
-- the {{format hatnote link}} template.
-- the {{format link}} template.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


Line 138: Line 141:
return p.makeWikitextError(
return p.makeWikitextError(
'no link specified',
'no link specified',
'Template:Format hatnote link#Errors',
'Template:Format link#Errors',
args.category
args.category
)
)
Line 177: Line 180:
local prePipe, display = link:match('^(.-)|(.*)$')
local prePipe, display = link:match('^(.-)|(.*)$')
link = prePipe or link
link = prePipe or link
-- Find the page, if it exists.
-- For links like [[#Bar]], the page will be nil.
local preHash, postHash = link:match('^(.-)#(.*)$')
local page
if not preHash then
-- We have a link like [[Foo]].
page = link
elseif preHash ~= '' then
-- We have a link like [[Foo#Bar]].
page = preHash
end


-- Find the section, if it exists.
-- Find the section, if it exists.
local page, section = link:match('^(.-)#(.*)$')
local section
page = page or link
if postHash and postHash ~= '' then
section = postHash
end
return {
return {
Line 228: Line 245:
local page = maybeItalicize(parsed.page, options.italicizePage)
local page = maybeItalicize(parsed.page, options.italicizePage)
local section = maybeItalicize(parsed.section, options.italicizeSection)
local section = maybeItalicize(parsed.section, options.italicizeSection)
if section then
if not page then
display = string.format('§ %s', section)
elseif section then
display = string.format('%s § %s', page, section)
display = string.format('%s § %s', page, section)
else
else
Line 274: Line 293:
end
end
return string.format(
return string.format(
'<div role="note" class="%s">%s</div>',
'%s<div role="note" class="%s">%s</div>',
mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' }
},
table.concat(classes, ' '),
table.concat(classes, ' '),
s
s
Anonymous user