5275
ediciones
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: | ||
require('strict') | |||
require(' | |||
local getArgs | local getArgs | ||
local yesno = require(' | local yesno = require('Module:Yesno') | ||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
local CONFIG_MODULE = 'Module:Message box/configuration' | |||
local CONFIG_MODULE = ' | local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'} | ||
local DEMOSPACES = { | |||
} | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
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 | 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 | 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('[[ | cat = string.format('[[Category:%s|%s]]', cat, sort) | ||
else | else | ||
cat = string.format('[[ | 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 | 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 | self.typeClass = typeData.class | ||
self.typeImage = typeData.image | 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 not cfg.smallParam and yesno(args.small) | or not cfg.smallParam and yesno(args.small) | ||
) | ) | ||
-- 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 | ||
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) | ||
self:addClass(args.class) | |||
self.style = args.style | |||
self.attrs = args.attrs | |||
-- Set text style. | -- Set text style. | ||
self.textstyle = args.textstyle | |||
-- 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, | ||
'^[ | '^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$' | ||
) or self.name | ) or self.name | ||
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. | ||
if self.isSmall and args.smalltext then | |||
if self.isSmall and | self.issue = args.smalltext | ||
self.issue = | |||
else | else | ||
local sect | local sect | ||
if args.sect == '' then | |||
sect = 'This ' .. (cfg.sectionDefault or 'page') | |||
elseif type(args.sect) == 'string' then | |||
sect = 'This ' .. args.sect | |||
elseif type( | |||
sect = | |||
end | end | ||
local issue = args.issue | 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 | 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 | 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 | |||
if self.isSmall then | |||
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk) | |||
talkText = string.format('([[%s|talk]])', talkLink) | |||
else | |||
talkText = 'Relevant discussion may be found on' | |||
if talkArgIsTalkPage then | |||
talkText = string.format( | |||
'%s [[%s|%s]].', | |||
talkText, | |||
talk, | |||
talkTitle.prefixedText | |||
) | |||
else | |||
talkText = string.format( | |||
'%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 | self.fix = args.fix ~= '' and args.fix or nil | ||
local date | local date | ||
if args.date | if args.date and args.date ~= '' then | ||
date = args.date | |||
elseif args.date == '' and self.isTemplatePage then | |||
date = lang:formatDate('F Y') | |||
end | end | ||
if date then | if date then | ||
self.date = string.format(" < | 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 | 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 | self.text = args.smalltext or args.text | ||
else | else | ||
self.text = args.text | self.text = args.text | ||
end | end | ||
-- Set the below row. | -- Set the below row. | ||
self.below = | 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 | ||
-- Left image settings. | -- Left image settings. | ||
local imageLeft = | local imageLeft = self.isSmall and args.smallimage or args.image | ||
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none' | |||
or not cfg.imageCheckBlank and imageLeft ~= 'none' | |||
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none | |||
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('[[ | self.imageLeft = string.format('[[File:%s|%s%s|alt=]]', self.typeImage | ||
or ' | or 'Information icon4.svg', imageSize, self.typeImageNeedsLink and "" or "|link=" ) | ||
end | end | ||
end | end | ||
-- Right image settings. | -- Right image settings. | ||
local imageRight = | local imageRight = self.isSmall and args.smallimageright or args.imageright | ||
if not (cfg.imageRightNone and imageRight == 'none') then | |||
if not | |||
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 | 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 | local date = args.date | ||
date = type(date) == 'string' and date | date = type(date) == 'string' and date | ||
local preposition = ' | 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 | or args['category' .. tostring(num)] | ||
local allCat = args['all | 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, | local catTitle = string.format('%s %s %s', mainCat, preposition, date) | ||
self:addCat(0, catTitle) | self:addCat(0, catTitle) | ||
catTitle = getTitleObject(' | catTitle = getTitleObject('Category:' .. catTitle) | ||
if not catTitle or not catTitle.exists then | if not catTitle or not catTitle.exists then | ||
self:addCat(0, ' | 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 ' | local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText | ||
self:addCat('all', ' | self:addCat('all', 'Wikipedia message box parameter needs fixing', allSort) | ||
end | end | ||
if self.isSubstituted then | if self.isSubstituted then | ||
self:addCat('all', ' | 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(' | 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 | all = table.concat(self.categories.all or {}), | ||
nocat = self.args.nocat | nocat = self.args.nocat, | ||
page = self.args.page | 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() | ||
-- 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( | ||
' | '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'): | 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') | ||
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) | 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(' | 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'): | 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') | ||
: | :addClass('mbox-invalid-type') | ||
:wikitext(string.format( | :wikitext(string.format( | ||
' | '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(' | 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})) |