Module:Format link: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Copied function removeInitialColon from Module:Hatnote) |
(Integrate improvements from Module:Hatnote/sandbox, in particular use of mw.ustring by Izno and my own categoryMissing stuff) |
||
Line 106: | Line 106: | ||
italicizePage = yesno(args.italicizepage), |
italicizePage = yesno(args.italicizepage), |
||
italicizeSection = yesno(args.italicizesection), |
italicizeSection = yesno(args.italicizesection), |
||
categorizeMissing = args.categorizemissing |
|||
} |
} |
||
end |
end |
||
Line 132: | Line 133: | ||
options.italicizeSection, |
options.italicizeSection, |
||
'boolean', |
'boolean', |
||
true |
|||
⚫ | |||
checkTypeForNamedArg( |
|||
'_formatLink', |
|||
'categorizeMissing', |
|||
options.categorizeMissing, |
|||
'string', |
|||
true |
true |
||
) |
) |
||
Line 137: | Line 145: | ||
local parsed = parseLink(options.link) |
local parsed = parseLink(options.link) |
||
local display = options.display or parsed.display |
local display = options.display or parsed.display |
||
local catMissing = options.categorizeMissing |
|||
⚫ | |||
local category = '' |
|||
--Test if page exists if a diagnostic category is specified |
|||
if catMissing and (mw.ustring.len(catMissing) > 0) then |
|||
if not mw.title.new(parsed.page).exists then |
|||
category = mw.ustring.format('[[Category:%s]]', catMissing) |
|||
end |
|||
end |
|||
-- Deal with the case where we don't have to pipe the link |
-- Deal with the case where we don't have to pipe the link |
||
if not display and not parsed.section and not options.italicizePage then |
if not display and not parsed.section and not options.italicizePage then |
||
return |
return mw.ustring.format('[[:%s]]%s', parsed.link, category) |
||
end |
end |
||
Line 148: | Line 165: | ||
local section = maybeItalicize(parsed.section, options.italicizeSection) |
local section = maybeItalicize(parsed.section, options.italicizeSection) |
||
if not page then |
if not page then |
||
display = |
display = mw.ustring.format('§ %s', section) |
||
elseif section then |
elseif section then |
||
display = |
display = mw.ustring.format('%s § %s', page, section) |
||
else |
else |
||
display = page |
display = page |
||
Line 156: | Line 173: | ||
end |
end |
||
return |
return mw.ustring.format('[[:%s|%s]]%s', parsed.link, display, category) |
||
end |
end |
||