Module:Category disambiguation
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 2,600 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. |
Usage
This module implements the {{Category disambiguation}} template. Please see the template page for usage instructions.
local concat = table.concat
local getArgs = require("Module:Arguments").getArgs
local insert = table.insert
local messageBox = require("Module:Message box").main
local namespace = mw.title.getCurrentTitle().namespace
local p = {}
function p.main(frame)
-- We want to keep blanks in the list or ipairs will terminate early, but if allowredlink is blank it should be nil.
local args = getArgs(frame, {
removeBlanks = false,
})
local allowredlink = args.allowredlink ~= "" and args.allowredlink or nil
local list, topic, needs_fixing = {}
for i, arg in ipairs(args) do
if i % 2 == 1 then
topic = arg
else
insert(
list,
"*For " .. topic .. ", see '''[[:Category:" .. arg .. "]].'''"
)
-- Add "needs fixing" category if:
-- (1) We're in the category namespace.
-- (2) allowredlink isn't set.
-- (3) The category is a redlink. (Use :getContent() to avoid triggering the expensive parser function count.)
if (
not needs_fixing and
namespace == 14 and
not (allowredlink or mw.title.new(arg, 14):getContent())
) then
needs_fixing = true
end
end
end
if #list < 2 then
error("Please supply at least two categories, using the first four parameters.")
end
return messageBox("cmbox", {
type = "content",
image = "[[File:Disambig gray.svg|50px]]",
text = "'''This category is not in use because it has an ambiguous title.'''" ..
frame:expandTemplate{
title = "Plainlist",
args = {
concat(list, "\n"),
style = "margin-left:1.6em;"
}
} ..
"'''Note:''' This category page should be empty. All entries should be recategorized under one of the above categories or an appropriate subcategory."
}) .. (needs_fixing and "[[Category:Wikipedia category-disambiguation box parameter needs fixing|∃" ..
mw.title.getCurrentTitle().text .. "]]" or "")
end
return p