Module:Message box: Difference between revisions

Jump to navigation Jump to search
add tmbox
(add cmbox)
(add tmbox)
Line 2:
 
local htmlBuilder = require('Module:HtmlBuilder')
local nsDetect = require('Module:Namespace detect')
local yesno = require('Module:Yesno')
 
local p = {}
 
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
success, page = pcall(mw.title.new, page)
if not success then
page = nil
end
end
return page or mw.title.getCurrentTitle()
end
 
local function generateBoxStructure()
Line 14 ⟶ 28:
 
function p.build(data, args)
-- Get the title object and the namespace.
local title = mw.title.getCurrentTitle()
local nsid = title.namespace
-- Commenting this out for now - this will require tinkering with Namespace detect to differentiate between
-- invalid titles and pages where the expensive parser function count has been exceeded.
--[[
local title = nsDetect.getPageObject(args.page)
local namespace = nsDetect.main{
page = args.page,
demospace = args.demospace,
main = 'main',
talk = 'talk',
file = 'file',
category = 'category',
other = 'other'
}
]]
 
-- Process config data.
local typeData = data.types[args.type]
Line 19 ⟶ 52:
typeData = typeData or data.types[data.default]
 
local isSmall = data.allowSmall and (args.small == 'yes' or args.small == true) and true or false
local image, imageRight, text, imageSize
if isSmall then
Line 25 ⟶ 58:
imageRight = args.smallimageright or args.imageright
text = args.smalltext or args.text
imageSize = data.imageSizeSmall or data.imageSize or '40x40px30x30px'
else
image = args.image
imageRight = args.imageright
text = args.text
imageSize = data.imageSizeLarge or data.imageSize or '40x40px'
end
 
Line 59 ⟶ 92:
row.tag('td')
.addClass('mbox-empty-cell') -- No image. Cell with some width or padding necessary for text cell to have 100% width.
.cssText(data.imageEmptyCellStyle and 'border:none;padding:0px;width:1px')
end
 
Line 84 ⟶ 118:
end
 
-- Add error messages and tracking categories.
if invalidType then
local titlecatsort = mw(nsid == 0 and 'Main:' or '') .. title.getCurrentTitle()prefixedText
root
local catsort = (title.namespace == 0 and 'Main:' or '') .. title.prefixedText
root .tag('div')
.css('text-align', 'center')
.wikitext(mw.ustring.format('This message box is using an invalid "type=%s" parameter and needs fixing.', args.type or ''))
.done()
.wikitext(mw.ustring.format('[[Category:Wikipedia message box parameter needs fixing|%s]]', catsort))
end
 
-- Categorise template pages.
if data.category and nsid == 10 and not title.isSubpage and not yesno(args.nocat) then
root.wikitext(mw.ustring.format('[[Category:%s]]', data.category))
end
return tostring(root)
Line 154 ⟶ 193:
data.default = 'notice'
data.classes = {'plainlinks', 'ombox'}
data.imageSizeLargeallowSmall = '40x40px'true
data.imageSizeSmall = '30x30px'
data.imageEmptyCell = true
data.imageRightNone = true
Line 243 ⟶ 281:
data.default = 'notice'
data.classes = {'plainlinks', 'cmbox'}
return p.build(data, args)
end
 
function p._tmbox(args)
local data = {}
data.types = {
speedy = {
class = 'tmbox-speedy',
image = 'Imbox speedy deletion.png'
},
delete = {
class = 'tmbox-delete',
image = 'Imbox deletion.png'
},
content = {
class = 'tmbox-content',
image = 'Imbox content.png'
},
style = {
class = 'tmbox-style',
image = 'Edit-clear.svg '
},
move = {
class = 'tmbox-move',
image = 'Imbox move.png'
},
protection = {
class = 'tmbox-protection',
image = 'Imbox protection.png'
},
notice = {
class = 'tmbox-notice',
image = 'Imbox notice.png'
}
}
data.default = 'notice'
data.classes = {'plainlinks', 'tmbox'}
data.allowSmall = true
data.imageRightNone = true
data.imageEmptyCellStyle = true
data.category = 'Talk message boxes'
return p.build(data, args)
end
Line 280 ⟶ 359:
p.ombox = makeWrapper(p._ombox)
p.cmbox = makeWrapper(p._cmbox)
p.tmbox = makeWrapper(p._tmbox)
 
return p
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu