跳转到内容

Module:Non-CC Copyrightwarning

轻之舟百科,让知识轻装启航

此模块的文档可以在Module:Non-CC Copyrightwarning/doc创建

local Arguments = require('Module:Arguments')

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 = {

	-- 检测是否CC BY-NC-SA 4.0页面
	cc_by_sa_4_notice = function(page, ctx)
		if page.namespace ~= 8 and page.namespace ~= 12 then return end
		local categories = page.categories
		if hasCategory('CC-BY-NC-SA-4.0', categories) then
			return "NonCommercial editintro"
		end
	end,

	-- 检测是否GPL-3.0页面
	gpl_3_notice = function(page, ctx)
		if page.namespace ~= 8 and page.namespace ~= 12 then return end
		local categories = page.categories
		if hasCategory('GPL-3.0', categories) then
			return "GPL-3.0 editintro"
		end
	end,

	-- 检测是否GPL-2.0-or-later页面
	gpl_2_or_later_notice = function(page, ctx)
		if page.namespace ~= 8 and page.namespace ~= 12 then return end
		local categories = page.categories
		if hasCategory('GPL-2.0-or-later', categories) then
			return "GPL-2.0-or-later editintro"
		end
	end,

	-- 检测是否MIT许可证页面
	mit_notice = function(page, ctx)
		if page.namespace ~= 8 and page.namespace ~= 12 then return end
		local categories = page.categories
		if hasCategory('MIT许可证', categories) then
			return "MIT editintro"
		end
	end,
}

p.core = function(page, frame)
	local text = ''
	for _, getNotice in pairs(notices) do
		local template = getNotice(page)
		text = text .. (template and (frame:expandTemplate{ title = template }) or '')
	end
	return text
end

return p