Module:Message box: Difference between revisions

pass nocat, page, and demospace parameters to Module:Category handler, and add a choice for which arguments to allow as blank
en>Mr. Stradivarius
(add mbox, various other fixes)
en>Mr. Stradivarius
(pass nocat, page, and demospace parameters to Module:Category handler, and add a choice for which arguments to allow as blank)
Line 88: Line 88:


local function getNamespaceId(ns)
local function getNamespaceId(ns)
    if not ns then return end
     if type(ns) == 'string' then
     if type(ns) == 'string' then
         ns = lang:ucfirst(mw.ustring.lower(ns))
         ns = lang:ucfirst(mw.ustring.lower(ns))
Line 124: Line 125:


     -- Get the title object and the namespace.
     -- Get the title object and the namespace.
     local title = getTitleObject(args.page) or mw.title.getCurrentTitle()
     local pageTitle = getTitleObject(args.page ~= '' and args.page)
     local nsid = getNamespaceId(args.demospace) or title.namespace
    local title = pageTitle or mw.title.getCurrentTitle()
     local demospace = getNamespaceId(args.demospace ~= '' and args.demospace)
    local nsid = demospace or title.namespace


     -- Get the box config data from the data page.
     -- Get the box config data from the data page.
Line 141: Line 144:
         error(format('invalid message box type "%s"; valid types are %s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
         error(format('invalid message box type "%s"; valid types are %s', tostring(boxType), mw.text.listToText(boxTypes)), 2)
     end
     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 ----------------------------
     ------------------------ Process config data ----------------------------
Line 222: Line 237:
     if data.allowMainspaceCategories then
     if data.allowMainspaceCategories then
         -- Categories for the main namespace.
         -- Categories for the main namespace.
        if args.cat then
            args.cat1 = args.cat
        end
         local origCatNums = getArgNums(args, 'cat')
         local origCatNums = getArgNums(args, 'cat')
        if args.category then
            args.category1 = args.category
        end
         local origCategoryNums = getArgNums(args, 'category')
         local origCategoryNums = getArgNums(args, 'category')
         local catNums = union(origCatNums, origCategoryNums)
         local catNums = union(origCatNums, origCategoryNums)
Line 233: Line 254:


     -- Process template namespace categories
     -- Process template namespace categories
    local isTemplatePage = type(name) == 'string' and title.prefixedText == ('Template:' .. name)
     local templateCats = {}
     local templateCats = {}
     if data.templateCategory and not title.isSubpage and not yesno(args.nocat) then
     if data.templateCategory then
        tinsert(templateCats, format('[[Category:%s]]', data.templateCategory))
        if name then
            if isTemplatePage then
                tinsert(templateCats, format('[[Category:%s]]', data.templateCategory))
            end
        elseif not title.isSubpage then
            tinsert(templateCats, format('[[Category:%s]]', data.templateCategory))
        end
     end
     end
 
   
     -- Add an error category for the template namespace if appropriate.
     -- Add an error category for the template namespace if appropriate.
     if data.templateErrorCategory then
     if data.templateErrorCategory then
Line 387: Line 415:
             main = tconcat(mainCats),
             main = tconcat(mainCats),
             template = tconcat(templateCats),
             template = tconcat(templateCats),
             all = tconcat(allCats)
             all = tconcat(allCats),
            nocat = args.nocat,
            demospace = demospace and args.demospace or nil,
            page = pageTitle and pageTitle.prefixedText or nil
         })
         })
      
      
Line 415: Line 446:
                 v = mw.text.trim(v)
                 v = mw.text.trim(v)
             end
             end
             if v ~= '' or k == 'talk' or k == 'sect' or k == 'date' then
             args[k] = v
                args[k] = v
            end
         end
         end
         return p.build(boxType, args)
         return p.build(boxType, args)
Anonymous user