Module:Sandbox/HistoryM:修订间差异
跳转到导航
跳转到搜索
添加的内容 删除的内容
小无编辑摘要 |
小无编辑摘要 |
||
第3行: | 第3行: | ||
local Hver = nil |
local Hver = nil |
||
local HV = { |
local HV = { |
||
xbox360 = nil, |
|||
xbone = nil, |
xbone = nil, |
||
ps = nil, |
ps = nil, |
||
第79行: | 第79行: | ||
function resetCon() |
function resetCon() |
||
HV. |
HV.xbox360 = nil |
||
HV.xbone = nil |
HV.xbone = nil |
||
HV.ps = nil |
HV.ps = nil |
||
第139行: | 第139行: | ||
if(version == 'none') then return ' ' end |
if(version == 'none') then return ' ' end |
||
if(version == 'unknown' or version=='?') then return '?[[Category:有未知版本的History模板的页面]]' end |
if(version == 'unknown' or version=='?') then return '?[[Category:有未知版本的History模板的页面]]' end |
||
local r = ' '.. version |
local r = platform..' '.. version |
||
local s = version |
local s = version |
||
if(platform == ' |
if(platform == 'ps') then s = s:gsub('%w*%(.*%)$','') |
||
elseif(platform == 'xbone') then r = 'xbone' .. r |
|||
elseif(platform == 'wiiu') then r = 'wiiu'.. r |
|||
elseif(platform == 'switch') then r = 'switch'.. r |
|||
elseif(platform == 'ps') then r ='ps'.. r s = s:gsub('%w*%(.*%)$','') |
|||
end |
end |
||
return versionLink({r,s}) |
return versionLink({r,s}) |
||
第199行: | 第195行: | ||
end |
end |
||
addConsoleVersions(" |
addConsoleVersions("xbox360",args.xbox,prnt) |
||
addConsoleVersions("xbone",args.xbone,prnt) |
addConsoleVersions("xbone",args.xbone,prnt) |
||
addConsoleVersions("ps",args.ps,prnt) |
addConsoleVersions("ps",args.ps,prnt) |
||
第331行: | 第327行: | ||
end |
end |
||
countConsoleRowspan(" |
countConsoleRowspan("xbox360",args.xbox,snapRows) |
||
countConsoleRowspan("xbone",args.xbone,snapRows) |
countConsoleRowspan("xbone",args.xbone,snapRows) |
||
countConsoleRowspan("ps",args.ps,snapRows) |
countConsoleRowspan("ps",args.ps,snapRows) |
||
第360行: | 第356行: | ||
Hrowspan = {} |
Hrowspan = {} |
||
HVrowspan = { |
HVrowspan = { |
||
xbox360 = {}, |
|||
xbone = {}, |
xbone = {}, |
||
ps = {}, |
ps = {}, |
||
第371行: | 第367行: | ||
Hindex = 0 |
Hindex = 0 |
||
HVindex = { |
HVindex = { |
||
xbox360 = 0, |
|||
xbone = 0, |
xbone = 0, |
||
ps = 0, |
ps = 0, |
2023年6月19日 (一) 11:40的版本
local p = {}
local Hmode = nil
local Hver = nil
local HV = {
xbox360 = nil,
xbone = nil,
ps = nil,
wiiu = nil,
switch = nil
}
local HVindex
local HVrowspan
local Hindex
local Hrowspan
local versionLink = require( 'Module:Version link' ).main
local editionAlias = {
['pre-classic'] = "java pre-Classic", ['java pre-classic'] = "java pre-Classic",
classic = "java Classic", ['java classic'] = "java Classic",
['classic server'] = "java Classic server", ['java classic server'] = "java Classic server",
indev = "java Indev", ['java indev'] = "java Indev",
infdev = "java Infdev", ['java infdev'] = "java Infdev",
alpha = "java Alpha", ['java alpha'] = "java Alpha", ['java edition alpha'] = "java Alpha",
['alpha server'] = "java Alpha server", ['java alpha server'] = "java Alpha server", ['java edition alpha server'] = "java Alpha server",
beta = "java Beta", ['java beta'] = "java Beta", ['java edition beta'] = "java Beta",
je = "java", java = "java", ['java edition'] = "java",
['java edition upcoming'] = "java upcoming", ['java upcoming'] = "java upcoming", ['upcoming java'] = "java upcoming",
['pe alpha'] = "pocket Alpha", ['pocket alpha'] = "pocket Alpha", ['pocket edition alpha'] = "pocket Alpha",
pe = "pocket", pocket = "pocket", ['pocket edition'] = "pocket",
ce = "console", lce = "console", console = "console", ['legacy console'] = "console", ['console edition'] = "console", ['legacy console edition'] = "console",
be = "bedrock", bedrock = "bedrock", ['bedrock edition'] = "bedrock",
['be upcoming'] = "bedrock upcoming", ['bedrock upcoming'] = "bedrock upcoming", ['bedrock edition upcoming'] = "bedrock upcoming", ['upcoming bedrock'] = "bedrock upcoming",
['3ds'] = "3ds", new3ds = "3ds", ['new 3ds'] = "3ds",
realms = "realms",
edu = "edu", minecraftedu = "edu",
education = "education", ['education edition'] = "education",
['ee upcoming'] = "education upcoming", ['education upcoming'] = "education upcoming", ['education edition upcoming'] = "education upcoming", ['upcoming education'] = "education upcoming",
ps4 = "ps4", playstation4 = "ps4", ['playstation 4'] = "ps4",
earth = "earth", ['minecraft earth'] = "earth",
dungeons = "dungeons", ['minecraft dungeons'] = "dungeons",
['?'] = "unknown", unknown = "unknown"
}
local headerText = {
['java pre-Classic'] = '[[Java版pre-Classic]]',
['java Classic'] = '[[Java版Classic]]',
['java Classic server'] = '[[Java版Classic|Java版Classic服务器]]',
['java Indev'] = '[[Java版Indev]]',
['java Infdev'] = '[[Java版Infdev]]',
['java Alpha'] = '[[Java版Alpha]]',
['java Alpha server'] = '[[Java版Alpha|Java版Alpha服务器]]',
['java Beta'] = '[[Java版Beta]]',
['java'] = '[[Java版版本记录|Java版]]',
['java upcoming'] = '[[计划版本#Java版|Java版(即将到来)]][[Category:Java版即将到来]]',
['pocket Alpha'] = '[[携带版Alpha]]',
['pocket'] = '[[携带版]]',
['bedrock'] = '[[基岩版版本记录|基岩版]]',
['bedrock upcoming'] = '[[计划版本#基岩版|基岩版(即将到来)]][[Category:基岩版即将到来]]',
['edu'] = '[[MinecraftEdu]]',
['education'] = '[[教育版版本记录|教育版]]',
['education upcoming'] = '[[计划版本#教育版|教育版(即将到来)]][[Category:教育版即将到来]]',
['console'] = '[[原主机版版本记录|原主机版]]',
['realms'] = '[[Realms#历史|Realms]]',
['3ds'] = '[[New Nintendo 3DS版版本记录|New Nintendo 3DS版]]',
['ps4'] = '[[原主机版版本记录|PlayStation 4版]]',
['earth'] = '[[Minecraft Earth]]',
['dungeons'] = '[[Minecraft Dungeons]]',
['unknown'] = '未知[[Category:有未知版本的History模板的页面]]'
}
local versionLinks = {
['java upcoming'] = 'java',
['bedrock upcoming'] = 'bedrock',
['education upcoming'] = 'education',
ps4 = 'ps4',
earth = 'Earth',
dungeons = 'Dungeons'
}
function resetCon()
HV.xbox360 = nil
HV.xbone = nil
HV.ps = nil
HV.wiiu = nil
HV.switch = nil
end
function reset()
Hver = nil
resetCon()
end
function footReset()
Hmode = nil
reset()
end
function getVersionLink(link,text,isSnap)
local cat = ''
if(not isSnap) then
-- upcoming categories
if(Hmode == 'java upcoming') then cat = '[[Category:Java版即将到来/'..text..']]'
elseif(Hmode == 'bedrock upcoming') then cat = '[[Category:基岩版即将到来/'..text..']]'
elseif(Hmode == 'education upcoming') then cat = '[[Category:教育版即将到来/'..text..']]'
end
end
if(link == 'none') then
if(text == 'unknown' or text == '?') then return '?[[Category:有未知版本的History模板的页面]]' end
if(isSnap and text == 'java') then return '' end --不知道有什么用
return text .. cat
end
if(link == 'ver') then
if(text == 'unknown' or text == '?') then return '?[[Category:有未知版本的History模板的页面]]' end
if(isSnap and text == 'java') then return '' end --不知道有什么用
if((not isSnap) and (Hmode == 'realms')) then return text end
local c
if(not isSnap) then
if(text == 'Pre-release' and Hmode == 'pocket Alpha') then c = 'pocket Pre-release'
else c = (versionLinks[Hmode] or Hmode) .. ' ' .. text
end
else
c = text:lower()
if(c:match('^pre') or c:match('^rc') or c:match('^exp')) then c = Hver .. '-' .. text
elseif(c:match('^test build') or c:match('^pre%-release') or c:match('^build') or c:match('^20[01]')) then c = Hver .. ' ' .. text
elseif(c:match('^release')) then c = Hver
else c = text
end
c = (versionLinks[Hmode] or Hmode) .. ' ' .. c
end
return versionLink({c,text:gsub( '^%((.*)%)$', '%1')}) .. cat
end
if(text == 'unknown' or text == '?') then cat = '[[Category:有未知版本的History模板的页面]]' end
if(link:find('//',1,true)) then return '['..link..' '..text..']'..cat else return '[['..link..'|'..text..']]'..cat end
end
function consoleVersionLink(platform,version)
if(version == 'none') then return ' ' end
if(version == 'unknown' or version=='?') then return '?[[Category:有未知版本的History模板的页面]]' end
local r = platform..' '.. version
local s = version
if(platform == 'ps') then s = s:gsub('%w*%(.*%)$','')
end
return versionLink({r,s})
end
function addConsoleVersions(platform,version,prnt)
if((version ~= nil and version == HV[platform]) or (version == nil and HV[platform] ~= nil))
then
return
end
prnt('<th class="nowrap" rowspan="')
HV[platform] = version or "none"
HVindex[platform] = HVindex[platform] + 1
prnt(HVrowspan[platform][HVindex[platform]]..'">')
prnt(consoleVersionLink(platform,version or 'none'))
prnt('</th>')
end
function processLine(args, prnt)
local snapRows = 1
for i,_ in ipairs(args) do
if(i > 3) then snapRows = snapRows + 1
end
end --要保证3不是nil
--Header or Foot
if(args[1] ~= nil and args[1] ~= '') then
local mode = (args[1]):lower()
if (mode == 'foot') then
prnt('</table>')
footReset()
Hhead = 0
return
end
Hmode = editionAlias[mode] or mode
reset()
prnt('<tr><th colspan="6">')
prnt(headerText[Hmode] or ('[['.. Hmode ..']]'))
prnt('</th></tr>')
return
end
--Content rows
prnt('<tr>')
if((Hmode == 'console') and (args.xbox or args.xbone or args.ps or args.wiiu or args.switch )) then
Hver = nil
if(args[3] ~= nil and args[3] ~= '') then
snapRows = snapRows + 1
end
addConsoleVersions("xbox360",args.xbox,prnt)
addConsoleVersions("xbone",args.xbone,prnt)
addConsoleVersions("ps",args.ps,prnt)
addConsoleVersions("wiiu",args.wiiu,prnt)
addConsoleVersions("switch",args.switch,prnt)
prnt('<td>'..args[2]..'</td></tr>')
for k,v in ipairs(args) do
if(k > 2) then prnt('<tr><td>' .. v .. '</td></tr>')
end
end --要保证中间没有nil
return
end
--Other versions:
resetCon()
if((args.snap == nil) or (args[2] and args[2]~='' and (args[2] ~= Hver))) then
Hver = nil
prnt('<th ')
if( not (args.link or args[2]:find('(', 1, true))) then prnt('class="nowrap"') end
prnt(' rowspan="')
if( args.snap ~= nil) then
Hver = args[2]
Hindex = Hindex + 1
prnt(Hrowspan[Hindex]..'" colspan="2">')
else
prnt(snapRows .. '" colspan="5">')
end
prnt(getVersionLink(args.link or 'ver', args[2], false))
prnt('</th>')
end
if(args.snap ~= nil) then
prnt('<th colspan="3" rowspan="' .. snapRows .. '">')
prnt(getVersionLink(args.slink or 'ver', args.snap, true))
prnt('</th>')
end
prnt('<td>' .. args[3] .. '</td></tr>')
for k,v in ipairs(args) do if(k>3) then prnt('<tr><td>'..v..'</td></tr>') end end --要保证中间不是nil
return
end
function p.getLines(f)
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
end
assert(mw.text.trim(args[1]):sub(-14)=='<!--LineEnd-->')
local stringLines = mw.text.split(mw.text.trim(args[1]):sub(1,-15),'<!--LineEnd-->',true)
local tableLines = {}
local stringArgs
local temp,temp1,temp2
for i,l in ipairs(stringLines) do
tableLines[i] = {}
temp = mw.text.trim(l) or ''
if(temp ~= '') then
stringArgs = mw.text.split(temp,'<!--ArgSep-->',true)
for m,n in ipairs(stringArgs) do
if(n ~= '') then
temp = n:find("=", 1, true)
temp1 = mw.text.trim(n:sub(1, temp - 1))
temp1 = tonumber(temp1) or temp1
temp2 = mw.text.trim(n:sub(temp + 1))
tableLines[i][temp1] = temp2
end
end
end
end
return tableLines
end
function p.printArgs(f)
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( false )
end
local result = ''
for k,v in pairs(args) do
result = result .. k .. '=' .. v .. '<!--ArgSep-->'
end
result = result .. '<!--LineEnd-->'
return result
end
function countConsoleRowspan(platform,version,snapRows)
if((version ~= nil and version == HV[platform]) or (version == nil and HV[platform] ~= nil))
then
HVrowspan[platform][HVindex[platform]] = HVrowspan[platform][HVindex[platform]] + snapRows
return
end
HV[platform] = version or "none"
HVindex[platform] = HVindex[platform] + 1
HVrowspan[platform][HVindex[platform]] = (HVrowspan[platform][HVindex[platform]] or 0) + snapRows
end
function countRowspan(args)
local snapRows = 1
for i,_ in ipairs(args) do
if(i>3) then snapRows = snapRows + 1
end
end --要保证3不是nil
--Header or Foot
if(args[1] ~= nil and args[1] ~= '') then
local mode = (args[1]):lower()
if (mode == 'foot') then
footReset()
return
end
Hmode = editionAlias[mode] or mode
reset()
return
end
--Content rows
if((Hmode == 'console') and (args.xbox or args.xbone or args.ps or args.wiiu or args.switch )) then
Hver = nil
if(args[3] ~= nil and args[3] ~= '') then
snapRows = snapRows + 1
end
countConsoleRowspan("xbox360",args.xbox,snapRows)
countConsoleRowspan("xbone",args.xbone,snapRows)
countConsoleRowspan("ps",args.ps,snapRows)
countConsoleRowspan("wiiu",args.wiiu,snapRows)
countConsoleRowspan("switch",args.switch,snapRows)
return
end
--Other versions:
resetCon()
if((args.snap == nil) or (args[2] and args[2] ~= '' and (args[2] ~= Hver))) then
Hver = nil
if( args.snap ~= nil) then
Hver = args[2]
Hindex = Hindex + 1
end
end
if(args.snap ~= nil) then
Hrowspan[Hindex] = (Hrowspan[Hindex] or 0) + snapRows
end
return
end
function initRowspan()
Hrowspan = {}
HVrowspan = {
xbox360 = {},
xbone = {},
ps = {},
wiiu = {},
switch = {}
}
end
function initRowspanIndex()
Hindex = 0
HVindex = {
xbox360 = 0,
xbone = 0,
ps = 0,
wiiu = 0,
switch = 0
}
end
function p.main(f)
local lines = p.getLines(f)
initRowspan()
initRowspanIndex()
for k,v in ipairs(lines) do
countRowspan(v)
end
initRowspanIndex()
Hhead=0
local result = {}
for k,v in ipairs(lines) do
if(Hhead~=1) then
table.insert(result, '<table class="wikitable" data-description="历史">')
Hhead = 1
end
processLine(v,function(a) table.insert(result, a) end)
end
return table.concat(result)
end
return p