Module:Message box: Difference between revisions
Content deleted Content added
better error message |
add mbox, various other fixes |
||
Line 1:
-- This is a meta-module for producing message box templates, including {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
-- Require necessary modules.
local htmlBuilder = require('Module:HtmlBuilder')
local categoryHandler = require('Module:Category handler').main
local yesno = require('Module:Yesno')
-- Set aliases for often-used functions to reduce table lookups.
local format = mw.ustring.format
local tinsert = table.insert
local tconcat = table.concat
local p = {}
Line 12 ⟶ 20:
-- 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
page = nil▼
end
end
return page▼
end
Line 37 ⟶ 43:
local preposition = 'from'
if cat and date then
local catTitle =
catTitle = getTitleObject(catTitle)
if not catTitle or not catTitle.exists then
end
elseif cat and not date then
end
if all then
end
return
end
Line 62 ⟶ 68:
end
local ret = {}
for k
end
table.sort(ret)
return ret
end
Line 73 ⟶ 80:
local num = mw.ustring.match(tostring(k), '^' .. prefix .. '([1-9]%d*)$')
if num then
end
end
table.sort(nums)
return nums
end
local function getNamespaceId(ns)
if type(ns) == 'string' then
ns = lang:ucfirst(mw.ustring.lower(ns))
end
end▼
local nsTable = mw.site.namespaces[ns]
if nsTable then
end
local function getMboxType(nsid)
if nsid == 0 then
return 'ambox' -- main namespace
elseif nsid == 6 then
return 'imbox' -- file namespace
elseif nsid == 14 then
return 'cmbox' -- category namespace
else
local nsTable = mw.site.namespaces[nsid]
if nsTable and nsTable.isTalk then
return 'tmbox' -- any talk namespace
else
return 'ombox' -- other namespaces or invalid input
end
end
end
function p.build(boxType, args)
if type(args) ~= 'table' then
error(format('invalid "args" parameter type; expected type "table", got type "%s"', type(args)), 2)
end
local title = getTitleObject(args.page) or mw.title.getCurrentTitle()▼
local nsid = getNamespaceId(args.demospace) or title.namespace
-- 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]
Line 87 ⟶ 136:
local boxTypes = {}
for k, v in pairs(dataTables) do
end
tinsert(boxTypes, '"mbox"')
error(
end
▲ -- Get the title object and the namespace.
▲ local title = mw.title.getCurrentTitle()
▲ local nsid = title.namespace
▲ -- Get a language object for formatDate.
▲ local lang = mw.language.getContentLanguage()
▲ main = 'main',
▲ }
------------------------ Process config data ----------------------------
Line 129 ⟶ 157:
local sect = args.sect
if presentButBlank(sect) then
sect =
elseif type(sect) == 'string' then
sect = 'This ' .. sect .. ' '
Line 161 ⟶ 189:
local talkText = ' Relevant discussion may be found on'
if talkTitle.isTalkPage then
talkText =
else
talkText =
end
talk = talkText
Line 200 ⟶ 228:
local cat = args['cat' .. tostring(num)] or args['category' .. tostring(num)]
local all = args['all' .. tostring(num)]
end
end
Line 207 ⟶ 235:
local templateCats = {}
if data.templateCategory and not title.isSubpage and not yesno(args.nocat) then
end
Line 215 ⟶ 243:
local templateCat
if not name and not title.isSubpage then
templateCat =
elseif type(name) == 'string' and title.prefixedText == ('Template:' .. name) then
local paramsToCheck = data.templateErrorParamsToCheck or {}
Line 225 ⟶ 253:
end
if count > 0 then
templateCat =
end
if origCategoryNums and #origCategoryNums > 0 then
templateCat =
end
end
end
Line 238 ⟶ 266:
if invalidType then
local catsort = (nsid == 0 and 'Main:' or '') .. title.prefixedText
end
Line 251 ⟶ 279:
.tag('b')
.addClass('error')
.wikitext(
'Template <code>%s%s%s</code> has been incorrectly substituted.',
mw.text.nowiki('{{'), name, mw.text.nowiki('}}')
))
end
end
Line 284 ⟶ 312:
end
imageLeftCell
.wikitext(image or
elseif data.imageEmptyCell then
row.tag('td')
Line 310 ⟶ 338:
end
textCellSpan
.wikitext(date and
if not isSmall then
textCellSpan
Line 351 ⟶ 379:
.addClass('error')
.css('text-align', 'center')
.wikitext(
end
Line 357 ⟶ 385:
root
.wikitext(categoryHandler{
main =
template =
all =
})
Line 395 ⟶ 423:
end
p.ambox = makeWrapper('ambox')
p.cmbox = makeWrapper('cmbox')
p.fmbox = makeWrapper('fmbox')
p.imbox = makeWrapper('imbox')
p.ombox = makeWrapper('ombox')
▲p.cmbox = makeWrapper('cmbox')
p.tmbox = makeWrapper('tmbox')
|