第1行: |
第1行: |
− | local SMWUtils = require("Module:SMWUtils")
| |
− | local PageName = require("Module:PageName")
| |
| local p = {} | | local p = {} |
| | | |
− | function p.display_title(frame) | + | function p.split(s) |
− | local pagename = mw.title.getCurrentTitle().text
| |
− | local node = mw.html.create(nil)
| |
− | local type_flag, group_name, page_name
| |
| local parent, name | | local parent, name |
− | base, sub = PageName.split(pagename) | + | parent, name = s:match("^(.+)/(.+)$") |
− | if base then
| + | return parent, name |
− | node:wikitext(sub)
| |
− | node:tag("span"):addClass("ifw-basepagename"):wikitext(" ("..base..")")
| |
− | else
| |
− | node:wikitext(page_name)
| |
− | end
| |
− | local code = node:done()
| |
− | return code | |
| end | | end |
| | | |
− | function renderMaintainers(frame, maintainers, other_creators) | + | function p.rsplit(s) |
− | local node = mw.html.create(nil)
| + | return s:match("^([^/]+)/(.+)$") |
− | local content = "" | |
− | content = content .. "创作者: "
| |
− | local l = {}
| |
− | local il = 1
| |
− | for i, m in ipairs(maintainers) do
| |
− | local n = m:match("^用户:(.+)$")
| |
− | local s = ""
| |
− | s = s .. "[[用户:"..n.."|"..n.."]]"
| |
− | s = s .. "[[Category:由"..n.."维护的条目]]"
| |
− | s = s .. "[[Category:由"..n.."创作的条目]]"
| |
− | l[il] = s
| |
− | il = il + 1
| |
− | mw.smw.set({
| |
− | ['Editable by user'] = 'User:'..n
| |
− | })
| |
− | end
| |
− | for i, m in ipairs(other_creators) do
| |
− | local n = m:match("^创作者:(.+)$")
| |
− | local s = ""
| |
− | s = s .. "[[创作者:"..n.."|"..n.."]]"
| |
− | s = s .. "[[Category:由"..n.."创作的条目]]"
| |
− | l[il] = s
| |
− | il = il + 1
| |
− | end
| |
− | content = content .. mw.text.listToText(l)
| |
− | local args = {image = 'Copyright.svg', content = content}
| |
− | return frame:expandTemplate{title = "LiteInfoBox", args = args}
| |
| end | | end |
| | | |
− | function renderLockedPage(frame)
| + | local type2name = { |
− | mw.smw.set({
| + | ['W'] = "世界观", |
− | ['Editable by'] = 'whitelist'
| + | ['X'] = "联动" |
− | })
| + | } |
− | return frame:expandTemplate{title = "本页面仅允许维护者编辑", args = {}}
| |
− | end
| |
| | | |
− | function renderLiteInfoBox(frame, image, content) | + | function p.type_name(s) |
− | local args = {
| + | return type2name[s] |
− | image = image,
| |
− | content = content
| |
− | }
| |
− | return frame:expandTemplate{title = "LiteInfoBox", args = args} | |
| end | | end |
| | | |
− | function renderStage(frame, stage) | + | function p.parse(s) |
− | return frame:expandTemplate{title = "创作阶段", args = {["创作阶段"]=stage}}
| + | local type_flag, full_name |
− | end
| + | type_flag, full_name = s:match("^([XW])/(.+)$") |
− | | + | if type_flag then |
− | function getParentProps(base, props)
| + | local base, sub |
− | return SMWUtils.query_page_properties("[["..base.."]]", props)[1]["properties"]
| + | base, sub = p.rsplit(full_name) |
− | end
| + | if base then |
− | | + | return type_flag, base, sub |
− | function renderType(frame, isIndexPage, type, relGroup)
| + | else |
− | local pagename = PageName.getPageName() | + | return type_flag, full_name, nil |
− | local parent, name
| |
− | base, sub = PageName.split(pagename) | |
− | local out = ""
| |
− | if isIndexPage or not base then
| |
− | mw.smw.set({['设定集'] = pagename})
| |
− | if type == "世界观设定" then
| |
− | mw.smw.set({['设定类型'] = "世界观设定"})
| |
− | out = out .. (renderLiteInfoBox(frame, "WorldItem.svg", "世界观介绍页"))
| |
− | out = out .. "[[Category:世界观介绍页]]"
| |
− | out = out .. "[[Category:世界观设定]]"
| |
− | elseif type == "联动设定" then
| |
− | local text = ""
| |
− | out = out .. (renderLiteInfoBox(frame, "联动.svg", "联动介绍页"))
| |
− | mw.smw.set({['设定类型'] = "联动设定"})
| |
− | out = out .. "[[Category:联动介绍页]]"
| |
− | out = out .. "[[Category:联动设定]]"
| |
− | else -- 公共设定
| |
− | out = out .. (renderLiteInfoBox(frame, "SharedItem.svg", "公共设定页"))
| |
− | mw.smw.set({['设定类型'] = "公共设定"})
| |
− | out = out .. "[[Category:公共设定]]"
| |
− | end
| |
− | else -- base must exist | |
− | local parent = getParentProps(base, {"设定集", "设定类型"}) | |
− | local parentGroup = parent["设定集"][1] | |
− | if parentGroup then
| |
− | mw.smw.set({['设定集'] = parentGroup})
| |
− | end
| |
− | local parentType = parent["设定类型"][1] or "公共设定"
| |
− | mw.smw.set({['设定类型'] = parentType})
| |
− | if parentType == "世界观设定" then | |
− | out = out .. (renderLiteInfoBox(frame, "WorldItem.svg", "本页面属于世界观: [[" .. base .. "]]")) | |
− | out = out .. "[[Category:世界观设定]]"
| |
− | elseif parentType == "联动设定" then
| |
− | local text = ""
| |
− | out = out .. (renderLiteInfoBox(frame, "联动.svg", "本页面属于联动: [["..base.."]]"))
| |
− | out = out .. "[[Category:联动设定]]"
| |
− | else -- 公共设定 | |
− | out = out .. (renderLiteInfoBox(frame, "SharedItem.svg", "公共设定页")) | |
− | out = out .. "[[Category:公共设定]]"
| |
| end | | end |
| + | else |
| + | return nil, nil, s |
| end | | end |
− | return out
| |
| end | | end |
| | | |
− | -- function p.test()
| + | function p.getPageName() |
− | -- mw.logObject(getParentProps("测试设定", {"设定集", "设定类型"}))
| + | return mw.title.getCurrentTitle().text |
− | -- end
| |
− | | |
− | function p.renderCreator(frame)
| |
− | local title = PageName.getPageName()
| |
− | local prop_names = {"维护者", "创作者", "输入设定类型", "设定集核心页", "依赖设定集", "仅允许维护者编辑", "创作阶段", "上级概念", "前置条件", "事后效果"}
| |
− | local props = SMWUtils.query_page_properties("[["..title.."]]", prop_names)[1]["properties"]
| |
− | local root = mw.html.create("div")
| |
− | root:attr("style", "display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, auto)); width: 100%")
| |
− | local maintainerTemp = renderMaintainers(frame, props["维护者"], props["创作者"])
| |
− |
| |
− | root:wikitext(maintainerTemp)
| |
− | if props["仅允许维护者编辑"][1] == "t" then
| |
− | root:wikitext(renderLockedPage(frame))
| |
− | end
| |
− | local isIndexPage = props["设定集核心页"][1] == 't'
| |
− | local typeNode = renderType(frame, isIndexPage, props["输入设定类型"][1] or "公共设定", props["依赖设定集"])
| |
− | root:wikitext(typeNode)
| |
− | root:wikitext(renderStage(frame, props["创作阶段"][1] or "空白"))
| |
− | return root:done()
| |
| end | | end |
− |
| |
− |
| |
| | | |
| return p | | return p |