Editing Module:Hatnote
From Guild of Archivists
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 34: | Line 34: | ||
-- function will not work if the link is enclosed in double brackets. Colons | -- function will not work if the link is enclosed in double brackets. Colons | ||
-- are trimmed from the start of the link by default. To skip colon | -- are trimmed from the start of the link by default. To skip colon | ||
-- trimming, set the removeColon parameter to | -- trimming, set the removeColon parameter to true. | ||
checkType('findNamespaceId', 1, link, 'string') | checkType('findNamespaceId', 1, link, 'string') | ||
checkType('findNamespaceId', 2, removeColon, 'boolean', true) | checkType('findNamespaceId', 2, removeColon, 'boolean', true) | ||
Line 75: | Line 75: | ||
end | end | ||
function p.makeWikitextError(msg, helpLink, addTrackingCategory | function p.makeWikitextError(msg, helpLink, addTrackingCategory) | ||
-- Formats an error message to be returned to wikitext. If | -- Formats an error message to be returned to wikitext. If | ||
-- addTrackingCategory is not false after being returned from | -- addTrackingCategory is not false after being returned from | ||
Line 83: | Line 83: | ||
checkType('makeWikitextError', 2, helpLink, 'string', true) | checkType('makeWikitextError', 2, helpLink, 'string', true) | ||
yesno = require('Module:Yesno') | yesno = require('Module:Yesno') | ||
title = | local title = mw.title.getCurrentTitle() | ||
-- Make the help link text. | -- Make the help link text. | ||
local helpText | local helpText | ||
Line 109: | Line 109: | ||
category | category | ||
) | ) | ||
end | end | ||
Line 144: | Line 135: | ||
function p._formatLink(link, display) | function p._formatLink(link, display) | ||
-- Find whether we need to use the colon trick or not. We need to use the | |||
-- colon trick for categories and files, as otherwise category links | |||
-- categorise the page and file links display the file. | |||
checkType('_formatLink', 1, link, 'string') | checkType('_formatLink', 1, link, 'string') | ||
checkType('_formatLink', 2, display, 'string', true) | checkType('_formatLink', 2, display, 'string', true) | ||
link = removeInitialColon(link) | link = removeInitialColon(link) | ||
local namespace = p.findNamespaceId(link, false) | |||
local colon | |||
if namespace == 6 or namespace == 14 then | |||
colon = ':' | |||
else | |||
colon = '' | |||
end | |||
-- Find whether a faux display value has been added with the {{!}} magic | -- Find whether a faux display value has been added with the {{!}} magic | ||
Line 162: | Line 161: | ||
local page, section = link:match('^(.-)#(.*)$') | local page, section = link:match('^(.-)#(.*)$') | ||
if page then | if page then | ||
display = page .. ' § | display = page .. ' § ' .. section | ||
end | end | ||
end | end | ||
Line 168: | Line 167: | ||
-- Assemble the link. | -- Assemble the link. | ||
if display then | if display then | ||
return string.format( | return string.format('[[%s%s|%s]]', colon, link, display) | ||
else | else | ||
return string.format('[[ | return string.format('[[%s%s]]', colon, link) | ||
end | end | ||
end | end | ||
Line 203: | Line 198: | ||
checkType('_hatnote', 1, s, 'string') | checkType('_hatnote', 1, s, 'string') | ||
checkType('_hatnote', 2, options, 'table', true) | checkType('_hatnote', 2, options, 'table', true) | ||
local classes = {'hatnote'} | local classes = {'hatnote'} | ||
local extraclasses = options.extraclasses | local extraclasses = options.extraclasses | ||
Line 214: | Line 208: | ||
end | end | ||
return string.format( | return string.format( | ||
'<div | '<div class="%s">%s</div>', | ||
table.concat(classes, ' '), | table.concat(classes, ' '), | ||
s | s |