模組:Mainspace editnotice
外观
| 此模块使用Lua语言: |
本模块用于{{Editnotices/Namespace/Main}}和{{Editnotices/Namespace/Wikipedia}},它有条件地包含其他编辑提示模板。
用法
[编辑]{{#invoke:Mainspace editnotice|main}}
不需要任何参数。如需测试特定页面生成的编辑提示,可将页面标题传入|page=参数。
local Arguments = require('Module:Arguments')
local Disambiguation = require('Module:Disambiguation')
local TfaTitle = require('Module:TFA title')
local function hasCategory(category, catList)
for _, c in ipairs(catList) do
if c == category then
return true
end
end
return false
end
local p = {}
p.main = function(frame)
local args = Arguments.getArgs(frame)
return p.core(args.page and mw.title.new(args.page) or mw.title.getCurrentTitle(), frame)
end
local notices = {
-- 检测是否存在草稿页面
draft_notice = function (page, ctx)
if page.namespace ~= 0 then return end
if mw.title.new('Draft:'..page.fullText).exists then
return "Draft at"
end
end,
-- 检测是否为在世人物传记条目
-- 由于中文版的[[:Category:在世人物]]是由{{bd}}模板自动添加,所以此处由原本的从Wikitext获取字符串改为获取页面分类的形式实现
blp_notice = function(page)
if page.namespace ~= 0 then return end
local categories = page.categories
if hasCategory('在世人物', categories) then
return "BLP editnotice"
end
end,
-- 检测是否为台湾电视剧条目
tvdrama_notice = function(page)
if page.namespace ~= 0 then return end
local content = page:getContent()
local tvdrama1 = "%[%[%s*[Cc]ategory:%s*%d+年[台臺][湾灣][电電][视視][剧劇]集%s*%|?%s*%S*%s*%]%]"
local tvdrama2 = "%[%[%s*[Cc][Aa][Tt]:%s*%d+年[台臺][湾灣][电電][视視][剧劇]集%s*%|?%s*%S*%s*%]%]"
local tvdrama3 = "%[%[%s*分[类類]:%s*%d+年[台臺][湾灣][电電][视視][剧劇]集%s*%|?%s*%S*%s*%]%]"
local tvdrama4 = "%[%[%s*CATEGORY:%s*%d+年[台臺][湾灣][电電][视視][剧劇]集%s*%|?%s*%S*%s*%]%]"
if content and (mw.ustring.find(content, tvdrama1) or mw.ustring.find(content, tvdrama2) or mw.ustring.find(content, tvdrama3) or mw.ustring.find(content, tvdrama4)) then
return "TVdrama editnotice"
end
end,
-- 检测是否消歧义条目
disambig_notice = function(page, ctx)
if page.namespace ~= 0 then return end
if ctx.isDisambigPage then
return "Disambig editnotice"
end
end,
-- 检测是否为今日典范条目或特色列表
tfa_notice = function(page)
if page.namespace ~= 0 then return end
if TfaTitle.today_title() == page.text then
return "TFA editnotice"
end
end,
-- 中文版特设:维基百科方针与指引页面
policy_notice = function(page)
if page.namespace ~= 4 then return end
local categories = page.categories
if hasCategory('維基百科方針與指引完整列表', categories) then
return "Policy or guideline editnotice"
end
end,
}
p.core = function(page, frame)
-- Context object to store values that are expensive to compute and required
-- in multiple places
local context = {
isDisambigPage = Disambiguation._isDisambiguationPage(page.fullText)
}
local text = ''
for _, getNotice in pairs(notices) do
local template = getNotice(page, context)
text = text .. (template and ('<div class="editnotice-link" style="clear: both; float: right; margin: 0px 0.8em; padding: 0; line-height: 1em;"> <small>[[Template:'..template..'|'..template..']]</small> </div>' .. frame:expandTemplate{ title = template }) or '')
end
return text
end
return p