10,178
edits
Changes
m
local p = {}---------------------------------------------------------------------------------- Helper functions--------------------------------------------------------------------------------
local function getArgNumsMessageBox:addCat(argsns, prefixcat, sort) local nums = {} if not cat then return nil end for k, v in pairs(args) do if sort then local num cat = mwstring.ustring.matchformat(tostring(k), '^' .. prefix .. '([1-9[Category:%s|%s]]%d*)$', cat, sort) if num then else tinsert cat = string.format(nums'[[Category:%s]]', tonumber(num)cat) end end self.hasCategories = true self.categories[ns] = self.categories[ns] or {} table.sortinsert(numsself.categories[ns], cat) return nums
local function getNamespaceIdMessageBox:addClass(nsclass) if not ns class then return nil end if type(ns) == 'string' then ns = lang:ucfirst table.insert(mw.ustringself.lower(ns)classes, class) if ns == 'Main' then ns = 0 end end local nsTable = mw.site.namespaces[ns] if nsTable then return nsTable.id end
local function getMboxTypeMessageBox:setParameters(nsid) local args = self.args local cfg = self.cfg -- Get type data. self.type = args.type local typeData = cfg.types[self.type] self.invalidTypeError = cfg.showInvalidTypeError and self.type and not typeData typeData = typeData or cfg.types[cfg.default] self.typeClass = typeData.class self.typeImage = typeData.image -- Gets Find if the mbox type from box has been wrongly substituted. self.isSubstituted = cfg.substCheck and args.subst == 'SUBST' -- Find whether we are using a namespace numbersmall message box. self.isSmall = cfg.allowSmall and ( cfg.smallParam and args.small == cfg.smallParam or not cfg.smallParam and yesno(args.small) ) -- Add attributes, classes and styles. self.id = args.id self.name = args.name if self.name then self:addClass('box-' .. string.gsub(self.name,' ','_')) end if yesno(args.plainlinks) ~= false then self:addClass('plainlinks') end for _, class in ipairs(cfg.classes or {}) do self:addClass(class) end if nsid self.isSmall then self:addClass(cfg.smallClass or 'mbox-small') end self:addClass(self.typeClass) self:addClass(args.class) self.style = args.style self.attrs = args.attrs -- Set text style. self.textstyle =args.textstyle -- Find if we are on the template page or not. This functionality is only -- used if useCollapsibleTextFields is set, or if both cfg.templateCategory -- and cfg.templateCategoryRequireName are set. self.useCollapsibleTextFields = 0 cfg.useCollapsibleTextFields if self.useCollapsibleTextFields or cfg.templateCategory and cfg.templateCategoryRequireName then return if self.name then local templateName = mw.ustring.match( self.name, '^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$' ) or self.name templateName = 'Template:'.. templateName self.templateTitle = getTitleObject(templateName) end self.isTemplatePage = self.templateTitle and mw.title.equals(self.title, self.templateTitle) end -- Process data for collapsible text fields. At the moment these are only -- used in {{ambox' }}. if self.useCollapsibleTextFields then -- main namespaceGet the self.issue value. if self.isSmall and args.smalltext then self.issue = args.smalltext else local sect if args.sect == '' then sect = 'This ' .. (cfg.sectionDefault or 'page') elseif nsid type(args.sect) == 6 'string' then return sect = 'This ' .. args.sect end local issue = args.issue issue = type(issue) == 'string' and issue ~= '' and issue or nil local text = args.text text = type(text) == 'string' and text or nil local issues = {} table.insert(issues, sect) table.insert(issues, issue) table.insert(issues, text) self.issue = table.concat(issues, 'imbox' ) end -- Get the self.talk value. local talk = args.talk -- Show talk links on the template page or template subpages if the talk -- file namespaceparameter is blank. if talk == '' and self.templateTitle and ( mw.title.equals(self.templateTitle, self.title) or self.title:isSubpageOf(self.templateTitle) ) then talk = '#' elseif nsid talk == 14 '' then talk = nil end if talk then return 'cmbox -- If the talk value is a talk page, make a link to that page. Else -- assume that it' s a section heading, and make a link to the talk -- category namespacepage of the current page with that section heading. else local talkTitle = getTitleObject(talk) local nsTable talkArgIsTalkPage = true if not talkTitle or not talkTitle.isTalkPage then talkArgIsTalkPage = false talkTitle = getTitleObject( self.title.text, mw.site.namespaces[nsidself.title.namespace].talk.id ) end if talkTitle and talkTitle.exists then local talkText = 'Relevant discussion may be found on' if talkArgIsTalkPage then talkText = string.format( '%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText ) else talkText = string.format( '%s the [[%s#%s|talk page]].', talkText, talkTitle.prefixedText, talk ) end self.talk = talkText end end -- Get other values. self.fix = args.fix ~= '' and args.fix or nil local date if nsTable args.date and nsTableargs.isTalk date ~= '' then date = args.date elseif args.date == '' and self.isTemplatePage then date = lang:formatDate('F Y') end if date then return self.date = string.format(" <small class='date-container'>'tmbox' (<span class='date'>%s</span>)''</small>", date) end self.info = args.info if yesno(args.removalnotice) then self.removalNotice = cfg.removalNotice end end -- Set the non-collapsible text field. At the moment this is used by all box -- any talk namespacetypes other than ambox, and also by ambox when small=yes. if self.isSmall then self.text = args.smalltext or args.text else return self.text = args.text end -- Set the below row. self.below = cfg.below and args.below -- General image settings. self.imageCellDiv = not self.isSmall and cfg.imageCellDiv self.imageEmptyCell = cfg.imageEmptyCell if cfg.imageEmptyCellStyle then self.imageEmptyCellStyle = 'omboxborder:none;padding:0px;width:1px' end -- other namespaces Left image settings. local imageLeft = self.isSmall and args.smallimage or args.image if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none' or not cfg.imageCheckBlank and imageLeft ~= 'none' then self.imageLeft = imageLeft if not imageLeft then local imageSize = self.isSmall and (cfg.imageSmallSize or '30x30px') or '40x40px' self.imageLeft = string.format('[[File:%s|%s|link=|alt=]]', self.typeImage or invalid input'Imbox notice.png', imageSize) end end -- Right image settings. local imageRight = self.isSmall and args.smallimageright or args.imageright if not (cfg.imageRightNone and imageRight == 'none') then self.imageRight = imageRight end
-- Get the title object and the namespace if not cfg.allowMainspaceCategories then local pageTitle = getTitleObject(args.page ~= '' and args.page) return nil local title = pageTitle or mw.title.getCurrentTitle() local demospace = getNamespaceId(args.demospace ~= '' and args.demospace) local nsid = demospace or title.namespace end
-- Get the box config data from the data page. if boxType == 'mbox' then boxType = getMboxType(nsid) end local dataTables = mw.loadData('Module:Message box/data') local data = dataTables[boxType] if not data then local boxTypes nums = {} for k_, v prefix in pairs(dataTables) do tinsert(boxTypes, format(ipairs{'"%s"cat', k)) end tinsert(boxTypes, '"mbox"category') error(format(, 'invalid message box type "%s"; valid types are %sall', tostring(boxType), mw.text.listToText(boxTypes)), 2)} do end -- Only allow blank arguments for the parameter names listed in data args[prefix .allowBlankParams.'1'] = args[prefix] local newArgs nums = {} for kunion(nums, v in pairsgetArgNums(args, prefix) 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 -------------------------- --The following is roughly equivalent to the old {{Ambox/category}}. local date = args.date date = type(date) == 'string' and date local preposition = 'from' for _, num in ipairs(nums) do local mainCat = args['cat' .. tostring(num)] or args['category' .. tostring(num)] local allCat = args['all' .. tostring(num)] mainCat = type(mainCat) == 'string' and mainCat allCat = type(allCat) == 'string' and allCat if mainCat and date and date ~= '' then local catTitle = string.format('%s %s %s', mainCat, preposition, date) self:addCat(0, catTitle) catTitle = getTitleObject('Category:' .. catTitle) if not catTitle or not catTitle.exists then self:addCat(0, 'Articles with invalid date parameter in template') end elseif mainCat and (not date or date == '') then self:addCat(0, mainCat) end if allCat then self:addCat(0, allCat) end endend
-- Type data.function MessageBox:setTemplateCategories() local typeData args = dataself.types[args.type] local invalidType = args.type and not typeData and true or false typeData cfg = typeData or data.types[dataself.default]cfg
-- Process data for collapsible text fieldsAdd template categories. local name, issue, talk, fix, date, info if cfg.templateCategory then if datacfg.useCollapsibleTextFields templateCategoryRequireName then name = args if self.name local nameTitle = getTitleObject(name) local isTemplatePage = nameTitle and title.prefixedText == ('Template:' .. nameTitle.text) and true or false local sect = args.sect if presentButBlank(sect) then sect = format self:addCat('This %s '10, datacfg.sectionDefault or 'page'templateCategory) elseif type(sect) == 'string' then sect = 'This ' .. sect .. ' ' end issue = (sect or '') elseif not self.title. (args.issue or '') .. ' ' .. (args.text or '') talk = args.talk if presentButBlank(talk) and isTemplatePage then talk = '#' end fix = args.fix date = args.date if presentButBlank(date) and isTemplatePage isSubpage then date = lang self:formatDateaddCat('F Y'10, cfg.templateCategory) end info = args.info end
-- Process the talk link, if presentAdd template error categories. if talk cfg.templateErrorCategory then -- See if the talk link exists and is for a talk or a content namespace local templateErrorCategory = cfg.templateErrorCategory local talkTitle = type(talk) == 'string' and getTitleObject(talk)templateCat, templateSort if not talkTitle or self.name and not talkTitleself.title.isSubpage then templateCat = templateErrorCategory elseif self.isTalkPage isTemplatePage then -- If we couldn't process the talk page link, get the talk page of the current page local paramsToCheck = cfg.templateErrorParamsToCheck or {} local successcount = 0 success for i, talkTitle = pcallparam in ipairs(title.talkPageTitle, titleparamsToCheck)do if not success args[param] then talkTitle count = nilcount + 1 end end if talkTitle and talkTitle.exists count > 0 then local talkText templateCat = templateErrorCategory templateSort = ' Relevant discussion may be found on'tostring(count) end if talkTitleself.isTalkPage categoryNums and #self.categoryNums > 0 then talkText templateCat = templateErrorCategory templateSort = format('%s [[%s|%s]].C', talkText, talk, talkTitle.prefixedText) else end end talkText = format self:addCat('%s the [[%s#%s|talk page]].'10, talkTexttemplateCat, talkTitle.prefixedText, talktemplateSort) end talk = talkText end end
function MessageBox:setAllNamespaceCategories() -- Find whether we are using a small message box and process our data accordinglySet categories for all namespaces. if self.invalidTypeError then local isSmall allSort = data(self.allowSmall and (argstitle.small namespace == 0 and 'yesMain:' or args'') .. self.title.small == true) and true or falseprefixedText local smallClass self:addCat('all', image'Wikipedia message box parameter needs fixing', imageRight, text, imageSizeallSort) end if isSmall self.isSubstituted then smallClass = data.smallClass or self:addCat('all', 'mbox-smallPages with incorrectly substituted templates') image = args endend function MessageBox:setCategories() if self.smallimage or argstitle.imagenamespace == 0 then self:setMainspaceCategories() imageRight = args elseif self.smallimageright or argstitle.imagerightnamespace == 10 then self:setTemplateCategories() end self:setAllNamespaceCategories()end function MessageBox:renderCategories() if datanot self.useCollapsibleTextFields hasCategories then text = args -- No categories added, no need to pass them to Category handler so, -- if it was invoked, it would return the empty string.smalltext or issue else -- So we shortcut and return the empty string. text = args.smalltext or args.text return "" end imageSize = data -- Convert category tables to strings and pass them through -- [[Module:Category handler]].imageSmallSize or return require('30x30pxModule:Category handler')._main{ else main = table.concat(self.categories[0] or {}), image template = argstable.concat(self.imagecategories[10] or {}), imageRight all = argstable.concat(self.categories.imagerightall or {}), imageSize nocat = '40x40px'self.args.nocat, text page = self.args.textpage } end function MessageBox:export() local root = mw.html.create()
-- Process mainspace categories. local mainCats = {} local origCategoryNums -- origCategoryNums might be used in computing Add the template subst check error category. if data.allowMainspaceCategories then -- Categories for the main namespaceself. if argsisSubstituted and self.cat name then args.cat1 = args.cat end local origCatNums = getArgNums root:tag(args, 'catb') if args.category then args.category1 = args.category end local origCategoryNums = getArgNums :addClass(args, 'categoryerror') local catNums = union :wikitext(origCatNums, origCategoryNums) for _, num in ipairsstring.format(catNums) do local cat = args 'Template <code>%s[[Template:%s|%s]]%s</code> has been incorrectly substituted.'cat' , mw.text. tostringnowiki(num)] or args['category{{' ), self.name, self.name, mw.text. tostringnowiki(num)] local all = args['all}}' .. tostring(num)] tinsert(mainCats, formatCategory(cat, args.date, all )) end end
-- Process template namespace categoriesCreate the box table. local isTemplatePage boxTable = typeroot:tag(name) == 'stringtable' and title.prefixedText == ('Template:' .. name) local templateCats = {} if data.templateCategory then if name then if isTemplatePage then tinsert(templateCats, format('[[Category boxTable:%s]]', data.templateCategory)) end elseif not title.isSubpage then tinsert(templateCats, formatattr('[[Category:%s]]id', dataself.templateCategory)id or nil) end 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 = format('[[Category:%s]]'i, catName) elseif typeclass in ipairs(name) == 'string' and title.prefixedText == ('Template:' .self. name) then local paramsToCheck = data.templateErrorParamsToCheck classes or {}) do local count = 0 for i, param in ipairs boxTable:addClass(paramsToCheckclass or nil) do if not args[param] then count = count + 1 end end boxTable if count > 0 then :cssText(self.style or nil) templateCat = format :attr('[[Category:%s|%d]]role', catName, count) end if origCategoryNums and #origCategoryNums > 0 then templateCat = format('[[Category:%s|C]]presentation', catName) end end tinsert(templateCats, templatecat) end
-- Categories for all namespaces if self. local allCats = {} if invalidType attrs then local catsort = boxTable:attr(nsid == 0 and 'Main:' or '') .. titleself.prefixedText tinsert(allCats, format('[[Category:Wikipedia message box parameter needs fixing|%s]]', catsort)attrs) end
--Add the left-hand image. local row = boxTable:tag('tr') if self.imageLeft then local imageLeftCell = row:tag('td'):addClass('mbox-image') if self.imageCellDiv then --If we are using a div, redefine imageLeftCell so that the image --is inside it. Divs use style="width: 52px;", which limits the --image width to 52px. If any images in a div are wider than that, --they may overlap with the text or cause other display problems. imageLeftCell = imageLeftCell:tag('div'):css('width', '52px') end imageLeftCell:wikitext(self.imageLeft or nil) elseif self.imageEmptyCell then --Some message boxes define an empty cell if no image is specified, and --some don't. The old template code in templates where empty cells are -------- Build specified gives the box ------------------------following hint: "No image. Cell with some width --or padding necessary for text cell to have 100% width." row:tag('td') :addClass('mbox-empty-cell') local root = htmlBuilder :cssText(self.create(imageEmptyCellStyle or nil) end
-- Do Add the subst checktext. local textCell = row:tag('td'):addClass('mbox-text') if dataself.useCollapsibleTextFields then -- The message box uses advanced text parameters that allow things to be -- collapsible. At the moment, only ambox uses this.substCheck and args textCell:cssText(self.subst =textstyle or nil) local textCellDiv = textCell:tag('SUBSTdiv' then) textCellDiv if type :addClass(name) == 'stringmbox-text-span' then) root :wikitext(self.issue or nil) if (self.talk or self.fix) and not self.isSmall then textCellDiv:tag('bspan') . :addClass('errorhide-when-compact') :wikitext(self.talk and (' ' .. self.talk) or nil) :wikitext(formatself.fix and (' ' .. self.fix) or nil) end textCellDiv:wikitext(self.date and (' 'Template <code>%s%s%s</code> has been incorrectly substituted.',. self.date) or nil) mw if self.textinfo and not self.nowikiisSmall then textCellDiv :tag('span') :addClass('{{hide-when-compact'), name, mw :wikitext(self.info and (' ' .. self.textinfo) or nil) end if self.nowikiremovalNotice then textCellDiv:tag('}}small') :addClass('hide-when-compact') :tag('i') :wikitext(string.format(" (%s)", self.removalNotice)) end tinsert else -- Default text formatting - anything goes. textCell :cssText(allCats, '[[Categoryself.textstyle or nil) :Pages with incorrectly substituted templates]]'wikitext(self.text or nil) end
-- Create Add the box tableright-hand image. if self.imageRight then local box imageRightCell = root.row:tag('tabletd') box .attr:addClass('idmbox-imageright', args.id) for i, class in ipairs(data if self.classes) doimageCellDiv then box -- If we are using a div, redefine imageRightCell so that the image -- is inside it.addClass(class) end box .addClass imageRightCell = imageRightCell:tag(isSmall and smallClass'div') .addClass:css(data.classPlainlinksYesno and yesno(args.plainlinks or true) and 'plainlinkswidth', '52px') .addClass(typeData.class) end .addClass(args.class) imageRightCell .cssText :wikitext(argsself.styleimageRight or nil) .attr('role', 'presentation') end
-- Add the left-hand imagebelow row. local row = box if self.below then boxTable: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 :attr('divcolspan'), self.css(imageRight and 'width3', or '52px2') -- If we are using a div, redefine imageLeftCell so that the image is inside it. end imageLeftCell .wikitext(image or format('[[File :%s|%s|link=|alt=]]', typeData.image, imageSize)) elseif data.imageEmptyCell then row.tag('td') .addClass('mbox-empty-celltext') -- No image :cssText(self. Cell with some width textstyle or padding necessary for text cell to have 100% width.nil) .cssText :wikitext(dataself.imageEmptyCellStyle and 'border:none;padding:0px;width:1px'below or nil) end
-- Add the text. local textCell = row.tag('td')error message for invalid type parameters.addClass('mbox-text') if dataself.useCollapsibleTextFields invalidTypeError then textCell .cssText(args.textstyle) local textCellSpan = textCell. root:tag('spandiv') textCellSpan .addClass :css('mbox-text-spanalign') .wikitext(issue) if not isSmall then textCellSpan .tag(, 'spancenter') .addClass :wikitext('hide-when-compact') string.wikitextformat(talk) .wikitext(' ') .wikitext(fix) .done() end textCellSpan .wikitext(date and format(This message box is using an invalid " <small>''(type=%s)''</small>", date)) if not isSmall then textCellSpan parameter and needs fixing.tag('span'), self.addClass('hide-when-compact') .wikitext(info and type or ' ' .. info) end else textCell .cssText(args.textstyle ) .wikitext(text) end
-- Add the right-hand imagecategories. if imageRight and not root:wikitext(data.imageRightNone and imageRight == 'none') then local imageRightCell = row.tagself:renderCategories('td').addClass('mbox-imageright'or nil) 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 imageRightCell .wikitext(imageRight) end
-- Add the below row. if data.below and args.below then box.tag('tr') .tag('td') .attr('colspan', args.imageright and '3' or '2') .addClass('mbox-text') .cssText(args.textstyle) .wikitext return tostring(args.belowroot) end
------------------------ Error messages and categories ---------------------------------------------------------- Exports--------------------------------------------------------------------------------
-- Add error message for invalid type parameters. if invalidType then root .tag('div') .addClass('error') .css('text-align'local p, 'center') .wikitext(format('This message box is using an invalid type parameter (<code>typemt =%s</code>) and needs fixing.'{}, args.type or '')) end{}
-- Add categories using categoryHandler. root function p.wikitext(categoryHandler{ main = tconcat_exportClasses(mainCats), template = tconcat(templateCats), all = tconcat(allCats), nocat = args -- For testing.nocat, demospace = demospace and args.demospace or nil, return { page MessageBox = pageTitle and pageTitle.prefixedText or nilMessageBox }) return tostring(root)
local function makeWrapperp.main(boxType) return function (frame) -- If called via #invoke, use the args passed into the invoking -- template, or the args passed to #invoke if any exist. Otherwise -- assume args are being passed directly in from the debug consolecfgTables) -- or from another Lua module. local origArgs if frame box == mwMessageBox.getCurrentFramenew() then origArgs = frame:getParent().boxType, args for k, v in pairscfgTables or mw.loadData(frame.argsCONFIG_MODULE) do origArgs = frame.args break end else origArgs = frame end -- Trim whitespace and remove blank arguments. local args = {} for k, v in pairs(origArgs) do if type box:setParameters(v) == 'string' then v = mw.text.trim box:setCategories(v) end args[k] = v end return p.buildbox:export(boxType, args) end
pfunction mt.mbox = makeWrapper__index('mbox't, k)p.ambox = makeWrapper return function ('ambox'frame)p.cmbox if not getArgs then getArgs = makeWrapperrequire('cmboxModule:Arguments').getArgsp end return t.fmbox main(k, getArgs(frame, {trim = makeWrapper('fmbox'false, removeBlanks = false})p.imbox = makeWrapper('imbox')p.ombox = makeWrapper('ombox') endp.tmbox = makeWrapper('tmbox')end
1 revision imported
-- This is a meta-module for producing message box templates, including -- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
-- Require Load necessary modules.local htmlBuilder = require('Module:HtmlBuilderNo globals')local categoryHandler = require('Module:Category handler').maingetArgs
local yesno = require('Module:Yesno')
local lang = mw.language.getContentLanguage()
-- Set aliases for often-used functions to reduce table lookups.Define constantslocal format CONFIG_MODULE = mw.ustring.format'Module:Message box/configuration'local tinsert DEMOSPACES = table.insertlocal tconcat {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = table.concat'ambox'}
local function getTitleObject(page) if type(page...) == 'string' then -- Get the title object, passing the function through pcall -- in case we are over the expensive function count limit. local success, title = pcall(mw.title.new, page...) if success then return title end end
end
local function presentButBlankunion(st1, t2) if type -- Returns the union of two arrays. local vals = {} for i, v in ipairs(st1) ~do vals[v] = 'string' then return true end for i, v in ipairs(t2) do vals[v] = true end if s and not mw.ustring local ret = {} for k in pairs(vals) do table.findinsert(sret, '%S'k) then return true end else table.sort(ret) return false endret
end
local function formatCategorygetArgNums(catargs, date, allprefix) local ret nums = {} cat = type for k, v in pairs(catargs) == 'string' and catdo date local num = typemw.ustring.match(date) == 'string' and date all = typetostring(allk) == , 'string^' and all local preposition = 'from.. prefix .. ' if cat and date then local catTitle = format('Category:%s %s [1-9]%s', cat, preposition, dated*) tinsert(ret, format('[[%s]]$', catTitle)) catTitle = getTitleObject(catTitle) if not catTitle or not catTitle.exists num then tinsert(ret, '[[Category:Articles with invalid date parameter in template]]') end elseif cat and not date then tinsert table.insert(retnums, formattonumber('[[Category:%s]]', catnum)) end if all then end tinsert(ret, format table.sort('[[Category:%s]]', allnums)) end return tconcat(ret)nums
end
---------------------------------------------------------------------------------- Box class definition-------------------------------------------------------------------------------- local MessageBox = {}MessageBox.__index = MessageBox function unionMessageBox.new(t1boxType, t2args, cfg) args = args or {} local obj = {} -- Set the title object and the namespace. obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle() -- Returns Set the union config for our box type. obj.cfg = cfg[boxType] if not obj.cfg then local ns = obj.title.namespace -- boxType is "mbox" or invalid input if args.demospace and args.demospace ~= '' then -- implement demospace parameter of two arraysmbox local demospace = string.lower(args.demospace) if DEMOSPACES[demospace] then -- use template from DEMOSPACES obj.cfg = cfg[DEMOSPACES[demospace]] elseif string.find( demospace, 'talk' ) then -- demo as a talk page obj.cfg = cfg.tmbox else -- default to ombox obj.cfg = cfg.ombox end elseif ns == 0 then obj.cfg = cfg.ambox -- main namespace elseif ns == 6 then obj.cfg = cfg.imbox -- file namespace elseif ns == 14 then obj.cfg = cfg.cmbox -- category namespace else local nsTable = mw.site.namespaces[ns] if nsTable and nsTable.isTalk then obj.cfg = cfg.tmbox -- any talk namespace else obj.cfg = cfg.ombox -- other namespaces or invalid input end end end -- Set the arguments, and remove all blank arguments except for the ones -- listed in cfg.allowBlankParams. do local vals newArgs = {} for ik, v in ipairspairs(t1args) do vals if v ~= '' then newArgs[vk] = truev end end for i, v param in ipairs(t2obj.cfg.allowBlankParams or {}) do vals newArgs[vparam] = trueargs[param] end local ret obj.args = newArgs end -- Define internal data structure. obj.categories = {} obj.classes = {} for k in pairs(vals) do -- For lazy loading of [[Module:Category handler]]. tinsert(ret, k) obj.hasCategories = false end table.sort return setmetatable(retobj, MessageBox) return ret
end
end
end
end
function p.buildMessageBox:setMainspaceCategories(boxType, args) if type( local args) ~= 'table' then error(format('invalid "self.args" parameter type; expected type "table", got type "%s"', type(args)), 2) end local cfg = self.cfg
end
end
return setmetatable(p, mt)