「模組:Infobox military conflict」:修訂間差異

移除 395 位元組 、​ 2024年8月2日 (星期五)
無編輯摘要
imported>Migertile CL
無編輯摘要
無編輯摘要
 
第8行: 第8行:


function IMC:renderPerCombatant(builder, headerText, prefix, suffix)
function IMC:renderPerCombatant(builder, headerText, prefix, suffix)
prefix = prefix or ''
prefix = prefix or ''
suffix = suffix or ''
suffix = sufix or ''
local colspans = {}
local colspans = {}
 
-- This may result in colspans[1] getting set twice, but
-- This may result in colspans[1] getting set twice, but
-- this is no big deal. The second set will be correct.
-- this is no big deal. The second set will be correct.
local lastCombatant = 1
local lastCombatant = 1
 
for i = 1,self.combatants do
for i = 1,self.combatants do
if self.args[prefix .. i .. suffix] then
if self.args[prefix .. i .. suffix] then
colspans[lastCombatant] = i - lastCombatant
colspans[lastCombatant] = i - lastCombatant
lastCombatant = i
lastCombatant = i
end
end
end
end
 
local jointText = self.args[prefix .. (self.combatants + 1) .. suffix]


local jointText = self.args[prefix .. (self.combatants + 1) .. suffix]
if headerText and (colspans[1] or jointText) then
builder:tag('tr')
if headerText and (colspans[1] or jointText) then
:tag('th')
builder:tag('tr')
:attr('colspan', self.combatants)
:tag('th')
:cssText(infoboxStyle.header_raw)
:attr('colspan', self.combatants)
:wikitext(headerText)
:cssText(infoboxStyle.header_raw)
end
:wikitext(headerText)
end


-- The only time colspans[1] wouldn't be set is if no
-- The only time colspans[1] wouldn't be set is if no
第61行: 第61行:
end
end


if jointText then
if jointText then
builder:tag('tr')
builder:tag('tr')
:tag('td')
:tag('td')
:attr('colspan', self.combatants)
:attr('colspan', self.combatants)
:css('text-align', 'center')
:css('text-align', 'center')
-- don't show the border if we're directly under a header
-- don't show the border if we're directly under a header
                :css('border-top', (not headerText or colspans[1]) and infoboxStyle.internal_border or nil)
:css('border-top', (not headerText or colspans[1]) and infoboxStyle.internal_border or nil)
                :css('font-size', '90%') -- 中文维基添加
:css('font-size', '90%') -- 中文維基添加
:newline()
:newline()
:wikitext(jointText)
:wikitext(jointText)
end
end
end
end


function IMC:renderHeaderTable(builder)
function IMC:renderHeaderTable(builder)
    builder = builder:tag('table')
builder = builder:tag('table')
        :cssText(infoboxStyle.box_label) -- 中文维基添加
:cssText(infoboxStyle.box_label) -- 中文維基添加
        :css('width', '100%')
:css('width', '100%')
:css('margin', 0)
:css('margin', 0)
:css('padding', 0)
:css('padding', 0)
:css('border', 0)
:css('border', 0)


if self.args.date then
if self.args.date then
builder:tag('tr')
builder:tag('tr')
:tag('th')
:tag('th')
:css('padding-right', '1em')
:css('padding-right', '1em')
                :css('white-space', 'nowrap')
:css('white-space', 'nowrap')
:wikitext('日期')
:wikitext('日期')
:done()
:done()
:tag('td')
:tag('td')
:wikitext(self.args.date)
:wikitext(self.args.date)
end
end


builder = builder:tag('tr')
builder = builder:tag('tr')
:tag('th')
:tag('th')
:css('padding-right', '1em')
:css('padding-right', '1em')
            :css('white-space', 'nowrap')
:css('white-space', 'nowrap')
:wikitext('地點')
:wikitext('地點')
:done()
:done()
:tag('td')
:tag('td')
:tag('div')
:tag('div')
:addClass('location')
:addClass('location')
:wikitext(self.args.place or '{{{place}}}') -- hack so that people who don't know Lua know that this parameter is required
:wikitext(self.args.place or '{{{place}}}') -- hack so that people who don't know Lua know that this parameter is required
:done()
:done()
if self.args.coordinates then
if self.args.coordinates then
builder:wikitext(self.args.coordinates)
builder:wikitext(self.args.coordinates)
end
end
builder = builder:done():done()
builder = builder:done():done()


-- only for "Putsch"
-- only for "Putsch"
    if self.args.action then
if self.args.action then
builder:tag('tr')
builder:tag('tr')
:tag('th')
:tag('th')
:css('padding-right', '1em')
:css('padding-right', '1em')
                :css('white-space', 'nowrap')
:css('white-space', 'nowrap')
:wikitext(self.args.action and '行動')
:wikitext(self.args.action and '行動')
:done()
:done()
:tag('td')
:tag('td')
:wikitext(self.args.action)
:wikitext(self.args.action)
end
end


if self.args.status or self.args.result then
if self.args.status or self.args.result then
builder:tag('tr')
builder:tag('tr')
:tag('th')
:tag('th')
:css('padding-right', '1em')
:css('padding-right', '1em')
                :css('white-space', 'nowrap')
:css('white-space', 'nowrap')
:wikitext(self.args.status and '狀態' or '結果')
:wikitext(self.args.status and '狀態' or '結果')
:done()
:done()
:tag('td')
:tag('td')
                                :addClass('status')
:addClass('status')
:newline()
:newline()
:wikitext(self.args.status or self.args.result)
:wikitext(self.args.status or self.args.result)
end
end


if self.args.territory then
if self.args.territory then
builder:tag('tr')
builder:tag('tr')
:tag('th')
:tag('th')
:css('padding-right', '1em')
:css('padding-right', '1em')
                :css('white-space', 'nowrap')
:css('white-space', 'nowrap')
:wikitext('領土變更')
:wikitext('領土變更')
:done()
:done()
:tag('td')
:tag('td')
:newline()
:newline()
:wikitext(self.args.territory)
:wikitext(self.args.territory)
end
end
end
end


function IMC:render()
function IMC:render()
local builder = mw.html.create()
local builder = mw.html.create()
if self.args.campaignbox then
if self.args.campaignbox then
-- this should be the same as using {{stack|clear=right|...}}
-- this should be the same as using {{stack|clear=right|...}}
builder:wikitext(self.frame:expandTemplate{ title = 'stack begin', args = { clear='true'} })
builder:wikitext(self.frame:expandTemplate{ title = 'stack begin', args = { clear='true'} })
end
end
builder = builder:tag('table')
builder = builder:tag('table')
:addClass('infobox vevent')
:addClass('infobox vevent')
:cssText(infoboxStyle.main_box_raw)
:cssText(infoboxStyle.main_box_raw)
:css('width', self.args.width or nil)
:css('width', self.args.width or nil)


builder:tag('tr')
:tag('th')
:addClass('summary')
:attr('colspan', self.combatants)
:cssText(infoboxStyle.header_raw .. 'font-size:100%') -- 中文维基修改
:wikitext(self.args.conflict or mw.title.getCurrentTitle().text)
builder:tag('tr')
builder:tag('tr')
:tag('th')
:tag('th')
第171行: 第177行:
:wikitext(self.args.partof .. '的一部分')
:wikitext(self.args.partof .. '的一部分')
end
end
if self.args.image or self.args['image-hans'] or self.args['image-hant'] then
if self.args.image or self.args['image-hans'] or self.args['image-hant'] then
builder:tag('tr')
builder:tag('tr')
:tag('td')
:tag('td')
:attr('colspan', self.combatants)
:attr('colspan', self.combatants)
:cssText(infoboxStyle.image_box_raw)
:cssText(infoboxStyle.image_box_raw)
:wikitext(string.format('%s%s%s',
:wikitext(string.format('%s%s%s',
require('Module:InfoboxImageVariant')._main{
require('Module:InfoboxImageVariant')._main{
image = self.args.image,
image = self.args.image,
['image-hans'] = self.args['image-hans'],
['image-hans'] = self.args['image-hans'],
['image-hant'] = self.args['image-hant'],
['image-hant'] = self.args['image-hant'],
size = self.args.image_size,
size = self.args.image_size,
sizedefault = 'frameless',
sizedefault = 'frameless',
upright = 1,
upright = 1,
alt = self.args.alt,
alt = self.args.alt,
['alt-hans'] = self.args['alt-hans'],
['alt-hans'] = self.args['alt-hans'],
['alt-hant'] = self.args['alt-hant'],
['alt-hant'] = self.args['alt-hant'],


},
},
第192行: 第198行:
self.args.caption or ''
self.args.caption or ''
))
))
end
end
self:renderHeaderTable(builder:tag('tr'):tag('td'):attr('colspan', self.combatants))
self:renderHeaderTable(builder:tag('tr'):tag('td'):attr('colspan', self.combatants))
self:renderPerCombatant(builder, self.args.combatants_header or '参战方', 'combatant')
self:renderPerCombatant(builder, self.args.combatants_header or '參戰方', 'combatant')
-- can be un-hardcoded once gerrit:165108 is merged
-- can be un-hardcoded once gerrit:165108 is merged
for _,v in ipairs{'a','b','c','d'} do
for _,v in ipairs{'a','b','c','d'} do
self:renderPerCombatant(builder, nil, 'combatant', v)
self:renderPerCombatant(builder, nil, 'combatant', v)
end
end
 
self:renderPerCombatant(builder, '指揮官', 'commander')
self:renderPerCombatant(builder, '指揮官與領導者', 'commander')
        for _,v in ipairs{'a','b','c','d'} do
for _,v in ipairs{'a','b','c','d'} do
self:renderPerCombatant(builder, nil, 'commander', v)
self:renderPerCombatant(builder, nil, 'commander', v)
end
end


self:renderPerCombatant(builder, '參戰單位', 'units')
self:renderPerCombatant(builder, '參戰單位', 'units')
self:renderPerCombatant(builder, '兵力', 'strength')
self:renderPerCombatant(builder, '兵力', 'strength')
self:renderPerCombatant(builder, '政治支持', 'polstrength')
self:renderPerCombatant(builder, '政治支持', 'polstrength')
self:renderPerCombatant(builder, '軍事支援', 'milstrength')
self:renderPerCombatant(builder, '軍事支援', 'milstrength')
self:renderPerCombatant(builder, '傷亡與損失', 'casualties')
self:renderPerCombatant(builder, '傷亡與損失', 'casualties')


if self.args.notes then
if self.args.notes then
builder:tag('tr')
builder:tag('tr')
:tag('td')
:tag('td')
:attr('colspan', self.combatants)
:attr('colspan', self.combatants)
-- :css('font-size', '90%') 中文维基去除
-- :css('font-size', '90%') 中文維基去除
:css('border-top', infoboxStyle.section_border)
:css('border-top', infoboxStyle.section_border)
:newline()
:newline()
:wikitext(self.args.notes)
:wikitext(self.args.notes)
end
end
if self.args.map_type then
if self.args.map_type then
builder:tag('tr')
builder:tag('tr')
:tag('td')
:tag('td')
:attr('colspan', self.combatants)
:attr('colspan', self.combatants)
:css('border-top', infoboxStyle.internal_border)
:css('border-top', infoboxStyle.internal_border)
:node(require('Module:Location map').main(self.frame, {
:node(require('Module:Location map').main(self.frame, {
self.args.map_type,
self.args.map_type,
relief = self.args.map_relief,
relief = self.args.map_relief,
coordinates = self.args.coordinates,
coordinates = self.args.coordinates,
width = self.args.map_size or 220,
width = self.args.map_size or 220,
float = 'center',
float = 'center',
border = 'none',
border = 'none',
mark = self.args.map_mark,
mark = self.args.map_mark,
marksize = self.args.map_marksize or 8,
marksize = self.args.map_marksize or 8,
label = self.args.map_label,
label = self.args.map_label,
alt = self.args.map_alt,
alt = self.args.map_alt,
caption = self.args.map_caption or ('在'  
caption = self.args.map_caption or ('在'
.. (require('Module:Location map').data(self.frame, {self.args.map_type, 'name'})) .. '的位置')
.. (require('Module:Location map').data(self.frame, {self.args.map_type, 'name'})) .. '的位置')
}))
}))
end
end
builder = builder:done()
builder = builder:done()
if self.args.campaignbox then
if self.args.campaignbox then
builder = builder:done()
builder = builder:done()
                builder:wikitext(self.args.campaignbox .. self.frame:expandTemplate{ title = 'stack end'})
builder:wikitext(self.args.campaignbox .. self.frame:expandTemplate{ title = 'stack end'})
end
end
return builder
return builder
end
end


function IMC.new(frame, args)
function IMC.new(frame, args)
if not args then
if not args then
args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Infobox military conflict'})
args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Infobox military conflict'})
end
end
local obj = {
local obj = {
frame = frame,
frame = frame,
args = args
args = args
}
}


-- until gerrit:165108 is merged, there's still a cap on combatants, but as soon as it merges, we can update this little bit of code to uncap it
-- until gerrit:165108 is merged, there's still a cap on combatants, but as soon as it merges, we can update this little bit of code to uncap it
-- also, don't try to make this more efficient, or references could be in the wrong order
-- also, don't try to make this more efficient, or references could be in the wrong order
obj.combatants = 2
obj.combatants = 2
for _,v in ipairs{'', 'a', 'b', 'c', 'd'} do
for _,v in ipairs{'', 'a', 'b', 'c', 'd'} do
for i = 1,5 do
for i = 1,5 do
if args['combatant' .. i .. v] then
if args['combatant' .. i .. v] then
obj.combatants = math.max(obj.combatants, i)
obj.combatants = math.max(obj.combatants, i)
end
end
end
end
end
end


return setmetatable(obj, IMC)
return setmetatable(obj, IMC)
end
end


第274行: 第280行:


function p.main(frame)
function p.main(frame)
return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(IMC.new(frame):render())
return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(IMC.new(frame):render())
end
end


return p
return p