Pergi ke kandungan

Modul:PD-US

Daripada Wikisumber
--[=[
Implements [[Template:PD-US]]
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local PD = require('Module:PD')

function p._PD_US(args)
	local deathyear = PD.getAuthorDeathYear({args[1], args.deathyear})
	local pubyear = PD.getPublicationYear({args[2], args.pubyear})
	local film = args.film
	local category = args.category
	local template = "PD-US"
	
	-- Is this work after the cutoff date?
	if pubyear and pubyear >= PD.PD_US_cutoff then
		return PD.error_text(template .. " does not apply to works published after " .. PD.PD_US_cutoff - 1 .. ".", template)
	end
	
	-- Should we use PD-old?
	if deathyear and PD.currentyear - deathyear > 100 then
		return require('Module:PD-old')._PD_old({['category'] = category})
	end
	
	local published_info
	if pubyear then
		published_info = "in " .. pubyear .. ", before the cutoff of January 1, " .. PD.PD_US_cutoff
	else
		published_info = "before January 1, " .. PD.PD_US_cutoff
	end
	local text = PD.license_scope() .. " in the '''[[w:public domain|public domain]]''' in the '''United States''' because " .. PD.license_grammar({"it was", "they were"}) .. " published " .. published_info .. "." .. PD.shorter_term_text(deathyear, film)
	
	return PD.license({
		['image'] = PD.PD_image,
		['image_r'] = PD.US_flag_image,
		['text'] = text,
		['category'] = category or PD.category_with_deathyear_floor("PD", deathyear) .. "-US"
	})
end

function p.PD_US(frame)
	return p._PD_US(getArgs(frame))
end

return p