Spring til indhold

Modul:Message box: Forskelle mellem versioner

1.029 bytes fjernet ,  25. januar 2021
m
1 version importeret
MartinusWiki>Steenth
(tilpasning / oversættelse)
 
m (1 version importeret)
 
(2 mellemliggende versioner af den samme bruger vises ikke)
Linje 12: Linje 12:
-- Define constants
-- Define constants
local CONFIG_MODULE = 'Module:Message box/configuration'
local CONFIG_MODULE = 'Module:Message box/configuration'
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}
local templatestyles = 'Module:Message box/styles.css'


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Linje 77: Linje 74:
local ns = obj.title.namespace
local ns = obj.title.namespace
-- boxType is "mbox" or invalid input
-- boxType is "mbox" or invalid input
if args.demospace and args.demospace ~= '' then
if ns == 0 then
-- implement demospace parameter of mbox
local demospace = string.lower(args.demospace)
if DEMOSPACES[demospace] then
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.find( demospace, 'talk' ) then
-- demo as a talk page
obj.cfg = cfg.tmbox
else
-- default to ombox
obj.cfg = cfg.ombox
end
elseif ns == 0 then
obj.cfg = cfg.ambox -- main namespace
obj.cfg = cfg.ambox -- main namespace
elseif ns == 6 then
elseif ns == 6 then
Linje 176: Linje 160:
-- Add attributes, classes and styles.
-- Add attributes, classes and styles.
self.id = args.id
self.id = args.id
self.name = args.name
if self.name then
self:addClass('box-' .. string.gsub(self.name,' ','_'))
end
if yesno(args.plainlinks) ~= false then
if yesno(args.plainlinks) ~= false then
self:addClass('plainlinks')
self:addClass('plainlinks')
Linje 205: Linje 185:
and cfg.templateCategoryRequireName
and cfg.templateCategoryRequireName
then
then
self.name = args.name
if self.name then
if self.name then
local templateName = mw.ustring.match(
local templateName = mw.ustring.match(
Linje 216: Linje 197:
and mw.title.equals(self.title, self.templateTitle)
and mw.title.equals(self.title, self.templateTitle)
end
end
 
-- Process data for collapsible text fields. At the moment these are only
-- Process data for collapsible text fields. At the moment these are only
-- used in {{ambox}}.
-- used in {{ambox}}.
Linje 226: Linje 207:
local sect
local sect
if args.sect == '' then
if args.sect == '' then
sect = 'Denne ' .. (cfg.sectionDefault or 'side')
sect = 'This ' .. (cfg.sectionDefault or 'page')
elseif type(args.sect) == 'string' then
elseif type(args.sect) == 'string' then
sect = 'Dette ' .. args.sect
sect = 'This ' .. args.sect
end
end
local issue = args.issue
local issue = args.issue
Linje 270: Linje 251:
end
end
if talkTitle and talkTitle.exists then
if talkTitle and talkTitle.exists then
local talkText = 'Begrundelsen kan findes på'
local talkText = 'Relevant discussion may be found on'
if talkArgIsTalkPage then
if talkArgIsTalkPage then
talkText = string.format(
talkText = string.format(
'%s [[%s|%s]] eller i artikelhistorikken.',
'%s [[%s|%s]].',
talkText,
talkText,
talk,
talk,
Linje 280: Linje 261:
else
else
talkText = string.format(
talkText = string.format(
'%s [[%s#%s|diskussionssiden]] eller i artikelhistorikken.',
'%s the [[%s#%s|talk page]].',
talkText,
talkText,
talkTitle.prefixedText,
talkTitle.prefixedText,
Linje 299: Linje 280:
end
end
if date then
if date then
self.date = string.format(" <small class='date-container'>''(<span class='date'>%s</span>)''</small>", date)
self.date = string.format(" <small>''(%s)''</small>", date)
end
end
self.info = args.info
self.info = args.info
Linje 364: Linje 345:
local date = args.date
local date = args.date
date = type(date) == 'string' and date
date = type(date) == 'string' and date
local preposition = 'siden'
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)]
Linje 376: Linje 357:
catTitle = getTitleObject('Category:' .. catTitle)
catTitle = getTitleObject('Category:' .. catTitle)
if not catTitle or not catTitle.exists then
if not catTitle or not catTitle.exists then
self:addCat(0, 'Artikler med ugyldig datoparameter i skabelon')
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
Linje 595: Linje 576:


local p, mt = {}, {}
local p, mt = {}, {}
local frame_from_invoke


function p._exportClasses()
function p._exportClasses()
Linje 605: Linje 585:


function p.main(boxType, args, cfgTables)
function p.main(boxType, args, cfgTables)
if not frame_from_invoke then
frame_from_invoke = mw.getCurrentFrame()
end
local tstyles = frame_from_invoke:extensionTag{ name = 'templatestyles', args = { src = templatestyles} }
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData(CONFIG_MODULE))
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData(CONFIG_MODULE))
box:setParameters()
box:setParameters()
box:setCategories()
box:setCategories()
return box:export() .. tstyles
return box:export()
end
end


function mt.__index(t, k)
function mt.__index(t, k)
return function (frame)
return function (frame)
frame_from_invoke = frame
if not getArgs then
if not getArgs then
getArgs = require('Module:Arguments').getArgs
getArgs = require('Module:Arguments').getArgs