Difference between revisions of "Module:Message box"
Fixed a few of the ambox bugs. Still have to add category support.
>Mr. Stradivarius (more ambox stuff - still a little broken) |
>Mr. Stradivarius (Fixed a few of the ambox bugs. Still have to add category support.) |
||
Line 17: | Line 17: | ||
end | end | ||
end | end | ||
return page | return page | ||
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 | end | ||
Line 24: | Line 33: | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
local nsid = title.namespace | 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 | -- Commenting this out for now - this will require tinkering with Namespace detect to differentiate between | ||
Line 48: | Line 60: | ||
-- Process data for collapsible text fields | -- Process data for collapsible text fields | ||
local | local name, issue, talk, fix, date, info | ||
if data.useCollapsibleTextFields then | if data.useCollapsibleTextFields then | ||
text = args.issue | name = args.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 = 'This article ' | |||
elseif type(sect) == 'string' then | |||
sect = 'This ' .. sect .. ' ' | |||
end | |||
issue = (sect or '') .. (args.issue or '') .. ' ' .. (args.text or '') | |||
talk = args.talk | talk = args.talk | ||
if presentButBlank(talk) and isTemplatePage then | |||
talk = '#' | |||
end | |||
fix = args.fix | fix = args.fix | ||
date = args.date | date = args.date | ||
if presentButBlank(date) and isTemplatePage then | |||
date = lang:formatDate('F Y') | |||
end | |||
info = args.info | info = args.info | ||
else | end | ||
-- 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 | end | ||
-- Find whether we are using a small message box and process our data accordingly. | -- 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 isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false | ||
local smallClass, image, imageRight, imageSize | local smallClass, image, imageRight, text, imageSize | ||
if isSmall then | if isSmall then | ||
smallClass = data.smallClass or 'mbox-small' | smallClass = data.smallClass or 'mbox-small' | ||
image = args.smallimage or args.image | image = args.smallimage or args.image | ||
imageRight = args.smallimageright or args.imageright | imageRight = args.smallimageright or args.imageright | ||
text = args.smalltext or text | if data.useCollapsibleTextFields then | ||
text = args.smalltext or issue | |||
else | |||
text = args.smalltext or args.text | |||
end | |||
imageSize = data.imageSmallSize or '30x30px' | imageSize = data.imageSmallSize or '30x30px' | ||
else | else | ||
Line 72: | Line 124: | ||
imageRight = args.imageright | imageRight = args.imageright | ||
imageSize = '40x40px' | imageSize = '40x40px' | ||
text = args.text | |||
end | end | ||
------------------------ Build the box ---------------------------- | ------------------------ Build the box ---------------------------- | ||
local root = htmlBuilder.create() | |||
-- Do the subst check. | -- Do the subst check. | ||
if data.substCheck and args.subst == 'SUBST' then | if data.substCheck and args.subst == 'SUBST' then | ||
if type(args.name) == 'string' then | if type(args.name) == 'string' then | ||
root | |||
.wikitext(mw.ustring.format( | .tag('b') | ||
.addClass('error') | |||
.wikitext(mw.ustring.format( | |||
'Template <code>%s%s%s</code> has been incorrectly substituted.', | |||
mw.text.nowiki('{{'), | |||
args.name, | |||
mw.text.nowiki('}}') | |||
)) | |||
end | end | ||
root.wikitext('[[Category:Pages with incorrectly substituted templates]]') | root.wikitext('[[Category:Pages with incorrectly substituted templates]]') | ||
end | end | ||
-- Build the box. | -- Build the box. | ||
local box = root.tag('table') | |||
box | box | ||
.attr('id', args.id) | .attr('id', args.id) | ||
Line 116: | Line 164: | ||
-- Add the left-hand image. | -- Add the left-hand image. | ||
local row = box.tag('tr') | |||
local imageLeftCell = row.tag('td').addClass('mbox-image') | |||
local imageCheckBlank = data.imageCheckBlank | local imageCheckBlank = data.imageCheckBlank | ||
if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then | if image ~= 'none' and not imageCheckBlank or image ~= 'none' and imageCheckBlank and image ~= 'blank' then | ||
Line 130: | Line 180: | ||
-- Add the text. | -- Add the text. | ||
local textCell = row.tag('td').addClass('mbox-text') | |||
if data.useCollapsibleTextFields then | if data.useCollapsibleTextFields then | ||
textCell | textCell | ||
Line 136: | Line 187: | ||
textCellSpan | textCellSpan | ||
.addClass('mbox-text-span') | .addClass('mbox-text-span') | ||
.wikitext( | .wikitext(issue) | ||
if not isSmall then | if not isSmall then | ||
textCellSpan | textCellSpan | ||
Line 142: | Line 193: | ||
.addClass('hide-when-compact') | .addClass('hide-when-compact') | ||
.wikitext(talk) | .wikitext(talk) | ||
.wikitext(' ') | |||
.wikitext(fix) | .wikitext(fix) | ||
.done() | .done() | ||
Line 160: | Line 212: | ||
-- Add the right-hand image. | -- Add the right-hand image. | ||
local imageRightCell = row.tag('td').addClass('mbox-imageright') | |||
if imageRight and not (data.imageRightNone and imageRight == 'none') then | if imageRight and not (data.imageRightNone and imageRight == 'none') then | ||
if not isSmall and data.imageCellDiv then | if not isSmall and data.imageCellDiv then |