Module:Message box: Difference between revisions

Fixed a few of the ambox bugs. Still have to add category support.
(more ambox stuff - still a little broken)
(Fixed a few of the ambox bugs. Still have to add category support.)
Line 17:
end
end
return page or mw.title.getCurrentTitle()
end
 
local function presentButBlank(s)
if type(s) ~= 'string' then return end
if s and not mw.ustring.find(s, '%S') then
return true
else
return false
end
end
 
Line 24 ⟶ 33:
local title = mw.title.getCurrentTitle()
local nsid = title.namespace
 
-- Get a language object for formatDate.
local lang = mw.language.getContentLanguage()
-- Commenting this out for now - this will require tinkering with Namespace detect to differentiate between
Line 48 ⟶ 60:
 
-- Process data for collapsible text fields
local textname, issue, talk, fix, date, info
if data.useCollapsibleTextFields then
textname = args.issuename
local nameTitle = getTitleObject(name)
local isTemplatePage = nameTitle and title.prefixedText == ('Template:' .. nameTitle.text) and true or false
textlocal sect = args.textsect
if presentButBlank(sect) then
sect = 'This article '
elseif type(sect) == 'string' then
sect = 'This ' .. sect .. ' '
end
issue = (sect or '') .. (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 then
date = lang:formatDate('F Y')
end
info = args.info
elseend
 
text = args.text
-- Process the talk link, if present.
if talk then
-- See if the talk link exists and is for a talk or a content namespace.
local talkTitle = type(talk) == 'string' and getTitleObject(talk)
if not talkTitle or not talkTitle.isTalkPage then
-- If we couldn't process the talk page link, get the talk page of the current page.
local success
success, talkTitle = pcall(title.talkPageTitle, title)
if not success then
talkTitle = nil
end
end
if talkTitle and talkTitle.exists then
local talkText = ' Relevant discussion may be found on'
if talkTitle.isTalkPage then
talkText = mw.ustring.format('%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText)
else
talkText = mw.ustring.format('%s the [[%s#%s|talk page]].', talkText, talkTitle.prefixedText, talk)
end
talk = talkText
end
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
textif = argsdata.smalltext oruseCollapsibleTextFields textthen
text = args.smalltext or issue
else
text = args.smalltext or args.text
end
imageSize = data.imageSmallSize or '30x30px'
else
Line 72 ⟶ 124:
imageRight = args.imageright
imageSize = '40x40px'
text = args.text
end
 
------------------------ Get the box structure ----------------------------
 
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-text')
local imageRightCell = row.tag('td').addClass('mbox-imageright')
 
------------------------ Build the box ----------------------------
local root = htmlBuilder.create()
 
-- Do the subst check.
if data.substCheck and args.subst == 'SUBST' then
if type(args.name) == 'string' then
substCheckroot
.wikitext(mw.ustring.formattag('b')
'Template <code>%s%s%s</code> has been incorrectly substituted.addClass('error',)
.wikitext(mw.textustring.nowikiformat('{{'),
args 'Template <code>%s%s%s</code> has been incorrectly substituted.name',
mw.text.nowiki('}}{{'),
)) args.name,
mw.text.nowiki('}}')
))
end
root.wikitext('[[Category:Pages with incorrectly substituted templates]]') -- This puts the category at the *end* of the output, rather than after the subst error message.
end
 
-- Build the box.
local box = root.tag('table')
box
.attr('id', args.id)
Line 116 ⟶ 164:
 
-- Add the left-hand image.
local row = box.tag('tr')
local imageLeftCell = row.tag('td').addClass('mbox-image')
local imageCheckBlank = data.imageCheckBlank
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then
Line 130 ⟶ 180:
 
-- Add the text.
local substChecktextCell = rootrow.tag('btd').addClass('errormbox-text')
if data.useCollapsibleTextFields then
textCell
Line 136 ⟶ 187:
textCellSpan
.addClass('mbox-text-span')
.wikitext(textissue)
if not isSmall then
textCellSpan
Line 142 ⟶ 193:
.addClass('hide-when-compact')
.wikitext(talk)
.wikitext(' ')
.wikitext(fix)
.done()
Line 160 ⟶ 212:
 
-- Add the right-hand image.
local textCellimageRightCell = row.tag('td').addClass('mbox-textimageright')
if imageRight and not (data.imageRightNone and imageRight == 'none') then
if not isSmall and data.imageCellDiv then