跳转到内容

Module:License scope

維基文庫,自由的圖書館
文档图示 模块文档[创建]
--[=[
Implements [[Template:License scope]] and [[Template:License grammar]]
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

local namespace = mw.title.getCurrentTitle().nsText

function p.plural_namespace()
	local plural_namespaces = {
		["Author"] = true,
		["Author talk"] = true,
		["Portal"] = true,
		["Portal talk"] = true,
		["Category"] = true,
		["Category talk"] = true
	}
	return plural_namespaces[namespace] or false
end

--[=[
Implements [[Template:License scope]]
]=]

function p._license_scope(args)
	if not args then
		args = {}
	end
	
	local text
	if p.plural_namespace() then
		local usesome
		if namespace == "Category" or namespace == "Category talk" then
			usesome = yesno(args.usesome or 'no')
		else
			usesome = yesno(args.usesome or 'yes')
		end
		if usesome then
			text = "的部分或全部作品"
		else
			text = "的全部作品"
		end
		if namespace == "Author" or namespace == "Author talk" then
			text = "本作者" .. text
		elseif namespace == "Portal" or namespace == "Portal talk" then
			text = "本导览中列出" .. text
		elseif namespace == "Category" or namespace == "Category talk" then
			text = "本分类" .. text
		end
	elseif namespace == "File" or namespace == "File talk" then
		text = "本文件"
	elseif namespace == "Image" or namespace == "Image talk" then
		text = "本图像"
	else
		text = "本作品"
	end
	
	return text
end

function p.license_scope(frame)
	return p._license_scope(getArgs(frame))
end

--[=[
Implements [[Template:License grammar]]
]=]

function p._license_grammar(args)
	if not args then
		args = {}
	end
	if p.plural_namespace() then
		return args[2]
	else
		return args[1]
	end
end

function p.license_grammar(frame)
	return p._license_grammar(getArgs(frame))
end

return p