(// Edit via Wikiplus 测试完成) 标签:手工回退 |
(// Edit via Wikiplus) 标签:已被回退 |
||
第7行: | 第7行: | ||
local function getComicData(episode) |
local function getComicData(episode) |
||
-- 去ComicData.json获取漫画数据 |
-- 去ComicData.json获取漫画数据 |
||
local comicList = mw.text.jsonDecode(mw. |
local comicList = mw.text.jsonDecode(mw.title.new('Template:漫画信息框/ComicData.json'):getContent()) |
||
return comicList[episode] |
return comicList[episode] |
||
第14行: | 第14行: | ||
-- 用模板数据替换自动获取的数据 |
-- 用模板数据替换自动获取的数据 |
||
local data = {} |
local data = {} |
||
-- 当ComicData.json中不存在此话数据时 直接使用模板数据 防止报错 |
|||
⚫ | |||
if data_from_json ~= nil then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
for k, v in pairs(data_from_args) do |
for k, v in pairs(data_from_args) do |
||
if v ~= '' then |
if v ~= '' then |
||
-- 当 |
-- 当自动获取的数据为空值时 使用模板数据 |
||
data[k] = v |
data[k] = v |
||
end |
end |
||
第26行: | 第29行: | ||
return data |
return data |
||
end |
end |
||
local function fillInfobox(data, episode) |
local function fillInfobox(data, episode,fast) |
||
local function argsCheck(args) |
|||
-- 检查缺失数据 生成提示 |
|||
⚫ | |||
if args['color'] == nil then |
|||
noticetext = noticetext .. '<li>此信息框缺少背景色,请添加<code>color</code>参数。</li>' |
|||
⚫ | |||
⚫ | |||
noticetext = noticetext .. '<li>此信息框缺少微博标题,请添加<code>title_weibo</code>参数。</li>' |
|||
end |
|||
⚫ | |||
noticetext = noticetext .. '<li>此信息框缺少B漫标题,请添加<code>title_bili</code>参数。</li>' |
|||
end |
|||
if args['episode'] == nil then |
|||
noticetext = noticetext .. '<li>此信息框缺少时间线,请添加<code>episode</code>参数。</li>' |
|||
end |
|||
⚫ | |||
noticetext = noticetext .. '<li>此信息框缺少微博发布时间,请添加<code>date_weibo</code>参数。</li>' |
|||
end |
|||
⚫ | |||
noticetext = noticetext .. '<li>此信息框缺少B漫发布时间,请添加<code>date_bili</code>参数。</li>' |
|||
end |
|||
if noticetext == '' then |
|||
return noticetext |
|||
end |
|||
--我知道这里写死很不礼貌 但是能用就懒得管了 少调一个模板榨点性能 |
|||
⚫ | |||
return '<table class="mw-collapsible mw-collapsed wikitable"><tr><th>信息框提示</th></tr><tr><td>' .. |
|||
⚫ | |||
noticetext .. '</td></tr></table>' |
|||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local frame = mw.getCurrentFrame() |
local frame = mw.getCurrentFrame() |
||
local res = '' |
|||
local noticetext = '' |
|||
⚫ | |||
for key, value in pairs(args) do |
|||
--检查缺失数据 |
|||
if fast == 0 then |
|||
local forcheck_args = { |
|||
res[#res + 1] = frame:expandTemplate { title = 'nowiki', args = { text } } |
|||
color = data['color'], |
|||
title_weibo = data['title_weibo'], |
|||
title_bili = data['title_bili'], |
|||
episode = data['episode'], |
|||
date_weibo = data['date_weibo'], |
|||
date_bili = data['date_bili'], |
|||
number = episode |
|||
} |
|||
noticetext = argsCheck(forcheck_args) |
|||
end |
end |
||
res[#res + 1] = frame:expandTemplate { title = 'nowiki', args = { '}}' } } |
|||
⚫ | |||
⚫ | |||
--return mw.getCurrentFrame():expandTemplate { title = 'Infobox', args = args } |
|||
-- 添加缺失数据提示 |
|||
if noticetext ~= '' then |
|||
res = res .. noticetext |
|||
end |
|||
⚫ | |||
end |
end |
||
第58行: | 第92行: | ||
local episode = 1 |
local episode = 1 |
||
-- 获取话数 |
-- 获取话数 |
||
if args[1] ~= nil then |
if tonumber(args[1]) ~= nil then |
||
episode = tonumber(args[1]) |
episode = tonumber(args[1]) |
||
end |
end |
||
if args['number'] ~= nil then |
if tonumber(args['number']) ~= nil then |
||
episode = tonumber(args['number']) |
episode = tonumber(args['number']) |
||
end |
end |
||
--模板数据齐全时直接使用模板数据 |
|||
if args['color'] ~= nil and args['color'] ~= nil and args['title_weibo'] ~= nil and args['title_bili'] ~= nil and args['episode'] ~= nil and args['date_weibo'] ~= nil and args['date_bili'] then |
|||
return fillInfobox(args, episode,1) |
|||
end |
|||
--获取自动补全用的数据 |
|||
local episodeData_autoFill = getComicData(episode) |
local episodeData_autoFill = getComicData(episode) |
||
--合并数据 |
|||
local episodeData = margeData(episodeData_autoFill, args) |
local episodeData = margeData(episodeData_autoFill, args) |
||
--生成信息框 |
|||
return fillInfobox(episodeData, episode) |
return fillInfobox(episodeData, episode,0) |
||
end |
end |
||
2023年9月2日 (六) 20:24的版本
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame)
local function getComicData(episode)
-- 去ComicData.json获取漫画数据
local comicList = mw.text.jsonDecode(mw.title.new('Template:漫画信息框/ComicData.json'):getContent())
return comicList[episode]
end
local function margeData(data_from_json, data_from_args)
-- 用模板数据替换自动获取的数据
local data = {}
-- 当ComicData.json中不存在此话数据时 直接使用模板数据 防止报错
if data_from_json ~= nil then
for k, v in pairs(data_from_json) do
data[k] = v
end
end
for k, v in pairs(data_from_args) do
if v ~= '' then
-- 当自动获取的数据为空值时 使用模板数据
data[k] = v
end
end
return data
end
local function fillInfobox(data, episode,fast)
local function argsCheck(args)
-- 检查缺失数据 生成提示
local noticetext = ''
if args['color'] == nil then
noticetext = noticetext .. '<li>此信息框缺少背景色,请添加<code>color</code>参数。</li>'
end
if args['title_weibo'] == nil then
noticetext = noticetext .. '<li>此信息框缺少微博标题,请添加<code>title_weibo</code>参数。</li>'
end
if args['title_bili'] == nil then
noticetext = noticetext .. '<li>此信息框缺少B漫标题,请添加<code>title_bili</code>参数。</li>'
end
if args['episode'] == nil then
noticetext = noticetext .. '<li>此信息框缺少时间线,请添加<code>episode</code>参数。</li>'
end
if args['date_weibo'] == nil then
noticetext = noticetext .. '<li>此信息框缺少微博发布时间,请添加<code>date_weibo</code>参数。</li>'
end
if args['date_bili'] == nil then
noticetext = noticetext .. '<li>此信息框缺少B漫发布时间,请添加<code>date_bili</code>参数。</li>'
end
if noticetext == '' then
return noticetext
end
--我知道这里写死很不礼貌 但是能用就懒得管了 少调一个模板榨点性能
return '<table class="mw-collapsible mw-collapsed wikitable"><tr><th>信息框提示</th></tr><tr><td>' ..
noticetext .. '</td></tr></table>'
end
local frame = mw.getCurrentFrame()
local res = ''
local noticetext = ''
--检查缺失数据
if fast == 0 then
local forcheck_args = {
color = data['color'],
title_weibo = data['title_weibo'],
title_bili = data['title_bili'],
episode = data['episode'],
date_weibo = data['date_weibo'],
date_bili = data['date_bili'],
number = episode
}
noticetext = argsCheck(forcheck_args)
end
res = res .. frame:expandTemplate { title = 'Template:漫画信息框/信息框', args = data }
-- 添加缺失数据提示
if noticetext ~= '' then
res = res .. noticetext
end
return res
end
-- 默认输出第一话的信息框
local episode = 1
-- 获取话数
if tonumber(args[1]) ~= nil then
episode = tonumber(args[1])
end
if tonumber(args['number']) ~= nil then
episode = tonumber(args['number'])
end
--模板数据齐全时直接使用模板数据
if args['color'] ~= nil and args['color'] ~= nil and args['title_weibo'] ~= nil and args['title_bili'] ~= nil and args['episode'] ~= nil and args['date_weibo'] ~= nil and args['date_bili'] then
return fillInfobox(args, episode,1)
end
--获取自动补全用的数据
local episodeData_autoFill = getComicData(episode)
--合并数据
local episodeData = margeData(episodeData_autoFill, args)
--生成信息框
return fillInfobox(episodeData, episode,0)
end
return p