模組:Mainspace editnotice
外观
| 此模块使用Lua语言: |
本模块用于{{Editnotices/Namespace/Main}}和{{Editnotices/Namespace/Wikipedia}},它有条件地包含其他编辑提示模板。
用法
[编辑]{{#invoke:Mainspace editnotice|main}}
不需要任何参数。如需测试特定页面生成的编辑提示,可将页面标题传入|page=参数。
local Arguments = require('Module:Arguments')
local Disambiguation
local TfaTitle
local lan = require('Module:Lan')
-- 只在判断主命名空间时需要的模块,无需在编辑其他命名空间页面时加载
-- 为方便Special:WhatLinksHere追踪,在模块自己的页面也加载
local function init(page)
if page.namespace == 0 or (page.namespace == 828 and page.rootText == 'Mainspace editnotice') then
if not Disambiguation then Disambiguation = require('Module:Disambiguation') end
if not TfaTitle then TfaTitle = require('Module:TFA title') end
end
end
init(mw.title.getCurrentTitle())
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,
-- 檢測是否最近逝世者條目
rd_notice = function(page)
if page.namespace ~= 0 then return end
local categories = page.categories
if hasCategory('最近逝世', categories) then
return "RD 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 Disambiguation._isDisambiguationPage(page.fullText) 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,
-- 检测是否为典范条目
fa_notice = function(page)
if page.namespace ~= 0 then return end
local categories = page.categories
if hasCategory('典范条目', categories) then
return "FA 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,
-- 本地自定义:[[WP:PEIS]]提示
peis_notice = function(page)
if hasCategory("引用模板后大小超过限制的页面", page.categories) then
return "PEIS 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 = {}
init(page)
local text = ''
for _, getNotice in pairs(notices) do
local template = getNotice(page, context)
if template then
local template_link = '<div class="editnotice-link" style="clear: both; float: right; margin: 0px 0.8em; padding: 0; line-height: 1em;"> <small>[[Template:'..template..'|'..template..']]</small> </div>'
text = text .. template_link .. frame:expandTemplate{ title = template }
end
end
-- Add a link to view and modify the page's editnotice.
-- Not needed if there is no editnotice, because then MediaWiki itself adds
-- the link through [[MediaWiki:Editnotice-notext]].
-- Also skip it if a page editnotice exists, as in that case it probably
-- adds the link, and we want to avoid a duplicate one.
if text ~= '' and not mw.title.new('Template:Editnotices/Page/' .. page.fullText).exists then
text = text .. '<div class="editnotice-link autoconfirmed-show" style="clear: both; float: right; margin: 0px 0.8em; padding: 0; line-height: 1em; display: none"><small>[[Template:Editnotices/Page/'.. page.fullText ..'|' .. lan._main({ ['zh-hans'] = '页面提示', ['zh-hant'] = '頁面提示' }, frame) .. ']]</small></div>'
end
return text
end
return p