“模块:创作者信息”的版本间的差异
跳到导航
跳到搜索
(建立内容为“local StringUtils = require("Module:StringUtils") local ListUtils = require("Module:ListUtils") local p = {} function _missing_maintainer(frame) return frame…”的新页面) |
|||
(未显示同一用户的13个中间版本) | |||
第14行: | 第14行: | ||
return frame:expandTemplate{title = "创作者信息/委托发布", args = { | return frame:expandTemplate{title = "创作者信息/委托发布", args = { | ||
['创作者'] = creator, ['维护者']=maintainer}} | ['创作者'] = creator, ['维护者']=maintainer}} | ||
+ | end | ||
+ | |||
+ | function _set_editable_by_user(user) | ||
+ | local nm = 'User:'..user | ||
+ | mw.smw.set({ | ||
+ | ['Editable by user'] = nm | ||
+ | }) | ||
end | end | ||
function _other_maintainers(frame, other_maintainers) | function _other_maintainers(frame, other_maintainers) | ||
− | local | + | local node = mw.html.create(nil) |
− | return frame:expandTemplate{title = " | + | node:wikitext("合作维护者: ") |
+ | for i, m in ipairs(other_maintainers) do | ||
+ | node:wikitext("[[User:"..m.."|"..m.."]]") | ||
+ | node:wikitext("[[Category:由"..m.."维护的条目]]") | ||
+ | _set_editable_by_user(m) | ||
+ | mw.smw.set({ | ||
+ | ['维护者'] = ("User:"..m) | ||
+ | }) | ||
+ | end | ||
+ | local res = node:done() | ||
+ | local args = {image = 'Brainstorm.svg', content = mw.dumpObject(res)} | ||
+ | return frame:expandTemplate{title = "LiteInfoBox", args = args} | ||
+ | end | ||
+ | |||
+ | function _maintainer_only(frame, maintainer) | ||
+ | mw.smw.set({ | ||
+ | ['Editable by'] = 'whitelist' | ||
+ | }) | ||
+ | return frame:expandTemplate{title = "本页面仅允许维护者编辑", args = {}} | ||
end | end | ||
function p.render(frame) | function p.render(frame) | ||
local creator = StringUtils.assert_not_empty(frame.args["创作者"]) | local creator = StringUtils.assert_not_empty(frame.args["创作者"]) | ||
+ | local maintainer_only = StringUtils.assert_not_empty(frame.args["仅允许维护者编辑"]) | ||
local maintainer = StringUtils.assert_not_empty(frame.args["维护者"]) | local maintainer = StringUtils.assert_not_empty(frame.args["维护者"]) | ||
local other_maintainers = StringUtils.split_or_empty(frame.args["合作维护者列表"], ",") | local other_maintainers = StringUtils.split_or_empty(frame.args["合作维护者列表"], ",") | ||
local result | local result | ||
− | if not creator then | + | if not creator and maintainer then |
creator = maintainer | creator = maintainer | ||
+ | elseif not maintainer and creator then | ||
+ | maintainer = creator | ||
end | end | ||
if maintainer then | if maintainer then | ||
第36行: | 第64行: | ||
result = _proxy_post(frame, creator, maintainer) | result = _proxy_post(frame, creator, maintainer) | ||
end | end | ||
− | + | if maintainer_only == "是" then | |
− | + | result = result .. _maintainer_only(frame, maintainer) | |
− | + | end | |
− | + | _set_editable_by_user(maintainer) | |
else | else | ||
result = _missing_maintainer(frame) | result = _missing_maintainer(frame) | ||
第45行: | 第73行: | ||
if other_maintainers[1] then | if other_maintainers[1] then | ||
− | + | local newcode = _other_maintainers(frame, other_maintainers) | |
+ | result = result .. newcode | ||
end | end | ||
2021年7月4日 (日) 15:27的最新版本
此模块的文档可以在模块:创作者信息/doc创建
local StringUtils = require("Module:StringUtils") local ListUtils = require("Module:ListUtils") local p = {} function _missing_maintainer(frame) return frame:expandTemplate{title = "无维护者警告", args = {}} end function _self_post(frame, creator) return frame:expandTemplate{title = "创作者信息/本人发布", args = {['创作者'] = creator}} end function _proxy_post(frame, creator, maintainer) return frame:expandTemplate{title = "创作者信息/委托发布", args = { ['创作者'] = creator, ['维护者']=maintainer}} end function _set_editable_by_user(user) local nm = 'User:'..user mw.smw.set({ ['Editable by user'] = nm }) end function _other_maintainers(frame, other_maintainers) local node = mw.html.create(nil) node:wikitext("合作维护者: ") for i, m in ipairs(other_maintainers) do node:wikitext("[[User:"..m.."|"..m.."]]") node:wikitext("[[Category:由"..m.."维护的条目]]") _set_editable_by_user(m) mw.smw.set({ ['维护者'] = ("User:"..m) }) end local res = node:done() local args = {image = 'Brainstorm.svg', content = mw.dumpObject(res)} return frame:expandTemplate{title = "LiteInfoBox", args = args} end function _maintainer_only(frame, maintainer) mw.smw.set({ ['Editable by'] = 'whitelist' }) return frame:expandTemplate{title = "本页面仅允许维护者编辑", args = {}} end function p.render(frame) local creator = StringUtils.assert_not_empty(frame.args["创作者"]) local maintainer_only = StringUtils.assert_not_empty(frame.args["仅允许维护者编辑"]) local maintainer = StringUtils.assert_not_empty(frame.args["维护者"]) local other_maintainers = StringUtils.split_or_empty(frame.args["合作维护者列表"], ",") local result if not creator and maintainer then creator = maintainer elseif not maintainer and creator then maintainer = creator end if maintainer then if maintainer == creator then result = _self_post(frame, creator) else result = _proxy_post(frame, creator, maintainer) end if maintainer_only == "是" then result = result .. _maintainer_only(frame, maintainer) end _set_editable_by_user(maintainer) else result = _missing_maintainer(frame) end if other_maintainers[1] then local newcode = _other_maintainers(frame, other_maintainers) result = result .. newcode end return result end return p