Module:ArtistSong:修订间差异

来自Arcaea中文维基
(parentArgs)
(测试曲名作参数)
(未显示2个用户的15个中间版本)
第1行: 第1行:
p={}
p={}
local CAL = mw.loadJsonData 'Template:ComplexArtistsList.json'
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json'
-- local CALv2 = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local trans = mw.loadJsonData 'Template:Transition.json'
local trans = mw.loadJsonData 'Template:Transition.json'
local SL = mw.loadJsonData 'Template:Song Length.json'
local SL = mw.loadJsonData 'Template:Song Length.json'
local VT = mw.loadJsonData 'User:Economy666/VersionTime.json'
local VT = mw.loadJsonData 'Template:VersionTime.json'


local mad = require 'Module:AnotherData'
local mad = require 'Module:AnotherData'
第12行: 第13行:
local queryMO = data.allSongInformation("id", "mobile")
local queryMO = data.allSongInformation("id", "mobile")
local queryNS = data.allSongInformation("id", "ns")
local queryNS = data.allSongInformation("id", "ns")
local NotJaName = {['旅人E']='Tabibito E'}


local function readList()
local function readList()
第80行: 第79行:
    local singleList = {}
    local singleList = {}
    for cArtist in pairs(convertList) do
    for cArtist in pairs(convertList) do
      if CAL[cArtist] then
   local artistlist={}
     local artistlist={}
      if CALv2[cArtist] then
       for _,text in pairs(CAL[cArtist]) do
if CALv2[cArtist].__FullData__ then
         if text.link then
for _,text in pairs(CALv2[cArtist].__FullData__) do
           local artist = text['link']
if text.link then
           if not artistlist[artist] then
           local artist = text['link']
           singleList = cate(singleList, cArtist, artist)
if not artistlist[artist] then
           artistlist[artist]=1
singleList = cate(singleList, cArtist, artist)
           end
artistlist[artist]=1
         end
end
       end
end
end
else
for link in pairs(CALv2[cArtist]) do
           local artist = link
if not artistlist[artist] then
singleList = cate(singleList, cArtist, artist)
artistlist[artist]=1
end
end
end
     -- elseif CAL[cArtist] then
     --   for _,text in pairs(CAL[cArtist]) do
     --     if text.link then
     --       local artist = text['link']
     --       if not artistlist[artist] then
     --       singleList = cate(singleList, cArtist, artist)
     --       artistlist[artist]=1
     --       end
     --     end
     --   end
      else
      else
        singleList = cate(singleList, cArtist)
        singleList = cate(singleList, cArtist)
第96行: 第115行:
end
end
    return singleList
    return singleList
end
local function isLetter(char)
return char:match("%a") ~= nil
end
end


-- 排序
-- 排序
local function customSort(a, b)
local function customSort(a, b)
   local function isLetter(char)
     return char:match("%a") ~= nil
   end
    
    
local a1 = a:sub(1, 1)
local a1 = a:sub(1, 1)
第154行: 第174行:
bpm = queryMO(id, 'bpm') or queryNS(id, 'bpm')
bpm = queryMO(id, 'bpm') or queryNS(id, 'bpm')
if bpm then return bpm 
if bpm then return bpm 
else return id end
else return nil end
end
end


local lang = mw.language.getContentLanguage()
local function songDate(id, byd)
local function songDate(id, byd)
local date, ver
local date, ver
if byd then
if byd then
date = queryMO(id, 'bydDate') or queryNS(id, 'bydDate')
date = queryMO(id, 'bydDate') or queryNS(id, 'bydDate')
if date then return date end
if date then return (tonumber(lang:formatDate('ymd', '@' .. date)) - 1) end
end
end
date = queryMO(id, 'date') or queryNS(id, 'date')
date = queryMO(id, 'date') or queryNS(id, 'date')
if date then return date
if date then return (tonumber(lang:formatDate('ymd', '@' .. date)) - 1)
else return id end
else return '000000' end
end
end


第187行: 第208行:
packid = queryMO(id, 'set')
packid = queryMO(id, 'set')
else
else
return id
return nil
end
end
local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
第194行: 第215行:
end
end


local lang = mw.language.getContentLanguage()
local function songLength(id,byd)
local function versionDate(ver, sec)
if byd then
local date = tonumber(lang:formatDate('ymd', '@' .. sec)) - 1
return SL.beyond[id]
else
return SL.normal[id]
end
end
 
local function versionDate(ver, date)
local vt
local vt
if VT[ver] then vt=VT[ver] else return ver, date end
if VT[ver] then vt=VT[ver] else return ver, date end
local dates = vt.time
local dates = vt.time
local version = vt.ver
local version = vt.ver
nDates = {}
local nDates = {}
for _,date in ipairs(dates) do
for _,d in ipairs(dates) do
table.insert(nDates,date)
table.insert(nDates,d)
end
end
if date > nDates[#nDates] then return ver, date end
if date > nDates[#nDates] then return ver, date end
第220行: 第247行:


function dateConvert(date)
function dateConvert(date)
if not date then return nil end
local dateStr = tostring(date)
local dateStr = tostring(date)
local yy = string.sub(dateStr,1,2)
local yy = string.sub(dateStr,1,2)
local mm = string.sub(dateStr,3,4)
local mm = string.sub(dateStr,3,4)
local dd = string.sub(dateStr,5,6)
local dd = string.sub(dateStr,5,6)
return string.format("%02d/%02d/%02d", yy, mm, dd % 100)
return '20'..string.format("%02d/%02d/%02d", yy, mm, dd % 100)
end
end


function p.main(frame)
function p.main(frame)
local parentArgs = frame:getParent().args
local parentArgs = frame:getParent().args
local Args = frame.args
    local rl, rlb = readList()
    local rl, rlb = readList()
    local cl = convertPick(rl, rlb)
    local cl = convertPick(rl, rlb)
    local gl = genList(cl)
    local gl = genList(cl)
    rl,rlb,cl = nil
    rl,rlb,cl = nil
  
   local appendList = Args['appendList']
if appendList then
local list = mw.text.split(appendList,'/')
for _,id in pairs(list) do
local artists = Args[id .. '.'..'artist']
local artistList = mw.text.split(artists,'/')
for _, artist in pairs(artistList) do
if gl[artist] and gl[artist].normal then
table.insert(gl[artist].normal, id)
end
end
end
end
  
    local wikiText = ""
    local wikiText = ""


第240行: 第285行:
local enName
local enName
if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
enName = parentArgs[name .. '.enName'] or name--nil
-- enName = parentArgs[name .. '.enName'] or name--nil
local enHide = parentArgs[name .. '.enHideName']
local notJaName = parentArgs[name .. '.notJaName']
enName = enHide or parentArgs[name .. '.enName'] or name--nil
gl2[enName] = gl[name]
gl2[enName] = gl[name]
gl2[enName].localName = name
gl2[enName].localName = name
if NotJaName[name] then
if enHide then
gl2[enName].enHide = 1
end
if notJaName then
gl2[enName].notJa = 1
gl2[enName].notJa = 1
end
end
第255行: 第306行:
end
end
table.sort(a2z, customSort)
table.sort(a2z, customSort)
-- 生成页首
local menuName={nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
for _, name in ipairs(a2z) do
local catId=27
local first=string.lower(name:sub(1, 1))
if isLetter(first) then
catId=string.byte(first)-string.byte("a")+1
end
if menuName[catId]==nil then
menuName[catId]=name
end
end
if menuName[27]==nil then
menuName[27]=""
end
for i=26,1,-1 do
if menuName[i]==nil then
menuName[i]=menuName[i+1]
end
end
local menu={}
for _, name in ipairs(menuName) do
if gl2[name] then
table.insert(menu,gl2[name].localName or name)
else
table.insert(menu,name)
end
end
wikiText = wikiText .. frame:expandTemplate{ title = "目录", args = menu } .. "\n\n"
    
    
    local function tableAppend(line,newStr) return line..'|'..newStr..'\n' end
    local function tableAppend(line,newStr) return line..'|'..newStr..'\n' end
    for _, name in pairs(a2z) do
  
   local function songArg(artist,id,byd,arg)
   arg = '.'..arg
   artist = artist .. '.'
   local function fun(a) return a and artist..a..arg end
if byd then
return parentArgs[fun(queryMO(id, 'bydSongName'))] or parentArgs[fun(id..'.byd')]
else
return parentArgs[fun(queryMO(id, 'title'))] or parentArgs[fun(id)]
end
end
  
   local function aslAppend(artist, songid, date, byd)
local theList={}
local function Input(arg) return songid.. ( byd and '.byd' or '') ..(arg and '.'..arg or '') end
local function aInput(arg) return artist ..'.' .. Input(arg) end
local function none(arg) return '|<span title="'.. aInput(arg) .. '">' .. '--'..'</span>' end
theList.title = ("[[" .. (Args[Input('title')] or songTitle(songid,byd)) .. "]]") or none()
theList.length = Args[Input('length')] or songLength(songid,byd) or none()
theList.bpm = Args[Input('bpm')] or songBPM(songid,byd) or none()
theList.pack = Args[Input('pack')] or songPack(songid) or none()
local releaseVer, releaseDate = versionDate(songVer(songid,byd), date)
ver = Args[Input('ver')] or releaseVer or none()
theList.date = Args[Input('date')] or releaseDate
local AprilFoolVer = Args[Input('AprilFoolVer')]
theList.AprilFoolDate = Args[Input('AprilFoolDate')]
local afVer
if AprilFoolVer and theList.AprilFoolDate then
afVer = ("'''愚人节'''<br>"..'v'..AprilFoolVer .. '<br />('.. dateConvert(theList.AprilFoolDate) .. ")<br>'''常驻'''<br>") or ''
end
theList.displayVer = (afVer or '')..'v'..ver .. '<br />('.. dateConvert(theList.date) .. ')' or none()
theList.text = songArg(artist,songid,byd,'text') or none('text')
return theList
end
  
    for _, name in ipairs(a2z) do
    local item = gl2[name]
    local item = gl2[name]
    local displayName, usingName,other
    local displayName, usingName,other
第265行: 第383行:
    if item.localName then
    if item.localName then
    usingName = item.localName
    usingName = item.localName
   enDisplay = item.enHide and '' or ' (' .. name ..')'
    if item.notJa then
    if item.notJa then
    displayName = usingName ..' (' .. name ..')'
    displayName = usingName .. (other or '') .. enDisplay
    else
    else
    displayName = '<span lang="ja">' .. usingName .. '</span>' .. (other or '') ..' (' .. name ..')'
    displayName = '-{<span lang="ja">' .. usingName .. '</span>}-' .. (other or '') .. enDisplay
    end
    end
    else
    else
    usingName = name
    usingName = name
    displayName = name
    displayName = name .. (other or '')
    end
    end
    -- wikiText = wikiText .. '*' .. usingName .. '\n'
    -- wikiText = wikiText .. '*' .. usingName .. '\n'
第278行: 第397行:
    wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
    wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
    wikiText = wikiText .. "==".. displayName .." ==\n"
    wikiText = wikiText .. "==".. displayName .." ==\n"
    wikiText = wikiText .. 'Span id: ' .. usingName .."\n"
    -- wikiText = wikiText .. 'Span id: ' .. usingName .."\n"
    wikiText = wikiText .. (item.description or '') .. '\n'
    wikiText = wikiText .. (item.description or '') .. '\n'
    wikiText = wikiText .. '{| class="wikitable" border="1" cellspacing="1" cellpadding="5" style="text-align:center;width: 80%"\n'
    wikiText = wikiText .. '{| class="wikitable" border="1" cellspacing="1" cellpadding="5" style="text-align:center;width: 100%"\n'
wikiText = wikiText .. '! style="width: 30.5%;"|曲目名称\n'
wikiText = wikiText .. '! style="width: 30.5%;"|曲目名称\n'
wikiText = wikiText .. '! style="width: 8%;"|时长\n'
wikiText = wikiText .. '! style="width: 6%;"|时长\n'
wikiText = wikiText .. '! style="width: 8%;"|BPM\n'
wikiText = wikiText .. '! style="width: 10%;"|BPM\n'
wikiText = wikiText .. '! style="width: 18.5%;"|曲包\n'
wikiText = wikiText .. '! style="width: 18.5%;"|曲包\n'
wikiText = wikiText .. '! style="width: 15%;"|发布版本\n'
wikiText = wikiText .. '! style="width: 15%;"|发布版本\n'
wikiText = wikiText .. '! style="width: 20%;"|备注\n'
wikiText = wikiText .. '! style="width: 20%;"|备注\n'
  
   local function aslAppend(artist,songid,date,byd)
local theList={}
local none = '<span title="'.. songid .. '">' .. '|--'..'</span>'
theList.title = "[[" .. songTitle(songid,byd) .. "]]"
theList.time = (byd and SL.beyond[songid] or SL.normal[songid]) or none
theList.bpm = songBPM(songid,byd)
theList.pack = songPack(songid)
realVer, realDate = versionDate(songVer(songid,byd), date)
theList.date = realVer .. '<br />('.. dateConvert(realDate) .. ')'
theList.text = parentArgs[artist .. '.' .. songid.. ( byd and '.byd' or '') .. '.text'] or none
return theList
end
   
   
    local artistSongList = {}
    local artistSongList = {}
第306行: 第412行:
    for _,songid in ipairs(item.normal) do
    for _,songid in ipairs(item.normal) do
    local date = songDate(songid)
    local date = songDate(songid)
    local aslId = date..songid
   local theList=aslAppend(usingName, songid, date)
    artistSongList[aslId]=aslAppend(usingName,songid, date)
    local aslId = (theList.AprilFoolDate or theList.date)..songid
    artistSongList[aslId] = theList
table.insert(listSort, aslId)
table.insert(listSort, aslId)
    end
    end
第314行: 第421行:
    for _,songid in ipairs(item.beyond) do
    for _,songid in ipairs(item.beyond) do
    local date = songDate(songid, 1)
    local date = songDate(songid, 1)
    local aslId = date..songid..'byd'
   local theList = aslAppend(usingName, songid, date, 1)
    artistSongList[aslId]=aslAppend(usingName,songid, date, 1)
    local aslId = (theList.AprilFoolDate or theList.date)..songid..'byd'
    artistSongList[aslId] = theList
table.insert(listSort, aslId)
table.insert(listSort, aslId)
    end
    end
第322行: 第430行:
    for _,id in ipairs(listSort) do
    for _,id in ipairs(listSort) do
    wikiText = tableAppend(wikiText, '-')
    wikiText = tableAppend(wikiText, '-')
    wikiText = tableAppend(wikiText, artistSongList[id].title)
   local theList = artistSongList[id]
    wikiText = tableAppend(wikiText, artistSongList[id].time)
    wikiText = tableAppend(wikiText, theList.title)
    wikiText = tableAppend(wikiText, artistSongList[id].bpm)
    wikiText = tableAppend(wikiText, theList.length)
    wikiText = tableAppend(wikiText, artistSongList[id].pack)
    wikiText = tableAppend(wikiText, theList.bpm)
    wikiText = tableAppend(wikiText, artistSongList[id].date)
    wikiText = tableAppend(wikiText, theList.pack)
    wikiText = tableAppend(wikiText, artistSongList[id].text)
    wikiText = tableAppend(wikiText, theList.displayVer)
    wikiText = tableAppend(wikiText, theList.text)
    end
    end
      wikiText = wikiText .. "|}\n"
      wikiText = wikiText .. "|}\n"

2024年7月29日 (一) 16:54的版本

可在Module:ArtistSong/doc创建此模块的帮助文档

p={}
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json'
-- local CALv2 = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
local multiId = mw.loadJsonData 'Template:Transition.json'.multiId
local trans = mw.loadJsonData 'Template:Transition.json'
local SL = mw.loadJsonData 'Template:Song Length.json'
local VT = mw.loadJsonData 'Template:VersionTime.json'

local mad = require 'Module:AnotherData'
local data = require "Module:Arcaea Data"
local CL = require 'Module:ConvertLink'

local queryMO = data.allSongInformation("id", "mobile")
local queryNS = data.allSongInformation("id", "ns")

local function readList()
    local pickList = {}
    local pickListBYD = {}
    for _, song in ipairs(mad.listOf('songs', 'mobile')) do
    	local artist = song.artist
        pickList[song.id] = song.artist
        if song.difficulties[4] and (song.difficulties[4].artist or song.difficulties[4].title_localized) then
        	local bydArtist = song['difficulties'][4]['artist'] or song.artist
            pickListBYD[song['id']] = bydArtist
        end
    end
    
    for _, song in ipairs(mad.listOf('songs', 'ns')) do
        if not pickList[song.id] and not multiId[song.id] then
			pickList[song.id] = song.artist
			if song.difficulties[4] and song.difficulties[4].artist or song.difficulties[4].title_localized then
        		local bydArtist = song['difficulties'][4]['artist'] or song.artist
				pickListBYD[song['id']] = bydArtist
			end
		end
	end

    return pickList, pickListBYD
end

local function convertPick(pickList, pickListBYD)
    convertList = {}
    for _id,_ in pairs(pickList) do
        local artist = pickList[_id]
        if not convertList[artist] then convertList[artist] = {} end
        if not convertList[artist].normal then convertList[artist]['normal'] = {} end
        table.insert(convertList[artist]['normal'], _id)
    end

    for _id in pairs(pickListBYD) do
    	local artist = pickListBYD[_id]
    	if not convertList[artist] then convertList[artist] = {} end
    	if not convertList[artist].beyond then convertList[artist]['beyond'] = {} end
    	table.insert(convertList[artist]['beyond'], _id)
    end

    return convertList
end

local function genList(convertList)
	local function cate(singleList, cArtist, artist)
		local artist = artist or cArtist
		if not singleList[artist] then singleList[artist] = {} end
        if convertList[cArtist].beyond then
            if not singleList[artist].beyond then singleList[artist]['beyond'] = {} end
            for _,i in pairs(convertList[cArtist]['beyond']) do
            	table.insert(singleList[artist]['beyond'],i)
            end
        end
        if convertList[cArtist].normal then
        	if not singleList[artist].normal then singleList[artist]['normal'] = {} end
            for _,i in pairs(convertList[cArtist]['normal']) do
            	table.insert(singleList[artist]['normal'],i)
            end
        end
        return singleList
    end
	
    local singleList = {}
    for cArtist in pairs(convertList) do
    	local artistlist={}
        if CALv2[cArtist] then
			if CALv2[cArtist].__FullData__ then
				for _,text in pairs(CALv2[cArtist].__FullData__) do
					if text.link then
	                    local artist = text['link']
						if not artistlist[artist] then
								singleList = cate(singleList, cArtist, artist)
								artistlist[artist]=1
						end
					end
				end
			else
				for link in pairs(CALv2[cArtist]) do
                    local artist = link
					if not artistlist[artist] then
							singleList = cate(singleList, cArtist, artist)
							artistlist[artist]=1
					end
				end
			end
        -- elseif CAL[cArtist] then
        --     for _,text in pairs(CAL[cArtist]) do
        --         if text.link then
        --             local artist = text['link']
        --             if not artistlist[artist] then
        --             	singleList = cate(singleList, cArtist, artist)
        --             	artistlist[artist]=1
        --             end
        --         end
        --     end
        else
            singleList = cate(singleList, cArtist)
        end
	end
    return singleList
end

local function isLetter(char)
	return char:match("%a") ~= nil
end

-- 排序
local function customSort(a, b)
    
	local a1 = a:sub(1, 1)
	local b1 = b:sub(1, 1)
    local la1 = isLetter(a:sub(1, 1))
    local lb1 = isLetter(b:sub(1, 1))

    if la1 and not lb1 then
        return true
    elseif lb1 and not la1 then
        return false
    elseif string.lower(a1) == string.lower(b1) then
    	local la2 = isLetter(a:sub(2, 2))
    	local lb2 = isLetter(b:sub(2, 2))
    	if la2 and not lb2 then
	        return true
	    elseif lb2 and not la2 then
	        return false
	    else
	    	return string.lower(a) < string.lower(b)
	    end
    else
        return string.lower(a) < string.lower(b)
    end

    return string.lower(a) < string.lower(b)
end

local function songTitle(id,byd)
	local display
	local title = queryMO(id, 'title') or queryNS(id, 'title')
	if byd then
		display = queryMO(id, 'bydSongName') or queryNS(id, 'bydSongName') or 'cant find BYD'
	else 
		display = title
	end
	local res = trans.songNameToDisplayName[title]
	if res then return res..'|'..display end
	res = trans.sameName[title]
	if res then return res[id]..'|'..display end
	if title then return title..'|'..display
	else return id end
end

local function songBPM(id, byd)
	local bpm
	if byd then
		bpm = queryMO(id, 'bydBPM') or queryNS(id, 'bydBPM')
		if bpm then return bpm end
	end
	bpm = queryMO(id, 'bpm') or queryNS(id, 'bpm')
	if bpm then return bpm 
	else return nil end
end

local lang = mw.language.getContentLanguage()
local function songDate(id, byd)
	local date, ver
	if byd then
		date = queryMO(id, 'bydDate') or queryNS(id, 'bydDate')
		if date then return (tonumber(lang:formatDate('ymd', '@' .. date)) - 1) end
	end
	date = queryMO(id, 'date') or queryNS(id, 'date')
	if date then return (tonumber(lang:formatDate('ymd', '@' .. date)) - 1)
	else return '000000' end
end

local function songVer(id, byd)
	local date, ver
	if byd then
		ver = queryMO(id, 'bydVersion') or queryNS(id, 'bydVersion')
		if ver then return ver end
	end
	ver = queryMO(id, 'version') or queryNS(id, 'version')
	if ver then return ver else return id end
end

local function songPack(id)
	local packid,plat,isNS
	-- if queryNS(id, 'set') then
	-- 	packid = queryNS(id, 'set')
	-- 	plat = 'ns'
	-- 	isNS = 1
	if queryMO(id, 'set') then
		packid = queryMO(id, 'set')
	else
		return nil
	end
	local packName = trans.packName[packid] or mad.packQueryWrap(packid, plat).name
	local packLink = CL.packLink(packName,1,isNS)
	return packLink
end

local function songLength(id,byd)
	if byd then
		return SL.beyond[id]
	else
		return SL.normal[id]
	end
end

local function versionDate(ver, date)
	local vt
	if VT[ver] then vt=VT[ver] else return ver, date end
	local dates = vt.time
	local version = vt.ver
	local nDates = {}
	for _,d in ipairs(dates) do
		table.insert(nDates,d)
	end
	if date > nDates[#nDates] then return ver, date end
	if #nDates == 1 then return ver.. '.' ..version[1], dates[1] end
	local l, r = 1, #nDates
	while l < r do
		local m = math.floor((l + r) / 2)
		if dates[m] < date then
			l = m + 1
		else
			r = m
		end
	end
	return ver.. '.' ..version[l], dates[l]
end

function dateConvert(date)
	if not date then return nil end
	local dateStr = tostring(date)
	local yy = string.sub(dateStr,1,2)
	local mm = string.sub(dateStr,3,4)
	local dd = string.sub(dateStr,5,6)
	return '20'..string.format("%02d/%02d/%02d", yy, mm, dd % 100)
end

function p.main(frame)
	local parentArgs = frame:getParent().args
	local Args = frame.args
	
    local rl, rlb = readList()
    local cl = convertPick(rl, rlb)
    local gl = genList(cl)
    rl,rlb,cl = nil
    
    local appendList = Args['appendList']
	if appendList then
		local list = mw.text.split(appendList,'/')
		for _,id in pairs(list) do
			local artists = Args[id .. '.'..'artist']
			local artistList = mw.text.split(artists,'/')
			for _, artist in pairs(artistList) do
				if gl[artist] and gl[artist].normal then
				table.insert(gl[artist].normal, id)
				end
			end
		end
	end
    
    local wikiText = ""

    local a2z = {}
    local gl2 = {}
	for name in pairs(gl) do
		local enName
		if mw.ustring.match(name,'[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+') then
			-- enName = parentArgs[name .. '.enName'] or name--nil
			local enHide = parentArgs[name .. '.enHideName']
			local notJaName = parentArgs[name .. '.notJaName']
			enName = enHide or parentArgs[name .. '.enName'] or name--nil
			gl2[enName] = gl[name]
			gl2[enName].localName = name
			if enHide then
				gl2[enName].enHide = 1
			end
			if notJaName then
				gl2[enName].notJa = 1
			end
		else
			enName = name
			gl2[enName] = gl[name]
		end
		gl2[enName].otherName = parentArgs[name .. '.otherName'] or nil
		gl2[enName].description = parentArgs[name .. '.description'] or nil
		table.insert(a2z,enName) 
	end
	table.sort(a2z, customSort)

	-- 生成页首
	local menuName={nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
	for _, name in ipairs(a2z) do
		local catId=27
		local first=string.lower(name:sub(1, 1))
		if isLetter(first) then
			catId=string.byte(first)-string.byte("a")+1
		end
		if menuName[catId]==nil then 
			menuName[catId]=name
		end
	end
	if menuName[27]==nil then
		menuName[27]=""
	end
	for i=26,1,-1 do
		if menuName[i]==nil then
			menuName[i]=menuName[i+1]
		end
	end

	local menu={}
	for _, name in ipairs(menuName) do
		if gl2[name] then
			table.insert(menu,gl2[name].localName or name) 
		else
			table.insert(menu,name) 
		end
	end

	wikiText = wikiText .. frame:expandTemplate{ title = "目录", args = menu } .. "\n\n"
    
    local function tableAppend(line,newStr) return line..'|'..newStr..'\n' end
    
    local function songArg(artist,id,byd,arg)
    	arg = '.'..arg
    	artist = artist .. '.'
    	local function fun(a) return a and artist..a..arg end
		if byd then 
			return parentArgs[fun(queryMO(id, 'bydSongName'))] or parentArgs[fun(id..'.byd')]
		else
			return parentArgs[fun(queryMO(id, 'title'))] or parentArgs[fun(id)]
		end
	end
    
    local function aslAppend(artist, songid, date, byd) 
		local theList={}
		local function Input(arg) return songid.. ( byd and '.byd' or '') ..(arg and '.'..arg or '') end
		local function aInput(arg) return artist ..'.' .. Input(arg) end
		local function none(arg) return '|<span title="'.. aInput(arg) .. '">' .. '--'..'</span>' end
		theList.title = ("[[" .. (Args[Input('title')] or songTitle(songid,byd)) .. "]]") or none()
		theList.length = Args[Input('length')] or songLength(songid,byd) or none()
		theList.bpm = Args[Input('bpm')] or songBPM(songid,byd) or none()
		theList.pack = Args[Input('pack')] or songPack(songid) or none()
		local releaseVer, releaseDate = versionDate(songVer(songid,byd), date)
		ver = Args[Input('ver')] or releaseVer or none()
		theList.date = Args[Input('date')] or releaseDate
		local AprilFoolVer = Args[Input('AprilFoolVer')]
		theList.AprilFoolDate = Args[Input('AprilFoolDate')]
		local afVer
		if AprilFoolVer and theList.AprilFoolDate then
			afVer = ("'''愚人节'''<br>"..'v'..AprilFoolVer .. '<br />('.. dateConvert(theList.AprilFoolDate) .. ")<br>'''常驻'''<br>") or ''
		end
		theList.displayVer = (afVer or '')..'v'..ver .. '<br />('.. dateConvert(theList.date) .. ')' or none()
		theList.text = songArg(artist,songid,byd,'text') or none('text')
		return theList
	end
    
    for _, name in ipairs(a2z) do
    	local item = gl2[name]
    	local displayName, usingName,other
    	if item.otherName then
    		other = (' ('..item.otherName..')') or nil
    	end
    	if item.localName then
    		usingName = item.localName
    		enDisplay = item.enHide and '' or ' (' .. name ..')'
    		if item.notJa then
    			displayName = usingName .. (other or '') .. enDisplay
    		else
    			displayName = '-{<span lang="ja">' .. usingName .. '</span>}-' .. (other or '') .. enDisplay
    		end
    	else
    		usingName = name
    		displayName = name .. (other or '')
    	end
    	-- wikiText = wikiText .. '*' .. usingName .. '\n'
    	
    	wikiText = wikiText .. '<span id="' .. usingName .. '" />\n'
    	wikiText = wikiText .. "==".. displayName .." ==\n"
    	-- wikiText = wikiText .. 'Span id: ' .. usingName .."\n"
    	wikiText = wikiText .. (item.description or '') .. '\n'
    	wikiText = wikiText .. '{| class="wikitable" border="1" cellspacing="1" cellpadding="5" style="text-align:center;width: 100%"\n'
		wikiText = wikiText .. '! style="width: 30.5%;"|曲目名称\n'
		wikiText = wikiText .. '! style="width: 6%;"|时长\n'
		wikiText = wikiText .. '! style="width: 10%;"|BPM\n'
		wikiText = wikiText .. '! style="width: 18.5%;"|曲包\n'
		wikiText = wikiText .. '! style="width: 15%;"|发布版本\n'
		wikiText = wikiText .. '! style="width: 20%;"|备注\n'
    	
    	local artistSongList = {}
    	local listSort = {}
    	if item.normal then
    		for _,songid in ipairs(item.normal) do
    			local date = songDate(songid)
    			local theList=aslAppend(usingName, songid, date)
    			local aslId = (theList.AprilFoolDate or theList.date)..songid
    			artistSongList[aslId] = theList
				table.insert(listSort, aslId)
    		end
    	end
    	if item.beyond then
    		for _,songid in ipairs(item.beyond) do
    			local date = songDate(songid, 1)
    			local theList = aslAppend(usingName, songid, date, 1)
    			local aslId = (theList.AprilFoolDate or theList.date)..songid..'byd'
    			artistSongList[aslId] = theList
				table.insert(listSort, aslId)
    		end
    	end
    	table.sort(listSort)
    	for _,id in ipairs(listSort) do
    		wikiText = tableAppend(wikiText, '-')
    		local theList = artistSongList[id]
    		wikiText = tableAppend(wikiText, theList.title)
    		wikiText = tableAppend(wikiText, theList.length)
    		wikiText = tableAppend(wikiText, theList.bpm)
    		wikiText = tableAppend(wikiText, theList.pack)
    		wikiText = tableAppend(wikiText, theList.displayVer)
    		wikiText = tableAppend(wikiText, theList.text)
    	end
        wikiText = wikiText .. "|}\n"
    end
    return wikiText
end

return p