Module:License scope

Documentation for this module may be created at Module:License scope/doc

--[=[
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 = "Some or all works "
		else
			text = "Works "
		end
		if namespace == "Author" or namespace == "Author talk" then
			text = text .. "by this author"
		elseif namespace == "Portal" or namespace == "Portal talk" then
			text = text .. "listed in this portal"
		elseif namespace == "Category" or namespace == "Category talk" then
			text = text .. "in this category"
		end
	elseif namespace == "File" or namespace == "File talk" then
		text = "This file"
	elseif namespace == "Image" or namespace == "Image talk" then
		text = "This image"
	else
		text = "This work"
	end
	
	local useverb = yesno(args.useverb) or args.useverb == nil
	if useverb then
		local past = yesno(args.past or 'no')
		if past and p.plural_namespace() then
			text = text .. " were"
		elseif past then
			text = text .. " was"
		elseif p.plural_namespace() then
			text = text .. " are"
		else
			text = text .. " is"
		end
	end
	
	if yesno(args.lc or 'no') then
		text = string.lower(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