Module:TV program order
来自Gal中文百科
更多语言
更多操作
此模块的文档可以在Module:TV program order/doc创建
local p = {}
local yesno = require('Module:Yesno')
local firstitem = false
local function union(t1, t2, t3)
local vals = {}
for k, v in pairs(t1) do
vals[v] = true
end
for k, v in pairs(t2) do
vals[v] = true
end
for k, v in pairs(t3) do
vals[v] = true
end
local ret = {}
for k, v in pairs(vals) do
table.insert(ret, k)
end
return ret
end
local function getArgNums(args, suffix)
local nums = {}
for k, v in pairs(args) do
local num = mw.ustring.match(tostring(k), '^' .. '([1-9]%d*)' .. suffix .. '$')
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
local function makeTitle(rowArgs)
if not rowArgs.title then return end
local row = mw.html.create('tr')
row:tag('th')
:attr('colspan', 3)
:wikitext(rowArgs.title)
return row
end
local function makeNote(notes)
if not notes.notea then return end
local noteCell = mw.html.create('ul')
noteCell
:css('font-size', 'smaller')
:css('font-weight', 'normal')
:css('text-align', 'left')
:tag('li')
:wikitext(notes.notea)
if notes.noteb then
noteCell
:tag('li')
:wikitext(notes.noteb)
end
return noteCell
end
local function makeSimpleCell(cells)
local dataCell = mw.html.create('td')
if firstitem == true then
dataCell
:attr('rowspan', 2)
:css('width', '33.33%')
:css('font-weight', 'bold')
end
dataCell
:cssText(cells.datastyle)
:wikitext(cells.data)
:node(makeNote({
notea = cells.notea,
noteb = cells.noteb
}))
return dataCell
end
local function makeContentRow(contents)
local row = mw.html.create('tr')
row:node(makeSimpleCell({
data = contents.dataa,
notea = contents.notea1,
noteb = contents.noteb1
}))
row:node(makeSimpleCell({
data = contents.datab,
datastyle = 'font-weight:bold;',
notea = contents.notea2,
noteb = contents.noteb2
}))
row:node(makeSimpleCell({
data = contents.datac,
notea = contents.notea3,
noteb = contents.noteb3
}))
return row
end
function p._main(args)
local root = mw.html.create()
if args["hide"] then
args["隐藏"] = args["hide"]
elseif args["折叠"] then
args["隐藏"] = args["折叠"]
elseif args["折叠"] then
args["隐藏"] = args["折叠"]
elseif args["隐藏"] then
args["隐藏"] = args["隐藏"]
end
if args["宽度"] then
args["宽度"] = args["宽度"]
end
if args["电视台"] then
args["电视台"] = args["电视台"]
elseif args["电视台"] then
args["电视台"] = args["电视台"]
end
if args["播放档次"] then
args["播放档次"] = args["播放档次"]
end
if args["节目名称"] then
args["节目名称"] = args["节目名称"]
end
if args["上一节目"] then
args["上一节目"] = args["上一节目"]
end
if args["下一节目"] then
args["下一节目"] = args["下一节目"]
end
if args["节目名称备注A"] then
args["节目名称备注A"] = args["节目名称备注A"]
end
if args["节目名称备注B"] then
args["节目名称备注B"] = args["节目名称备注B"]
end
if args["上一节目备注A"] then
args["上一节目备注A"] = args["上一节目备注A"]
end
if args["上一节目备注B"] then
args["上一节目备注B"] = args["上一节目备注B"]
end
if args["下一节目备注A"] then
args["下一节目备注A"] = args["下一节目备注A"]
end
if args["下一节目备注B"] then
args["下一节目备注B"] = args["下一节目备注B"]
end
args["隐藏"] = yesno(args["隐藏"], false)
local tableRoot = root:tag('table')
tableRoot
:addClass('wikitable')
:addClass(args["隐藏"] and 'mw-collapsible mw-collapsed' or nil)
:css('margin', '1em auto')
:css('font-size', '90%')
:css('table-layout', 'fixed')
:css('width', args["宽度"] or '598pt')
:css('text-align', 'center')
local s = ''
if args["播放档次"] then
s = args["播放档次"]
end
if args["电视台"] then
s = args["电视台"] .. ' ' .. s
end
if s == '' then
s = '{{{播放档次}}}'
end
tableRoot:node(makeTitle({
title = s
}))
local headerRow = tableRoot:tag('tr')
local contentRow = tableRoot:tag('tr')
firstitem = true
headerRow
:tag('th')
:css('width', '33.33%')
:wikitext('-{zh-hans:接档;zh-hant:上一节目;}-')
headerRow:node(makeSimpleCell({
data = (args["节目名称"] or mw.title.getCurrentTitle().text),
notea = args["节目名称备注A"],
noteb = args["节目名称备注B"]
}))
headerRow
:tag('th')
:css('width', '33.33%')
:wikitext('-{zh-hans:被接档;zh-hant:下一节目;}-')
firstitem = false
contentRow:node(makeSimpleCell({
data = (args["上一节目"] or '—'),
notea = args["上一节目备注A"],
noteb = args["上一节目备注B"]
}))
contentRow:node(makeSimpleCell({
data = (args["下一节目"] or '—'),
notea = args["下一节目备注A"],
noteb = args["下一节目备注B"]
}))
local nums = union(getArgNums(args, '播放[档档]次'), getArgNums(args, '上一[节节]目'), getArgNums(args, '下一[节节]目'))
table.sort(nums)
for _, num in ipairs(nums) do
if tonumber(num) >=2 then
if args[tostring(num) .. "电视台"] then
args[tostring(num) .. "电视台"] = args[tostring(num) .. "电视台"]
elseif args[tostring(num) .. "电视台"] then
args[tostring(num) .. "电视台"] = args[tostring(num) .. "电视台"]
end
if args[tostring(num) .. "播放档次"] then
args[tostring(num) .. "播放档次"] = args[tostring(num) .. "播放档次"]
end
if args[tostring(num) .. "节目名称"] then
args[tostring(num) .. "节目名称"] = args[tostring(num) .. "节目名称"]
end
if args[tostring(num) .. "上一节目"] then
args[tostring(num) .. "上一节目"] = args[tostring(num) .. "上一节目"]
end
if args[tostring(num) .. "下一节目"] then
args[tostring(num) .. "下一节目"] = args[tostring(num) .. "下一节目"]
end
if args[tostring(num) .. "节目名称备注A"] then
args[tostring(num) .. "节目名称备注A"] = args[tostring(num) .. "节目名称备注A"]
end
if args[tostring(num) .. "节目名称备注B"] then
args[tostring(num) .. "节目名称备注B"] = args[tostring(num) .. "节目名称备注B"]
end
if args[tostring(num) .. "上一节目备注A"] then
args[tostring(num) .. "上一节目备注A"] = args[tostring(num) .. "上一节目备注A"]
end
if args[tostring(num) .. "上一节目备注B"] then
args[tostring(num) .. "上一节目备注B"] = args[tostring(num) .. "上一节目备注B"]
end
if args[tostring(num) .. "下一节目备注A"] then
args[tostring(num) .. "下一节目备注A"] = args[tostring(num) .. "下一节目备注A"]
end
if args[tostring(num) .. "下一节目备注B"] then
args[tostring(num) .. "下一节目备注B"] = args[tostring(num) .. "下一节目备注B"]
end
local sn = nil
if args[tostring(num) .. '播放档次'] then
sn = args[tostring(num) .. '播放档次']
if args[tostring(num) .. '电视台'] then
sn = args[tostring(num) .. '电视台'] .. ' ' .. sn
end
end
tableRoot:node(makeTitle({
title = sn
}))
tableRoot:node(makeContentRow({
dataa = (args[tostring(num) .. '上一节目'] or '—'),
datab = (args[tostring(num) .. '节目名称'] or '第' .. tostring(num) .. '季'),
datac = (args[tostring(num) .. '下一节目'] or '—'),
notea1 = args[tostring(num) .. '上一节目备注A'],
noteb1 = args[tostring(num) .. '上一节目备注B'],
notea2 = args[tostring(num) .. '节目名称备注A'],
noteb2 = args[tostring(num) .. '节目名称备注B'],
notea3 = args[tostring(num) .. '下一节目备注A'],
noteb3 = args[tostring(num) .. '下一节目备注B']
}))
end
end
return tostring(root)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:电视节目的变迁'
})
return p._main(args)
end
return p