Module:Category disambiguation explained

local concat = table.concatlocal insert = table.insertlocal makeTitle = mw.title.makeTitlelocal messageBox = require("Module:Message box").mainlocal nowiki = mw.text.nowikilocal pagesInCategory = mw.site.stats.pagesInCategorylocal remove = table.removelocal sort = table.sortlocal trim = mw.text.trimlocal yesno = require("Module:Yesno")

local title = mw.title.getCurrentTitlelocal namespace = title.namespacelocal title_text = title.text

local p =

function p.main(frame) local args local len, needs_fixing = 0, -- Documentation example. if namespace

10 and title_text:match("Category disambiguation") then args = len = 4 -- Otherwise, process input arguments. else -- Produce a new args table, to get the actual length. -- Trim input arguments, and add various maintenance warnings as needed. args = local raw_args = (frame:getParent or frame).args for k, v in pairs(raw_args) do v = trim(v) if type(k)

"number" then if v

"" then insert(needs_fixing, "Parameter " .. k .. " is blank.") v = "" end len = k > len and k or len end args[k] = v end -- Number of parameters should be even. local orig_len = len if len % 2

1 then -- Don't give a blank parameter warning if the template call ends "|}}". if args[len]

"" then args[len] = nil len = len - 1 remove(needs_fixing) -- Otherwise we need a blank final parameter for the missing category. else len = len + 1 end end if len < 4 then insert(needs_fixing, "Should specify at least 2 categories.") end -- Fill out any missing parameters, but stop inputs like causing a cascade of warnings. local missing = 0 for i = 1, len do if not args[i] then insert(needs_fixing, "Parameter " .. i .. " not given.") args[i] = "" missing = missing + 1 if missing

10 then error("Large number of missing parameters between 1 and " .. orig_len .. " (the highest specified parameter)") end end end end local list = for i = 2, len, 2 do local topic, cat = args[i - 1], args[i] local cat_title = makeTitle(14, cat) -- Warn if the category isn't valid (e.g. "