Module:Category see also
Appearance
![]() | This Lua module is used on approximately 48,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module implements {{Category see also}}. It produces see also links to categories which look something like this:
For full documentation, see Template:Category see also.
-- This module implements {{Category see also}}
local mHatnote = require('Module:Hatnote')
local p = {}
local function makeWikitextError(msg)
return string.format(
'<strong class="error">Error: %s ([[Template:Category see also]])</strong>',
msg
)
end
-- Given a project string, returns a function that formats categories for that
-- project. The project can be nil, in which case it formats the category for
-- the current project.
--
-- This is implemented as a function generator rather than a simple function
-- so that we can just process the project name once, instead of every time
-- we generate a category.
local function generateCategoryLinkMaker(project)
local formatString
if project then
formatString = '[[:' .. project .. ':Category:%s|%s]]'
else
formatString = '[[:Category:%s|%s]]'
end
return function (category)
return formatString:format(category, category)
end
end
function p._main(args)
if not args[1] then
return makeWikitextError('at least one parameter required')
end
local makeCategoryLink = generateCategoryLinkMaker(args.project)
local links = {}
for i, cat in ipairs(args) do
links[i] = makeCategoryLink(cat)
end
local hatnoteText = string.format(
'%s: %s.',
args.LABEL or 'See also',
mw.text.listToText(links, ', ', ', and ')
)
return mHatnote._hatnote(hatnoteText, {selfref = true})
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Category see also',
})
return p._main(args)
end
return p