local p = {}
local getArgs = require("Module:Arguments").getArgs
function p.main(frame)
local args = getArgs(frame)
local info = ""
-- 处理全碟信息
if args["all_writing"] then
info = info .. "全碟-{zh-hans:作词;zh-hant:作詞;zh-hk:填詞;}-及作曲:" .. args["all_writing"] .. " "
end
if args["all_lyrics"] then
info = info .. "全碟-{zh-hans:作词;zh-hant:作詞;zh-hk:填詞;}-:" .. args["all_lyrics"] .. " "
end
if args["all_music"] then
info = info .. "全碟作曲:" .. args["all_music"] .. " "
end
if args["all_arranger"] then
info = info .. "全碟编曲:" .. args["all_arranger"] .. " "
end
if args["all_singer"] then
info = info .. "全碟演唱:" .. args["all_singer"] .. " "
end
if args["all_producer"] then
info = info .. "全碟监制:" .. args["all_producer"] .. " "
end
if args["all_note"] then
if args["all_note"] == "except" or args["all_note"] == "yes" then
info = info .. "<small>(下面注明例外曲目)</small>"
else
info = info .. args["all_note"]
end
end
if args["all_note2"] then
info = info .. args["all_note2"]
end
-- 检查是否有长度参数
local length_check = false
for key, value in pairs(args) do
if string.match(key, "^length%d+") and value ~= "" then
length_check = true
break
end
end
-- 开始构建HTML
local output = '<div class="tracklist '
if args["switch_colour"] then
output = output .. 'tracklist-switch'
end
output = output .. '" style="display:flow-root; min-width:340px; '
if args["collapsed"] == "open" or args["collapsed"] == "closed" or args["collapsed"] == "yes" then
output = output .. 'border: #aaa 1px solid; padding: 3px'
else
output = output .. 'padding: 4px'
end
output = output .. '">\n'
output = output .. '<table class="'
if args["collapsed"] == "closed" or args["collapsed"] == "yes" then
output = output .. 'mw-collapsible mw-collapsed'
elseif args["collapsed"] == "open" then
output = output .. 'mw-collapsible'
end
output = output .. '" cellpadding="0" style="width: 100%;">\n'
-- 表头行
output = output .. '<tr>\n<th class="tlheadline" colspan="10" style="'
local headline_align = args["headline_align"]
if not headline_align then
headline_align = info ~= "" and "center" or "left"
end
if headline_align == "center" then
output = output .. 'text-align: center;'
elseif headline_align == "right" then
output = output .. 'text-align: right; padding-right: 3em;'
else
output = output .. 'text-align: left; padding-left: 3em;'
end
output = output .. ' background-color: #fff;">'
if args["headline"] or args["1"] then
output = output .. (args["headline"] or args["1"])
else
output = output .. "曲目列表"
end
if info ~= "" then
output = output .. '<div style="font-weight: normal; ">' .. info .. '</div>'
end
output = output .. '</th>\n</tr>\n'
-- 隐藏行处理
if args["hidden"] == "yes" then
output = output .. '<tr>\n<th colspan="10" style="text-align: left; background-color: #fff">\n'
output = output .. '<div style="padding-left: 2em">' .. (args["hidden_note"] or "") .. '</div>\n'
output = output .. '</th>\n</tr>\n'
else
-- 表头
output = output .. '<tr style="background-color: #eee">\n'
output = output .. '<th class="tlheader" scope="col" style="width: 3em;">曲序</th>\n'
output = output .. '<th class="tlheader" style="text-align: left;">曲目</th>\n'
if args["writing_credits"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">' ..
(mw.language.getContentLanguage():getCode() == "zh-hans" and "作词" or "作詞") ..
'及作曲</th>\n'
else
if args["lyrics_credits"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">' ..
(mw.language.getContentLanguage():getCode() == "zh-hans" and "作词" or "作詞") ..
'</th>\n'
end
if args["music_credits"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">作曲</th>\n'
end
end
if args["arranger_credits"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">编曲</th>\n'
end
if args["singer_credits"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">演唱</th>\n'
end
if args["producer_credits"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">监制</th>\n'
end
if args["extra_column"] then
output = output .. '<th class="tlheader" style="text-align: left;">' .. args["extra_column"] .. '</th>\n'
end
if args["longnote_column"] == "yes" then
output = output .. '<th class="tlheader" style="text-align: left;">备注</th>\n'
end
if length_check then
output = output .. '<th class="tlheader" style="padding-right: 10px; text-align: right; width: 3em;">时长</th>\n'
end
output = output .. '</tr>\n'
-- 处理曲目行
local track_count = 0
for key, value in pairs(args) do
if string.match(key, "^title%d+") then
track_count = track_count + 1
end
end
-- 获取起始序号,默认为1
local start_number = tonumber(args["start_number"]) or 1
for i = 1, track_count do
local track_args = {
switch_colour = args["switch_colour"],
lyrics_credits = args["lyrics_credits"],
music_credits = args["music_credits"],
writing_credits = args["writing_credits"],
arranger_credits = args["arranger_credits"],
singer_credits = args["singer_credits"],
producer_credits = args["producer_credits"],
extra_column = args["extra_column"],
longnote_column = args["longnote_column"],
number = start_number + i - 1, -- 计算实际显示的序号
title = args["title" .. i],
note = args["note" .. i],
length = args["length" .. i],
lyrics = args["lyrics" .. i],
music = args["music" .. i],
writer = args["writer" .. i],
arranger = args["arranger" .. i],
singer = args["singer" .. i],
producer = args["producer" .. i],
extra = args["extra" .. i],
longnote = args["longnote" .. i]
}
output = output .. p.render_track(track_args)
end
-- 总时长行
if length_check then
local colspan = 2
if args["writing_credits"] == "yes" then
colspan = colspan + 1
else
if args["lyrics_credits"] == "yes" then colspan = colspan + 1 end
if args["music_credits"] == "yes" then colspan = colspan + 1 end
end
if args["arranger_credits"] == "yes" then colspan = colspan + 1 end
if args["singer_credits"] == "yes" then colspan = colspan + 1 end
if args["producer_credits"] == "yes" then colspan = colspan + 1 end
if args["extra_column"] then colspan = colspan + 1 end
if args["longnote_column"] == "yes" then colspan = colspan + 1 end
output = output .. '<tr style="text-align: right; background-color: #fff">\n'
output = output .. '<td colspan="' .. colspan .. '"><div style="text-align: right; padding: 5px 0 5px 10px; margin: 0">总时长:</div></td>\n'
output = output .. '<td style="text-align: right; padding: 5px 10px" class="total_length"> - </td>\n'
output = output .. '</tr>\n'
end
end
-- 更多信息行
if args["more"] then
output = output .. '<tr style="background-color: #fff"><td colspan="10">' .. args["more"] .. '</td></tr>\n'
end
output = output .. '</table>\n</div>'
return output
end
function p.render_track(args)
local output = '<tr'
if args.switch_colour and tonumber(args.number) % 2 == 0 then
output = output .. ' style="background-color: #f9f9f9"'
end
output = output .. '>\n'
output = output .. '<td class="tracklist-number">' .. args.number .. '</td>\n'
output = output .. '<td class="tracklist-name">' .. (args.title or "") .. '</td>\n'
if args.writing_credits == "yes" then
output = output .. '<td class="tracklist-writing">' .. (args.writer or "") .. '</td>\n'
else
if args.lyrics_credits == "yes" then
output = output .. '<td class="tracklist-lyrics">' .. (args.lyrics or "") .. '</td>\n'
end
if args.music_credits == "yes" then
output = output .. '<td class="tracklist-music">' .. (args.music or "") .. '</td>\n'
end
end
if args.arranger_credits == "yes" then
output = output .. '<td class="tracklist-arranger">' .. (args.arranger or "") .. '</td>\n'
end
if args.singer_credits == "yes" then
output = output .. '<td class="tracklist-singer">' .. (args.singer or "") .. '</td>\n'
end
if args.producer_credits == "yes" then
output = output .. '<td class="tracklist-producer">' .. (args.producer or "") .. '</td>\n'
end
if args.extra_column then
output = output .. '<td class="tracklist-extra">' .. (args.extra or "") .. '</td>\n'
end
if args.longnote_column == "yes" then
output = output .. '<td class="tracklist-longnote">' .. (args.longnote or "") .. '</td>\n'
end
if args.length then
output = output .. '<td class="tracklist-length" style="text-align: right;">' .. args.length .. '</td>\n'
end
output = output .. '</tr>\n'
if args.note then
output = output .. '<tr><td colspan="10" class="tracklist-note"><small>' .. args.note .. '</small></td></tr>\n'
end
return output
end
return p