Module:Message box: Difference between revisions

more ambox stuff - still a little broken
(initial code for ambox)
(more ambox stuff - still a little broken)
Line 18:
end
return page or mw.title.getCurrentTitle()
end
 
local function generateBoxStructure()
local root = htmlBuilder.create() -- Includes error messages and categories added after the box.
local substCheck = root.tag('b').addClass('error')
local box = root.tag('table')
local row = box.tag('tr')
local imageLeftCell = row.tag('td')
return root, substCheck, box, row, imageLeftCell
end
 
Line 49 ⟶ 40:
]]
 
------------------------ Process config data. ----------------------------
 
-- Type data.
local typeData = data.types[args.type]
local invalidType = args.type and not typeData and true or false
typeData = typeData or data.types[data.default]
 
-- Process data for collapsible text fields
local text, talk, fix, date, info
if data.useCollapsibleTextFields then
text = args.textissue
talk = args.talk
fix = args.fix
date = args.date
info = args.info
else
text = args.text
end
 
-- Find whether we are using a small message box and process our data accordingly.
local isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false
local smallClass, image, imageRight, text, imageSize
if isSmall then
smallClass = data.smallClass or 'mbox-small'
image = args.smallimage or args.image
imageRight = args.smallimageright or args.imageright
text = args.smalltext or args.text
imageSize = data.imageSmallSize or '30x30px'
else
image = args.image
imageRight = args.imageright
text = args.text
imageSize = '40x40px'
end
 
------------------------ Get the box structure. ----------------------------
 
local root, substCheck, box, row, imageLeftCell = generateBoxStructure()
local root = htmlBuilder.create() -- Includes error messages and categories added after the box.
local substCheck = root.tag('b').addClass('error')
local box = root.tag('table')
local row = box.tag('tr')
local imageLeftCell = row.tag('td').addClass('mbox-image')
local textCell = row.tag('td').addClass('mbox-imagetext')
local imageRightCell = row.tag('td').addClass('mbox-imageright')
 
------------------------ Build the box ----------------------------
 
-- Do the subst check.
Line 104 ⟶ 118:
local imageCheckBlank = data.imageCheckBlank
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then
imageLeftCell
.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.
Line 118 ⟶ 130:
 
-- Add the text.
if data.useCollapsibleTextFields then
row.tag('td')
.addClass('mbox-text')textCell
.cssText(args.textstyle)
local textCellSpan = textCell.wikitexttag(text'span')
textCellSpan
.addClass('mbox-text-span')
row .tagwikitext('td'text)
if not isSmall then
textCellSpan
row .tag('tdspan')
.addClass('hide-when-compact')
.wikitext(talk)
.wikitext(fix)
.done()
end
textCellSpan
.wikitext(date and mw.ustring.format(" <small>''(%s)''</small>", date))
if not isSmall then
textCellSpan
.tag('span')
.addClass('hide-when-compact')
.wikitext(info and ' ' .. info)
end
else
textCell
.cssText(args.textstyle)
.wikitext(text)
end
 
-- Add the right-hand image.
if imageRight and not (data.imageRightNone and imageRight == 'none') then
if not isSmall and data.imageCellDiv then
row.tag('td')
imageRightCell = imageRightCell.tag('div').css('width', '52px') -- If we are using a div, redefine imageRightCell so that the image is inside it.
.addClass('mbox-imageright')
end
imageRightCell
.wikitext(imageRight)
end
Line 140 ⟶ 178:
end
 
------------------------ Add error messages and tracking categories. ----------------------------
 
-- Add error message and tracking category for invalid type parameters.
if invalidType then
local catsort = (nsid == 0 and 'Main:' or '') .. title.prefixedText
Line 199 ⟶ 239:
data.imageSmallSize = '20x20px'
data.imageCellDiv = true
data.talkLinkuseCollapsibleTextFields = true
data.imageRightNone = true
return p.build(data, args)
end
Line 414 ⟶ 455:
v = mw.text.trim(v)
end
if v ~= '' or k == 'talk' or k == 'sect' or k == 'date' then
args[k] = v
end