FANDOM


-- For reference data, see [[Module:Ref/data]]
local p = {}
 
-- Load data from [[Module:Ref/data]]
local refTable = mw.loadData('Module:Ref/data')
 
-- Lookup a table with specific key
local function lookup(tbl, key)
  local value = tbl[key]
  if value == nil then
    -- If key is not found, use value of "#default"
    value = tbl["#default"]
  end
 
  -- For legacy reason, "{{{2}}}" may be contained in the value string 
  -- Lua will not parse it as wikitext will do, so we should replace it with key
  -- One can comment the following single line, if and only if 
  -- he is capable of replacing all "{{{2}}}" in [[Module:Ref/data]] with correct key :)
  value = value:gsub("{{{2}}}", key)
 
  return value
end
 
-- Generate the reference sentence
local function gen(book, frame)
  local res = lookup(refTable.src, book)
  local refCode = frame.args[1]
  local note = frame.args[2]
  -- Handle, {{Ref|aGoT}} & {{Ref|aGoT||Hi}}
  if refCode ~= nil and refCode ~= "" then
    res = res .. "," .. lookup(refTable[book], refCode)
  end
  res = res .. "。"
 
  if note ~= nil then
    res = res .. note
  end
 
  return res
end
 
-- Export to be invoked
function p.agot(frame) 
  return gen("agot", frame)
end
 
function p.acok(frame) 
  return gen("acok", frame)
end
 
function p.asos(frame) 
  return gen("asos", frame)
end
 
function p.affc(frame) 
  return gen("affc", frame)
end
 
function p.adwd(frame) 
  return gen("adwd", frame)
end
 
function p.twow(frame) 
  return gen("twow", frame)
end
 
function p.ados(frame) 
  return gen("ados", frame)
end
 
function p.tloiaf(frame) 
  return gen("tloiaf", frame)
end
 
function p.twoiaf(frame) 
  return gen("twoiaf", frame)
end
 
function p.awoiaf(frame) 
  return gen("awoiaf", frame)
end
 
function p.fab(frame)
  return gen("fab", frame)
end
 
function p.thk(frame) 
  return gen("thk", frame)
end
 
function p.thkg(frame)
  return gen("thkg", frame)
end
 
function p.tss(frame) 
  return gen("tss", frame)
end
 
function p.tmk(frame) 
  return gen("tmk", frame)
end
 
function p.tpatq(frame) 
  return gen("tpatq", frame)
end
 
function p.trp(frame) 
  return gen("trp", frame)
end
 
-- Take care of TV reference
function p.tv(frame)
  local res = refTable.src.tv
  local season = frame.args[1]
  local episode = frame.args[2]
  local note = frame.args[3]
  local value = ""
 
  local tbl = refTable.tv
  local tseason = tbl[season]
  if tseason == nil then
    value = tbl["#default"]
    value = value:gsub("{{{2}}}", season)
    if episode ~= nil and episode ~= "" then
      value = value .. "。" .. episode .. "。"
    else
      value = value .. "。"
    end
    res = res .. "。"
  elseif type(tseason) == "string" then
    value = tseason
    local sig = "。"
    if value ~= nil and value ~= "" then
      value = value .. "。"
      sig = ","
    end
    if episode ~= nil and episode ~= "" then
      value = value .. episode .. "。"
      sig = ","
    end
    res = res .. sig
  else
    value = tseason[episode]
    if value == nil then
      value = tseason["#default"]
      value = value:gsub("{{{3}}}", episode)
    end
    if value ~= nil and value ~= "" then
      value = value .. "。"
      res = res .. ","
    else
      res = res .. "。"
    end
  end
 
  if note ~= nil and note ~= "" then
    value = value .. note
  end
 
  return res .. value
end
p.got = p.tv
 
return p
除了特别提示,社区内容遵循CC-BY-SA 授权许可。