Diferencia entre revisiones de «Módulo:Message box»

1883 bytes eliminados ,  24 dic 2023
m
1 revisión importada
wikitves>CaiusSPQR
m (um pouco de cleanup)
 
m (1 revisión importada)
 
(No se muestran 4 ediciones intermedias de 3 usuarios)
Línea 1: Línea 1:
-- This is a meta-module for producing message box templates, including
require('strict')
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
 
-- Load necessary modules.
require('Módulo:No globals')
local getArgs
local getArgs
local yesno = require('Módulo:Yesno')
local yesno = require('Module:Yesno')
 
-- Get a language object for formatDate and ucfirst.
local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()


-- Define constants
local CONFIG_MODULE = 'Module:Message box/configuration'
local CONFIG_MODULE = 'Módulo:Message box/configuration'
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}
local DEMOSPACES = {
talk = 'tmbox',
image = 'imbox',
file = 'imbox',
category = 'cmbox',
article = 'ambox',
main = 'ambox',
['discussão'] = 'tmbox',
imagem = 'imbox',
ficheiro = 'imbox',
categoria = 'cmbox',
artigo = 'ambox',
principal = 'ambox',
}


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Línea 81: Línea 61:


-- Set the title object and the namespace.
-- Set the title object and the namespace.
obj.title = getTitleObject(args.page) or getTitleObject(args['página']) or mw.title.getCurrentTitle()
obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle()


-- Set the config for our box type.
-- Set the config for our box type.
Línea 94: Línea 74:
-- use template from DEMOSPACES
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.find( demospace, 'talk' ) or string.find( demospace, 'Discussão' ) or string.find( demospace, 'discussão' ) then
elseif string.find( demospace, 'talk' ) then
-- demo as a talk page
-- demo as a talk page
obj.cfg = cfg.tmbox
obj.cfg = cfg.tmbox
Línea 146: Línea 126:
end
end
if sort then
if sort then
cat = string.format('[[Categoria:%s|%s]]', cat, sort)
cat = string.format('[[Category:%s|%s]]', cat, sort)
else
else
cat = string.format('[[Categoria:%s]]', cat)
cat = string.format('[[Category:%s]]', cat)
end
end
self.hasCategories = true
self.hasCategories = true
Línea 167: Línea 147:


-- Get type data.
-- Get type data.
self.type = args.type or args.tipo
self.type = args.type
local typeData = cfg.types[self.type]
local typeData = cfg.types[self.type]
self.invalidTypeError = cfg.showInvalidTypeError
self.invalidTypeError = cfg.showInvalidTypeError
Línea 173: Línea 153:
and not typeData
and not typeData
typeData = typeData or cfg.types[cfg.default]
typeData = typeData or cfg.types[cfg.default]
self.typeClass = typeData.class or typeData.classe
self.typeClass = typeData.class
self.typeImage = typeData.image or typeData.imagem
self.typeImage = typeData.image
self.typeImageNeedsLink = typeData.imageNeedsLink


-- Find if the box has been wrongly substituted.
-- Find if the box has been wrongly substituted.
Línea 182: Línea 163:
self.isSmall = cfg.allowSmall and (
self.isSmall = cfg.allowSmall and (
cfg.smallParam and args.small == cfg.smallParam
cfg.smallParam and args.small == cfg.smallParam
or cfg.smallParam and args.small == 'esquerda'
or not cfg.smallParam and yesno(args.small)
or not cfg.smallParam and yesno(args.small)
or cfg.smallParam and args.pequeno == cfg.smallParam
or cfg.smallParam and args.pequeno == 'esquerda'
or not cfg.smallParam and yesno(args.pequeno)
or cfg.smallParam and args.pequena == cfg.smallParam
or cfg.smallParam and args.pequena == 'esquerda'
or not cfg.smallParam and yesno(args.pequena)
)
)


-- Add attributes, classes and styles.
-- Add attributes, classes and styles.
self.id = args.id
self.id = args.id
self.name = args.name or args.nome
self.name = args.name
if self.name then
if self.name then
self:addClass('box-' .. string.gsub(self.name,' ','_'))
self:addClass('box-' .. string.gsub(self.name,' ','_'))
Línea 208: Línea 182:
end
end
self:addClass(self.typeClass)
self:addClass(self.typeClass)
if args.class then
self:addClass(args.class)
self:addClass(args.class)
self.style = args.style
elseif args.classe then
self.attrs = args.attrs
self:addClass(args.classe)
 
end
if args.style then
self.style = args.style
elseif args.estilo then
self.style = args.estilo
end
if args.attrs then
self.attrs = args.attrs
elseif args.atrs then
self.attrs = args.atrs
end
-- Set text style.
-- Set text style.
if args.textstyle then
self.textstyle = args.textstyle
self.textstyle = args.textstyle or args.estilotexto or args['estilo-texto'] or args['estilo_texto']
 
end
-- Find if we are on the template page or not. This functionality is only
-- Find if we are on the template page or not. This functionality is only
-- used if useCollapsibleTextFields is set, or if both cfg.templateCategory
-- used if useCollapsibleTextFields is set, or if both cfg.templateCategory
Línea 240: Línea 200:
local templateName = mw.ustring.match(
local templateName = mw.ustring.match(
self.name,
self.name,
'^[pP][rR][eE][dD][eE][fF][iI][nI][çÇ][ãÃ][oO][%s_]*:[%s_]*(.*)$'
'^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$'
) or self.name
) or self.name
templateName = 'Predefinição:' .. templateName
templateName = 'Template:' .. templateName
self.templateTitle = getTitleObject(templateName)
self.templateTitle = getTitleObject(templateName)
end
end
Línea 253: Línea 213:
if self.useCollapsibleTextFields then
if self.useCollapsibleTextFields then
-- Get the self.issue value.
-- Get the self.issue value.
local textoPequeno = args.smalltext or args.textopequeno or args['texto-pequeno'] or args['texto_pequeno']
if self.isSmall and args.smalltext then
if self.isSmall and textoPequeno then
self.issue = args.smalltext
self.issue = textoPequeno
else
else
local sect
local sect
local seccao = args.sect or args['secção'] or args['seção']
if args.sect == '' then
if seccao == '' then
sect = 'This ' .. (cfg.sectionDefault or 'page')
if cfg.sectionDefault then
elseif type(args.sect) == 'string' then
sect = 'Este ' .. cfg.sectionDefault
sect = 'This ' .. args.sect
else
sect = 'Esta página'
end
elseif type(seccao) == 'string' then
sect = seccao
end
end
local issue = args.issue or args.problema
local issue = args.issue
issue = type(issue) == 'string' and issue ~= '' and issue or nil
issue = type(issue) == 'string' and issue ~= '' and issue or nil
local text = args.text or args.texto
local text = args.text
text = type(text) == 'string' and text or nil
text = type(text) == 'string' and text or nil
local issues = {}
local issues = {}
Línea 280: Línea 234:


-- Get the self.talk value.
-- Get the self.talk value.
local talk = args.talk or args['discussão']
local talk = args.talk
-- Show talk links on the template page or template subpages if the talk
-- Show talk links on the template page or template subpages if the talk
-- parameter is blank.
-- parameter is blank.
Línea 308: Línea 262:
end
end
if talkTitle and talkTitle.exists then
if talkTitle and talkTitle.exists then
local talkText = 'Discussão relevante pode ser encontrada'
                local talkText
if talkArgIsTalkPage then
                if self.isSmall then
talkText = string.format(
                    local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
'%s [[%s|%s]].',
                    talkText = string.format('([[%s|talk]])', talkLink)
talkText,
                else
talk,
                    talkText = 'Relevant discussion may be found on'
talkTitle.prefixedText
                    if talkArgIsTalkPage then
)
                        talkText = string.format(
else
                            '%s [[%s|%s]].',
talkText = string.format(
                            talkText,
'%s na [[%s#%s|página de discussão]].',
                            talk,
talkText,
                            talkTitle.prefixedText
talkTitle.prefixedText,
                        )
talk
                    else
)
                        talkText = string.format(
end
                            '%s the [[%s#%s|talk page]].',
                            talkText,
                            talkTitle.prefixedText,
                            talk
                        )
                    end
                end
self.talk = talkText
self.talk = talkText
end
end
Línea 329: Línea 289:


-- Get other values.
-- Get other values.
self.fix = args.fix ~= '' and args.fix or args.conserto ~= '' and args.conserto or nil  
self.fix = args.fix ~= '' and args.fix or nil
local date
local date
if args.date then
if args.date and args.date ~= '' then
if args.date ~= '' then
date = args.date
date = args.date
elseif args.date == '' and self.isTemplatePage then
elseif args.date == '' and self.isTemplatePage then
date = lang:formatDate('F Y')
date = lang:formatDate('F "de" Y')
end
else
if args.data ~= '' then
date = args.data
elseif args.data == '' and self.isTemplatePage then
date = lang:formatDate('F "de" Y')
end
end
end
if date then
if date then
self.date = string.format(" <small class='date-container'>''(<span class='date'>%s</span>)''</small>", lang:ucfirst(date))
self.date = string.format(" <span class='date-container'><i>(<span class='date'>%s</span>)</i></span>", date)
end
end
self.info = args.info
self.info = args.info
if yesno(args.removalnotice or args['avisoderemoção'] or args['aviso-de-remoção'] or args['aviso_de_remoção'] or args['avisoremoção'] or args['aviso-remoção'] or args['aviso_remoção']) then
if yesno(args.removalnotice) then
self.removalNotice = cfg.removalNotice
self.removalNotice = cfg.removalNotice
end
end
Línea 356: Línea 308:
-- types other than ambox, and also by ambox when small=yes.
-- types other than ambox, and also by ambox when small=yes.
if self.isSmall then
if self.isSmall then
self.text = args.smalltext or args.text or args.textopequeno or args['texto-pequeno'] or args['texto_pequeno'] or args.texto
self.text = args.smalltext or args.text
else
else
self.text = args.text or args.texto
self.text = args.text
end
end


-- Set the below row.
-- Set the below row.
self.below = (cfg.below and args.below) or (cfg.below and args.abaixo)
self.below = cfg.below and args.below


-- General image settings.
-- General image settings.
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageEmptyCell = cfg.imageEmptyCell
self.imageEmptyCell = cfg.imageEmptyCell
if cfg.imageEmptyCellStyle then
self.imageEmptyCellStyle = 'border: none; padding: 0px; width:1px'
end


-- Left image settings.
-- Left image settings.
local imageLeft = (self.isSmall and args.smallimage
local imageLeft = self.isSmall and args.smallimage or args.image
  or self.isSmall and args.imagempequena
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none'
  or self.isSmall and args['imagem-pequena']
or not cfg.imageCheckBlank and imageLeft ~= 'none'
  or self.isSmall and args['imagem_pequena']
  or args.image
  or args.imagem)
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none' and imageLeft ~= 'em branco' and imageLeft ~= 'nenhuma'
  or not cfg.imageCheckBlank and imageLeft ~= 'none' and imageLeft ~= 'nenhuma'
then
then
self.imageLeft = imageLeft
self.imageLeft = imageLeft
Línea 386: Línea 330:
and (cfg.imageSmallSize or '30x30px')
and (cfg.imageSmallSize or '30x30px')
or '40x40px'
or '40x40px'
self.imageLeft = string.format('[[Ficheiro:%s|%s|link=|alt=]]', self.typeImage
self.imageLeft = string.format('[[File:%s|%s%s|alt=]]', self.typeImage
or 'Imbox notice.png', imageSize)
or 'Information icon4.svg', imageSize, self.typeImageNeedsLink and "" or "|link=" )
end
end
end
end


-- Right image settings.
-- Right image settings.
local imageRight = (self.isSmall and args.smallimageright)
local imageRight = self.isSmall and args.smallimageright or args.imageright
or (self.isSmall and args.imagemdireitapequena)
if not (cfg.imageRightNone and imageRight == 'none') then
or (self.isSmall and args['imagem-direita-pequena'])
or (self.isSmall and args['imagem_direita_pequena'])
or args.imageright or args.imagemdireita or args['imagem-direita'] or args['imagem_direita']
if not ((cfg.imageRightNone and imageRight == 'none') or (cfg.imageRightNone and imageRight == 'nenhuma')) then
self.imageRight = imageRight
self.imageRight = imageRight
end
end
-- set templatestyles
self.base_templatestyles = cfg.templatestyles
self.templatestyles = args.templatestyles
end
end


Línea 411: Línea 355:


local nums = {}
local nums = {}
for _, prefix in ipairs{'cat', 'category', 'all', 'categoria', 'todos'} do
for _, prefix in ipairs{'cat', 'category', 'all'} do
args[prefix .. '1'] = args[prefix]
args[prefix .. '1'] = args[prefix]
nums = union(nums, getArgNums(args, prefix))
nums = union(nums, getArgNums(args, prefix))
Línea 417: Línea 361:


-- The following is roughly equivalent to the old {{Ambox/category}}.
-- The following is roughly equivalent to the old {{Ambox/category}}.
local date = args.date or args.data
local date = args.date
date = type(date) == 'string' and date
date = type(date) == 'string' and date
local preposition = 'desde'
local preposition = 'from'
for _, num in ipairs(nums) do
for _, num in ipairs(nums) do
local mainCat = args['cat' .. tostring(num)]
local mainCat = args['cat' .. tostring(num)]
or args['category' .. tostring(num)] or args['categoria' .. tostring(num)]
or args['category' .. tostring(num)]
local allCat = args['all' .. tostring(num)] or args['todos' .. tostring(num)]
local allCat = args['all' .. tostring(num)]
mainCat = type(mainCat) == 'string' and mainCat
mainCat = type(mainCat) == 'string' and mainCat
allCat = type(allCat) == 'string' and allCat
allCat = type(allCat) == 'string' and allCat
if mainCat and date and date ~= '' then
if mainCat and date and date ~= '' then
local catTitle = string.format('%s %s %s', mainCat, preposition, mw.ustring.lower(date))
local catTitle = string.format('%s %s %s', mainCat, preposition, date)
self:addCat(0, catTitle)
self:addCat(0, catTitle)
catTitle = getTitleObject('Categoria:' .. catTitle)
catTitle = getTitleObject('Category:' .. catTitle)
if not catTitle or not catTitle.exists then
if not catTitle or not catTitle.exists then
self:addCat(0, '!Artigos com parâmetro de data inválido em predefinições')
self:addCat(0, 'Articles with invalid date parameter in template')
end
end
elseif mainCat and (not date or date == '') then
elseif mainCat and (not date or date == '') then
Línea 487: Línea 431:
-- Set categories for all namespaces.
-- Set categories for all namespaces.
if self.invalidTypeError then
if self.invalidTypeError then
local allSort = (self.title.namespace == 0 and 'Principal:' or '') .. self.title.prefixedText
local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText
self:addCat('all', '!Parâmetro de message box que precisa de conserto', allSort)
self:addCat('all', 'Wikipedia message box parameter needs fixing', allSort)
end
end
if self.isSubstituted then
if self.isSubstituted then
self:addCat('all', '!Páginas com predefinições substituídas incorretamente')
self:addCat('all', 'Pages with incorrectly substituted templates')
end
end
end
end
Línea 513: Línea 457:
-- Convert category tables to strings and pass them through
-- Convert category tables to strings and pass them through
-- [[Module:Category handler]].
-- [[Module:Category handler]].
return require('Módulo:Category handler')._main{
return require('Module:Category handler')._main{
main = table.concat(self.categories[0] or {}),
main = table.concat(self.categories[0] or {}),
template = table.concat(self.categories[10] or {}),
template = table.concat(self.categories[10] or {}),
all = table.concat(self.categories.all or self.categories.todos or {}),
all = table.concat(self.categories.all or {}),
nocat = self.args.nocat or self.args.semcat,
nocat = self.args.nocat,
page = self.args.page or self.args['página']
page = self.args.page
}
}
end
end
Línea 524: Línea 468:
function MessageBox:export()
function MessageBox:export()
local root = mw.html.create()
local root = mw.html.create()
root:wikitext(mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Ambox/styles.css'}))


-- Add the subst check error.
-- Add the subst check error.
Línea 531: Línea 474:
:addClass('error')
:addClass('error')
:wikitext(string.format(
:wikitext(string.format(
'Predefinição <code>%s[[Predefinição:%s|%s]]%s</code> foi substituída incorretamente.',
'Template <code>%s[[Template:%s|%s]]%s</code> has been incorrectly substituted.',
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')
))
))
end
local frame = mw.getCurrentFrame()
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = self.base_templatestyles },
})
-- Add support for a single custom templatestyles sheet. Undocumented as
-- need should be limited and many templates using mbox are substed; we
-- don't want to spread templatestyles sheets around to arbitrary places
if self.templatestyles then
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = self.templatestyles },
})
end
end


Línea 559: Línea 517:
-- image width to 52px. If any images in a div are wider than that,
-- image width to 52px. If any images in a div are wider than that,
-- they may overlap with the text or cause other display problems.
-- they may overlap with the text or cause other display problems.
imageLeftCell = imageLeftCell:tag('div'):css('width', '52px')
imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div')
end
end
imageLeftCell:wikitext(self.imageLeft or nil)
imageLeftCell:wikitext(self.imageLeft or nil)
Línea 569: Línea 527:
row:tag('td')
row:tag('td')
:addClass('mbox-empty-cell')
:addClass('mbox-empty-cell')
:cssText(self.imageEmptyCellStyle or nil)
end
end


Línea 582: Línea 539:
:addClass('mbox-text-span')
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
:wikitext(self.issue or nil)
if (self.talk or self.fix) and not self.isSmall then
if (self.talk or self.fix) then
textCellDiv:tag('span')
textCellDiv:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
Línea 596: Línea 553:
end
end
if self.removalNotice then
if self.removalNotice then
textCellDiv:tag('small')
textCellDiv:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:tag('i')
:tag('i')
Línea 614: Línea 571:
-- If we are using a div, redefine imageRightCell so that the image
-- If we are using a div, redefine imageRightCell so that the image
-- is inside it.
-- is inside it.
imageRightCell = imageRightCell:tag('div'):css('width', '52px')
imageRightCell = imageRightCell:tag('div'):addClass('mbox-image-div')
end
end
imageRightCell
imageRightCell
Línea 633: Línea 590:
if self.invalidTypeError then
if self.invalidTypeError then
root:tag('div')
root:tag('div')
:css('text-align', 'center')
:addClass('mbox-invalid-type')
:wikitext(string.format(
:wikitext(string.format(
'Esta message box está a utilizar um parâmetro "type=%s" inválido e necessita de conserto.',
'This message box is using an invalid "type=%s" parameter and needs fixing.',
self.type or ''
self.type or ''
))
))
Línea 669: Línea 626:
return function (frame)
return function (frame)
if not getArgs then
if not getArgs then
getArgs = require('Módulo:Arguments').getArgs
getArgs = require('Module:Arguments').getArgs
end
end
return t.main(k, getArgs(frame, {trim = false, removeBlanks = false}))
return t.main(k, getArgs(frame, {trim = false, removeBlanks = false}))
MediaWiki spam blocked by CleanTalk.