Changes
finish ambox and split the config functions out to Module:Message box/data
local htmlBuilder = require('Module:HtmlBuilder')
local nsDetect = require('Module:Namespace detect')
local categoryHandler = require('Module:Category handler').main
local yesno = require('Module:Yesno')
end
local function formatCategory(cat, date, all) local ret = {} cat = type(cat) == 'string' and cat date = type(date) == 'string' and date all = type(all) == 'string' and all local preposition = 'from' if cat and date then local catTitle = mw.ustring.format('Category:%s %s %s', cat, preposition, date) table.insert(ret, mw.ustring.format('[[%s]]', catTitle)) catTitle = getTitleObject(catTitle) if not catTitle or not catTitle.exists then table.insert(ret, '[[Category:Articles with invalid date parameter in template]]') end elseif cat and not date then table.insert(ret, mw.ustring.format('[[Category:%s]]', cat)) end if all then table.insert(ret, mw.ustring.format('[[Category:%s]]', all)) end return table.concat(ret)end local function union(t1, t2) -- Returns the union of two arrays. local vals = {} for i, v in ipairs(t1) do vals[v] = true end for i, v in ipairs(t2) do vals[v] = true end local ret = {} for k, v in pairs(vals) do table.insert(ret, k) end return retend local function getArgNums(args, prefix) local nums = {} for k, v in pairs(args) do local num = mw.ustring.match(tostring(k), '^' .. prefix .. '([1-9]%d*)$') if num then table.insert(nums, tonumber(num)) end end table.sort(nums) return numsend function p.build(boxType, args) -- Get the box config datafrom the data page. local dataTables = mw.loadData('Module:Message box/data') local data = dataTables[boxType] if not data then local boxTypes = {} for k, v in pairs(dataTables) do table.insert(boxTypes, mw.ustring.format('"%s"', argsk)) end error(mw.ustring.format('Invalid message box type. Valid types are %s.', mw.text.listToText(boxTypes))) end
-- Get the title object and the namespace.
local title = mw.title.getCurrentTitle()
local sect = args.sect
if presentButBlank(sect) then
sect = mw.ustring.format('This article %s ', data.sectionDefault or 'page')
elseif type(sect) == 'string' then
sect = 'This ' .. sect .. ' '
imageSize = '40x40px'
text = args.text
end
-- Process mainspace categories.
local mainCats = {}
local origCategoryNums -- origCategoryNums might be used in computing the template error category.
if data.allowMainspaceCategories then
-- Categories for the main namespace.
local origCatNums = getArgNums(args, 'cat')
local origCategoryNums = getArgNums(args, 'category')
local catNums = union(origCatNums, origCategoryNums)
for _, num in ipairs(catNums) do
local cat = args['cat' .. tostring(num)] or args['category' .. tostring(num)]
local all = args['all' .. tostring(num)]
table.insert(mainCats, formatCategory(cat, args.date, all))
end
end
-- Process template namespace categories
local templateCats = {}
if data.templateCategory and not title.isSubpage and not yesno(args.nocat) then
table.insert(templateCats, mw.ustring.format('[[Category:%s]]', data.templateCategory))
end
-- Add an error category for the template namespace if appropriate.
if data.templateErrorCategory then
local catName = data.templateErrorCategory
local templateCat
if not name and not title.isSubpage then
templateCat = mw.ustring.format('[[Category:%s]]', catName)
elseif type(name) == 'string' and title.prefixedText == ('Template:' .. name) then
local paramsToCheck = data.templateErrorParamsToCheck or {}
local count = 0
for i, param in ipairs(paramsToCheck) do
if not args[param] then
count = count + 1
end
end
if count > 0 then
templateCat = mw.ustring.format('[[Category:%s|%d]]', catName, count)
end
if origCategoryNums and #origCategoryNums > 0 then
templateCat = mw.ustring.format('[[Category:%s|C]]', catName)
end
end
table.insert(templateCats, templatecat)
end
-- Categories for all namespaces.
local allCats = {}
if invalidType then
local catsort = (nsid == 0 and 'Main:' or '') .. title.prefixedText
table.insert(allCats, mw.ustring.format('[[Category:Wikipedia message box parameter needs fixing|%s]]', catsort))
end
-- Do the subst check.
if data.substCheck and args.subst == 'SUBST' then
if type(args.name) == 'string' then
root
.tag('b')
.wikitext(mw.ustring.format(
'Template <code>%s%s%s</code> has been incorrectly substituted.',
mw.text.nowiki('{{'), args.name, mw.text.nowiki('}}')
))
end
end
-- Build Create the boxtable.
local box = root.tag('table')
box
-- Add the left-hand image.
local row = box.tag('tr')
local imageCheckBlank = data.imageCheckBlank
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then
local imageLeftCell = row.tag('td').addClass('mbox-image')
if not isSmall and data.imageCellDiv then
imageLeftCell = imageLeftCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageLeftCell so that the image is inside it.
-- Add the right-hand image.
if imageRight and not (data.imageRightNone and imageRight == 'none') then
local imageRightCell = row.tag('td').addClass('mbox-imageright')
if not isSmall and data.imageCellDiv then
imageRightCell = imageRightCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageRightCell so that the image is inside it.
end
------------------------ Add error Error messages and categories ----------------------------
-- Add error message and tracking category for invalid type parameters.
if invalidType then
root
.tag('div')
.addClass('error')
.css('text-align', 'center')
.wikitext(mw.ustring.format('This message box is using an invalid "type parameter (<code>type=%s" parameter </code>) and needs fixing.', args.type or '')) .done() .wikitext(mw.ustring.format('[[Category:Wikipedia message box parameter needs fixing|%s]]', catsort))
end
-- Categorise template pagesAdd categories using categoryHandler. if dataroot .category and nsid wikitext(categoryHandler{ main == 10 and not titletable.isSubpage and not yesnoconcat(args.nocatmainCats) then, roottemplate = table.wikitextconcat(mwtemplateCats), all = table.ustring.formatconcat('[[Category:%s]]', data.categoryallCats) }) end
return tostring(root)
end
return function (frame)
-- If called via #invoke, use the args passed into the invoking
end
end
return funcp.build(boxType, args)
end
end
p.ambox = makeWrapper(p._ambox'ambox')p.fmbox = makeWrapper(p._fmbox'fmbox')p.imbox = makeWrapper(p._imbox'imbox')p.ombox = makeWrapper(p._ombox'ombox')p.cmbox = makeWrapper(p._cmbox'cmbox')p.tmbox = makeWrapper(p._tmbox'tmbox')
return p