“模板:设定页v2”的版本间的差异

来自iFx Wiki
跳到导航 跳到搜索
第1行: 第1行:
<noinclude>
+
local SMWUtils = require("Module:SMWUtils")
这是“设定页v2”模板。调用它时应该采用如下格式:
+
local PageName = require("Module:PageName")
<pre>
+
local p = {}
{{设定页v2
+
 
|维护者=
+
function p.display_title(frame)
|创作者=
+
    local pagename = mw.title.getCurrentTitle().text
|设定集核心页=
+
    local node = mw.html.create(nil)
|设定类型=
+
    local type_flag, group_name, page_name
|创作阶段=
+
    local parent, name
}}
+
    base, sub = PageName.split(pagename)
</pre>
+
    if base then
编辑页面以阅读模板文本。
+
        node:wikitext(sub)
</noinclude><includeonly>
+
        node:tag("span"):addClass("ifw-basepagename"):wikitext(" ("..base..")")
<div style="display: none">
+
    else
{{#arraymap:{{{维护者|}}}|,|x|[[维护者::x]]}}
+
        node:wikitext(page_name)
{{#arraymap:{{{创作者|}}}|,|x|[[创作者::x]]}}
+
    end
[[设定集核心页::{{{设定集核心页|}}}]]
+
    local code = node:done()
[[设定类型::{{{设定类型|}}}]]
+
    return code
{{#arraymap:{{{依赖设定集|}}}|,|x|[[依赖设定集::x]]}}
+
end
[[仅允许维护者编辑::{{{仅允许维护者编辑|}}}]]
+
 
[[创作阶段::{{{创作阶段|}}}]]
+
function renderMaintainers(frame, maintainers, other_creators)
{{#arraymap:{{{上级概念|}}}|,|x|[[上级概念::x]]}}
+
    local node = mw.html.create(nil)
{{#arraymap:{{{前置条件|}}}|,|x|[[前置条件::x]]}}
+
    local content = ""
{{#arraymap:{{{事后效果|}}}|,|x|[[事后效果::x]]}}
+
    content = content .. "创作者: "
</div>
+
    for i, m in ipairs(maintainers) do
{{DISPLAYTITLE:{{#invoke:设定页v2|display_title}} }}
+
        content = content .. "[[User:"..m.."|"..m.."]]"
{{#invoke:设定页v2|renderCreator}}
+
        content = content .. "[[Category:由"..m.."维护的条目]]"
[[分类:设定页v2]]
+
        content = content .. "[[Category:由"..m.."创作的条目]]"
</includeonly>
+
        mw.smw.set({
 +
            ['Editable by user'] = 'User:'..m
 +
        })
 +
    end
 +
    for i, m in ipairs(other_creators) do
 +
        content = content .. "[[创作者:"..m.."|"..m.."]]"
 +
        content = content .. "[[Category:由"..m.."创作的条目]]"
 +
    end
 +
    local args = {image = 'Copyright.svg', content = content}
 +
    return frame:expandTemplate{title = "LiteInfoBox", args = args}
 +
end
 +
 
 +
function renderLockedPage(frame)
 +
    mw.smw.set({
 +
        ['Editable by'] = 'whitelist'
 +
    })
 +
    return frame:expandTemplate{title = "本页面仅允许维护者编辑", args = {}}
 +
end
 +
 
 +
function renderLiteInfoBox(frame, image, content)
 +
    local args = {
 +
        image = image,
 +
        content = content
 +
    }
 +
    return frame:expandTemplate{title = "LiteInfoBox", args = args}
 +
end
 +
 
 +
function renderStage(frame, stage)
 +
    return frame:expandTemplate{title = "创作阶段", args = {["创作阶段"]=stage}}
 +
end
 +
 
 +
function renderType(frame, isIndexPage, type, relGroup)
 +
    local pagename = mw.title.getCurrentTitle().text
 +
    local parent, name
 +
    base, sub = PageName.split(pagename)
 +
    local root = mw.html.create(nil)
 +
    if isIndexPage or not base then
 +
        if type == "世界观设定" then
 +
            root:wikitext(renderLiteInfoBox(frame, "WorldItem.svg", "世界观介绍页"))
 +
        elseif type == "联动设定" then
 +
            local text = ""
 +
            root:wikitext(renderLiteInfoBox(frame, "联动.svg", "联动介绍页"))
 +
        else -- 公共设定
 +
            root:wikitext(renderLiteInfoBox(frame, "SharedItem.svg", "公共设定页"))
 +
        end
 +
    else
 +
        if type == "世界观设定" then
 +
            root:wikitext(renderLiteInfoBox(frame, "WorldItem.svg", "本页面属于世界观: [[" .. base .. "]]"))
 +
        elseif type == "联动设定" then
 +
            local text = ""
 +
            root:wikitext(renderLiteInfoBox(frame, "联动.svg", "本页面属于联动: [["..base.."]"))
 +
        else -- 公共设定
 +
            root:wikitext(renderLiteInfoBox(frame, "SharedItem.svg", "公共设定页"))
 +
        end
 +
    end
 +
    return root:done()
 +
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(nil)
 +
    local maintainerTemp = renderMaintainers(frame, props["维护者"], props["创作者"])
 +
   
 +
    root:wikitext(maintainerTemp)
 +
    if props["仅允许维护者编辑"][1] == "t" then
 +
        root:wikitext(renderLockedPage(frame))
 +
    end
 +
    local isIndexPage = props["设定集核心页"][1] == 't'
 +
    root:wikitext(renderType(frame, isIndexPage, props["设定类型"][1] or "公共设定"), props["依赖设定集"])
 +
    root:wikitext(renderStage(frame, props["创作阶段"][1] or "空白"))
 +
    return root:done()
 +
end
 +
 
 +
 
 +
 
 +
return p

2021年7月4日 (日) 16:24的版本

local SMWUtils = require("Module:SMWUtils") local PageName = require("Module:PageName") local p = {}

function p.display_title(frame)

   local pagename = mw.title.getCurrentTitle().text
   local node = mw.html.create(nil)
   local type_flag, group_name, page_name
   local parent, name
   base, sub = PageName.split(pagename)
   if base then
       node:wikitext(sub)
       node:tag("span"):addClass("ifw-basepagename"):wikitext(" ("..base..")")
   else
       node:wikitext(page_name)
   end
   local code = node:done()
   return code

end

function renderMaintainers(frame, maintainers, other_creators)

   local node = mw.html.create(nil)
   local content = ""
   content = content .. "创作者: "
   for i, m in ipairs(maintainers) do
       content = content .. ""..m..""
       content = content .. ""
       content = content .. ""
       mw.smw.set({
           ['Editable by user'] = 'User:'..m
       })
   end
   for i, m in ipairs(other_creators) do
       content = content .. ""..m..""
       content = content .. ""
   end
   local args = {image = 'Copyright.svg', content = content}
   return frame:expandTemplate{title = "LiteInfoBox", args = args}

end

function renderLockedPage(frame)

   mw.smw.set({
       ['Editable by'] = 'whitelist'
   })
   return frame:expandTemplate{title = "本页面仅允许维护者编辑", args = {}}

end

function renderLiteInfoBox(frame, image, content)

   local args = {
       image = image,
       content = content
   }
   return frame:expandTemplate{title = "LiteInfoBox", args = args}

end

function renderStage(frame, stage)

   return frame:expandTemplate{title = "创作阶段", args = {["创作阶段"]=stage}}

end

function renderType(frame, isIndexPage, type, relGroup)

   local pagename = mw.title.getCurrentTitle().text
   local parent, name
   base, sub = PageName.split(pagename)
   local root = mw.html.create(nil)
   if isIndexPage or not base then
       if type == "世界观设定" then
           root:wikitext(renderLiteInfoBox(frame, "WorldItem.svg", "世界观介绍页"))
       elseif type == "联动设定" then
           local text = ""
           root:wikitext(renderLiteInfoBox(frame, "联动.svg", "联动介绍页"))
       else -- 公共设定
           root:wikitext(renderLiteInfoBox(frame, "SharedItem.svg", "公共设定页"))
       end
   else
       if type == "世界观设定" then
           root:wikitext(renderLiteInfoBox(frame, "WorldItem.svg", "本页面属于世界观: " .. base .. ""))
       elseif type == "联动设定" then
           local text = ""
           root:wikitext(renderLiteInfoBox(frame, "联动.svg", "本页面属于联动: [["..base.."]"))
       else -- 公共设定
           root:wikitext(renderLiteInfoBox(frame, "SharedItem.svg", "公共设定页"))
       end
   end
   return root:done()

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(nil)
   local maintainerTemp = renderMaintainers(frame, props["维护者"], props["创作者"])
   
   root:wikitext(maintainerTemp)
   if props["仅允许维护者编辑"][1] == "t" then
       root:wikitext(renderLockedPage(frame))
   end
   local isIndexPage = props["设定集核心页"][1] == 't'
   root:wikitext(renderType(frame, isIndexPage, props["设定类型"][1] or "公共设定"), props["依赖设定集"])
   root:wikitext(renderStage(frame, props["创作阶段"][1] or "空白"))
   return root:done()

end


return p