Module:Non-CC Copyrightwarning

闲敲棋子落灯花​(留言 | 贡献)2026年8月6日 (四) 14:19的版本 (来源:求闻编者,https://www.qiuwenbaike.cn/wiki/Module:Non-CC Copyrightwarning,许可证:CC BY-SA 4.0(https://creativecommons.org/licenses/by-sa/4.0/))
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在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