Changes

Module:Message box

985 bytes added, 06:02, 27 September 2013
pass nocat, page, and demospace parameters to Module:Category handler, and add a choice for which arguments to allow as blank
local function getNamespaceId(ns)
if not ns then return end
if type(ns) == 'string' then
ns = lang:ucfirst(mw.ustring.lower(ns))
-- Get the title object and the namespace.
local title pageTitle = getTitleObject(args.page ~= '' and args.page) local title = pageTitle or mw.title.getCurrentTitle() local nsid demospace = getNamespaceId(args.demospace ~= '' and args.demospace) local nsid = demospace or title.namespace
-- Get the box config data from the data page.
error(format('invalid message box type "%s"; valid types are %s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
end
-- Only allow blank arguments for the parameter names listed in data.allowBlankParams.
local newArgs = {}
for k, v in pairs(args) do
for i, param in ipairs(data.allowBlankParams or {}) do
if v ~= '' or k == param then
newArgs[k] = v
end
end
end
args = newArgs
newArgs = nil
------------------------ Process config data ----------------------------
if data.allowMainspaceCategories then
-- Categories for the main namespace.
if args.cat then
args.cat1 = args.cat
end
local origCatNums = getArgNums(args, 'cat')
if args.category then
args.category1 = args.category
end
local origCategoryNums = getArgNums(args, 'category')
local catNums = union(origCatNums, origCategoryNums)
-- Process template namespace categories
local isTemplatePage = type(name) == 'string' and title.prefixedText == ('Template:' .. name)
local templateCats = {}
if data.templateCategory and then if name then if isTemplatePage then tinsert(templateCats, format('[[Category:%s]]', data.templateCategory)) end elseif not title.isSubpage and not yesno(args.nocat) then tinsert(templateCats, format('[[Category:%s]]', data.templateCategory)) end
end
-- Add an error category for the template namespace if appropriate.
if data.templateErrorCategory then
main = tconcat(mainCats),
template = tconcat(templateCats),
all = tconcat(allCats), nocat = args.nocat, demospace = demospace and args.demospace or nil, page = pageTitle and pageTitle.prefixedText or nil
})
v = mw.text.trim(v)
end
if v ~= '' or k == 'talk' or k == 'sect' or k == 'date' then args[k] = v end
end
return p.build(boxType, args)
Anonymous user