Edición de «Módulo:Message box»
Puedes deshacer la edición. Antes de deshacer la edición, comprueba la siguiente comparación para verificar que realmente es lo que quieres hacer, y entonces publica los cambios para así efectuar la reversión.
Revisión actual | Tu texto | ||
Línea 1: | Línea 1: | ||
require(' | -- This is a meta-module for producing message box templates, including | ||
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}. | |||
-- Load necessary modules. | |||
require('Módulo:No globals') | |||
local getArgs | local getArgs | ||
local yesno = require(' | local yesno = require('Módulo:Yesno') | ||
-- Get a language object for formatDate and ucfirst. | |||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
local CONFIG_MODULE = ' | -- Define constants | ||
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'} | local CONFIG_MODULE = 'Módulo:Message box/configuration' | ||
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 61: | Línea 81: | ||
-- Set the title object and the namespace. | -- Set the title object and the namespace. | ||
obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle() | obj.title = getTitleObject(args.page) or getTitleObject(args['página']) or mw.title.getCurrentTitle() | ||
-- Set the config for our box type. | -- Set the config for our box type. | ||
Línea 74: | Línea 94: | ||
-- use template from DEMOSPACES | -- use template from DEMOSPACES | ||
obj.cfg = cfg[DEMOSPACES[demospace]] | obj.cfg = cfg[DEMOSPACES[demospace]] | ||
elseif string.find( demospace, 'talk' ) then | elseif string.find( demospace, 'talk' ) or string.find( demospace, 'Discussão' ) or string.find( demospace, 'discussão' ) then | ||
-- demo as a talk page | -- demo as a talk page | ||
obj.cfg = cfg.tmbox | obj.cfg = cfg.tmbox | ||
Línea 126: | Línea 146: | ||
end | end | ||
if sort then | if sort then | ||
cat = string.format('[[ | cat = string.format('[[Categoria:%s|%s]]', cat, sort) | ||
else | else | ||
cat = string.format('[[ | cat = string.format('[[Categoria:%s]]', cat) | ||
end | end | ||
self.hasCategories = true | self.hasCategories = true | ||
Línea 147: | Línea 167: | ||
-- Get type data. | -- Get type data. | ||
self.type = args.type | self.type = args.type or args.tipo | ||
local typeData = cfg.types[self.type] | local typeData = cfg.types[self.type] | ||
self.invalidTypeError = cfg.showInvalidTypeError | self.invalidTypeError = cfg.showInvalidTypeError | ||
Línea 153: | Línea 173: | ||
and not typeData | and not typeData | ||
typeData = typeData or cfg.types[cfg.default] | typeData = typeData or cfg.types[cfg.default] | ||
self.typeClass = typeData.class | self.typeClass = typeData.class or typeData.classe | ||
self.typeImage = typeData.image | self.typeImage = typeData.image or typeData.imagem | ||
-- Find if the box has been wrongly substituted. | -- Find if the box has been wrongly substituted. | ||
Línea 163: | Línea 182: | ||
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 | self.name = args.name or args.nome | ||
if self.name then | if self.name then | ||
self:addClass('box-' .. string.gsub(self.name,' ','_')) | self:addClass('box-' .. string.gsub(self.name,' ','_')) | ||
Línea 182: | Línea 208: | ||
end | end | ||
self:addClass(self.typeClass) | self:addClass(self.typeClass) | ||
self:addClass(args.class) | if args.class then | ||
self.style = args.style | self:addClass(args.class) | ||
self.attrs = args.attrs | elseif args.classe then | ||
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. | ||
self.textstyle = args.textstyle | if args.textstyle then | ||
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 200: | Línea 240: | ||
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_]*(.*)$' | ||
) or self.name | ) or self.name | ||
templateName = ' | templateName = 'Predefinição:' .. templateName | ||
self.templateTitle = getTitleObject(templateName) | self.templateTitle = getTitleObject(templateName) | ||
end | end | ||
Línea 213: | Línea 253: | ||
if self.useCollapsibleTextFields then | if self.useCollapsibleTextFields then | ||
-- Get the self.issue value. | -- Get the self.issue value. | ||
if self.isSmall and | local textoPequeno = args.smalltext or args.textopequeno or args['texto-pequeno'] or args['texto_pequeno'] | ||
self.issue = | if self.isSmall and textoPequeno then | ||
self.issue = textoPequeno | |||
else | else | ||
local sect | local sect | ||
local seccao = args.sect or args['secção'] or args['seção'] | |||
sect = ' | if seccao == '' then | ||
elseif type( | if cfg.sectionDefault then | ||
sect = | sect = 'Este ' .. cfg.sectionDefault | ||
else | |||
sect = 'Esta página' | |||
end | |||
elseif type(seccao) == 'string' then | |||
sect = seccao | |||
end | end | ||
local issue = args.issue | local issue = args.issue or args.problema | ||
issue = type(issue) == 'string' and issue ~= '' and issue or nil | issue = type(issue) == 'string' and issue ~= '' and issue or nil | ||
local text = args.text | local text = args.text or args.texto | ||
text = type(text) == 'string' and text or nil | text = type(text) == 'string' and text or nil | ||
local issues = {} | local issues = {} | ||
Línea 234: | Línea 280: | ||
-- Get the self.talk value. | -- Get the self.talk value. | ||
local talk = args.talk | local talk = args.talk or args['discussão'] | ||
-- 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 262: | Línea 308: | ||
end | end | ||
if talkTitle and talkTitle.exists then | if talkTitle and talkTitle.exists then | ||
local talkText = 'Discussão relevante pode ser encontrada' | |||
if talkArgIsTalkPage then | |||
talkText = string.format( | |||
'%s [[%s|%s]].', | |||
talkText, | |||
talk, | |||
talkTitle.prefixedText | |||
) | |||
else | |||
talkText = string.format( | |||
'%s na [[%s#%s|página de discussão]].', | |||
talkText, | |||
talkTitle.prefixedText, | |||
talk | |||
) | |||
end | |||
self.talk = talkText | self.talk = talkText | ||
end | end | ||
Línea 289: | Línea 329: | ||
-- Get other values. | -- Get other values. | ||
self.fix = args.fix ~= '' and args.fix or nil | self.fix = args.fix ~= '' and args.fix or args.conserto ~= '' and args.conserto or nil | ||
local date | local date | ||
if args.date | if args.date then | ||
if args.date ~= '' then | |||
date = args.date | |||
date = lang:formatDate('F Y') | elseif args.date == '' and self.isTemplatePage then | ||
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(" < | self.date = string.format(" <small class='date-container'>''(<span class='date'>%s</span>)''</small>", lang:ucfirst(date)) | ||
end | end | ||
self.info = args.info | self.info = args.info | ||
if yesno(args.removalnotice) then | 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 | ||
self.removalNotice = cfg.removalNotice | self.removalNotice = cfg.removalNotice | ||
end | end | ||
Línea 308: | Línea 356: | ||
-- 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 | self.text = args.smalltext or args.text or args.textopequeno or args['texto-pequeno'] or args['texto_pequeno'] or args.texto | ||
else | else | ||
self.text = args.text | self.text = args.text or args.texto | ||
end | end | ||
-- Set the below row. | -- Set the below row. | ||
self.below = cfg.below and args.below | self.below = (cfg.below and args.below) or (cfg.below and args.abaixo) | ||
-- 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 or args.image | local imageLeft = (self.isSmall and args.smallimage | ||
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none' | or self.isSmall and args.imagempequena | ||
or self.isSmall and args['imagem-pequena'] | |||
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 330: | Línea 386: | ||
and (cfg.imageSmallSize or '30x30px') | and (cfg.imageSmallSize or '30x30px') | ||
or '40x40px' | or '40x40px' | ||
self.imageLeft = string.format('[[ | self.imageLeft = string.format('[[Ficheiro:%s|%s|link=|alt=]]', self.typeImage | ||
or ' | or 'Imbox notice.png', imageSize) | ||
end | end | ||
end | end | ||
-- Right image settings. | -- Right image settings. | ||
local imageRight = self.isSmall and args.smallimageright or args.imageright | local imageRight = (self.isSmall and args.smallimageright) | ||
if not (cfg.imageRightNone and imageRight == 'none') then | or (self.isSmall and args.imagemdireitapequena) | ||
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 | ||
end | end | ||
Línea 355: | Línea 411: | ||
local nums = {} | local nums = {} | ||
for _, prefix in ipairs{'cat', 'category', 'all'} do | for _, prefix in ipairs{'cat', 'category', 'all', 'categoria', 'todos'} 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 361: | Línea 417: | ||
-- The following is roughly equivalent to the old {{Ambox/category}}. | -- The following is roughly equivalent to the old {{Ambox/category}}. | ||
local date = args.date | local date = args.date or args.data | ||
date = type(date) == 'string' and date | date = type(date) == 'string' and date | ||
local preposition = ' | local preposition = 'desde' | ||
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['category' .. tostring(num)] or args['categoria' .. tostring(num)] | ||
local allCat = args['all' .. tostring(num)] | local allCat = args['all' .. tostring(num)] or args['todos' .. 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, date) | local catTitle = string.format('%s %s %s', mainCat, preposition, mw.ustring.lower(date)) | ||
self:addCat(0, catTitle) | self:addCat(0, catTitle) | ||
catTitle = getTitleObject(' | catTitle = getTitleObject('Categoria:' .. catTitle) | ||
if not catTitle or not catTitle.exists then | if not catTitle or not catTitle.exists then | ||
self:addCat(0, ' | self:addCat(0, '!Artigos com parâmetro de data inválido em predefinições') | ||
end | end | ||
elseif mainCat and (not date or date == '') then | elseif mainCat and (not date or date == '') then | ||
Línea 431: | Línea 487: | ||
-- 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 ' | local allSort = (self.title.namespace == 0 and 'Principal:' or '') .. self.title.prefixedText | ||
self:addCat('all', ' | self:addCat('all', '!Parâmetro de message box que precisa de conserto', allSort) | ||
end | end | ||
if self.isSubstituted then | if self.isSubstituted then | ||
self:addCat('all', ' | self:addCat('all', '!Páginas com predefinições substituídas incorretamente') | ||
end | end | ||
end | end | ||
Línea 457: | Línea 513: | ||
-- 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(' | return require('Módulo: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 {}), | all = table.concat(self.categories.all or self.categories.todos or {}), | ||
nocat = self.args.nocat, | nocat = self.args.nocat or self.args.semcat, | ||
page = self.args.page | page = self.args.page or self.args['página'] | ||
} | } | ||
end | end | ||
Línea 468: | Línea 524: | ||
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 474: | Línea 531: | ||
:addClass('error') | :addClass('error') | ||
:wikitext(string.format( | :wikitext(string.format( | ||
' | 'Predefinição <code>%s[[Predefinição:%s|%s]]%s</code> foi substituída incorretamente.', | ||
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | ||
)) | )) | ||
end | end | ||
Línea 517: | Línea 559: | ||
-- 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'): | imageLeftCell = imageLeftCell:tag('div'):css('width', '52px') | ||
end | end | ||
imageLeftCell:wikitext(self.imageLeft or nil) | imageLeftCell:wikitext(self.imageLeft or nil) | ||
Línea 527: | Línea 569: | ||
row:tag('td') | row:tag('td') | ||
:addClass('mbox-empty-cell') | :addClass('mbox-empty-cell') | ||
:cssText(self.imageEmptyCellStyle or nil) | |||
end | end | ||
Línea 539: | Línea 582: | ||
:addClass('mbox-text-span') | :addClass('mbox-text-span') | ||
:wikitext(self.issue or nil) | :wikitext(self.issue or nil) | ||
if (self.talk or self.fix) then | if (self.talk or self.fix) and not self.isSmall then | ||
textCellDiv:tag('span') | textCellDiv:tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
Línea 553: | Línea 596: | ||
end | end | ||
if self.removalNotice then | if self.removalNotice then | ||
textCellDiv:tag(' | textCellDiv:tag('small') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:tag('i') | :tag('i') | ||
Línea 571: | Línea 614: | ||
-- 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'): | imageRightCell = imageRightCell:tag('div'):css('width', '52px') | ||
end | end | ||
imageRightCell | imageRightCell | ||
Línea 590: | Línea 633: | ||
if self.invalidTypeError then | if self.invalidTypeError then | ||
root:tag('div') | root:tag('div') | ||
: | :css('text-align', 'center') | ||
:wikitext(string.format( | :wikitext(string.format( | ||
' | 'Esta message box está a utilizar um parâmetro "type=%s" inválido e necessita de conserto.', | ||
self.type or '' | self.type or '' | ||
)) | )) | ||
Línea 626: | Línea 669: | ||
return function (frame) | return function (frame) | ||
if not getArgs then | if not getArgs then | ||
getArgs = require(' | getArgs = require('Módulo:Arguments').getArgs | ||
end | end | ||
return t.main(k, getArgs(frame, {trim = false, removeBlanks = false})) | return t.main(k, getArgs(frame, {trim = false, removeBlanks = false})) |