Module:PD-US-notice

From Wikisource
Jump to navigation Jump to search

--[=[
Implements PD-US-[no/defective]-notice templates
]=]

local p = {} --p stands for package

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

local function notice_basic_text(post_1977, no_notice, deathyear)
	local published_floor
	local published_ceiling
	local published_suffix
	if post_1977 then
		published_floor = 1978
		published_ceiling = "March 1, 1989"
		published_suffix = ", and without subsequent [https://cocatalog.loc.gov copyright registration] with the U.S. Copyright Office within 5 years"
	else
		published_floor = PD.PD_US_cutoff
		published_ceiling = 1977
		published_suffix = ""
	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"}) .. " ''[[United States Code/Title 17/Chapter 1/Section 101#publication|legally published]]'' within the United States (or the United Nations Headquarters in New York subject to Section 7 of the [[United States Headquarters Agreement]]) between " .. published_floor .. " and " .. published_ceiling .. " (inclusive) "
	if no_notice then
		text = text .. "without a copyright notice" .. published_suffix .. "."
	else
		text = text .. "with a '''''defective''''' copyright notice" .. published_suffix .. ". " .. PD.license_grammar({"The copyright notice in this work contains", "The copyright notices in these works contain"}) .. " at least one of the following defects:"
		local defects = {
			'\n* Notice does not include the copyright symbol ©, the word "Copyright", or the abbreviation "Copr.";',
			'\n* Notice is dated more than one year later than the actual date of first publication;',
			'\n* Notice does not include a named claimant or does not name the actual copyright holder;',
			'\n* Notice is illegible or concealed from view;',
			'\n* The work is a printed literary, musical, or dramatic work whose copyright notice does not include the year.'
		}
		text = text .. table.concat(defects) .. "\nA defective notice does not invalidate copyright in cases where the error is immaterial and would not mislead an infringer, such as an abbreviated name."
	end
	return text
end

function p._PD_US_notice(args)
	local deathyear = PD.getAuthorDeathYear({args[1], args.deathyear})
	local pubyear = PD.getPublicationYear({args[2], args.pubyear})
	local pubmonth = tonumber(args[3]) or tonumber(args.pubmonth)
	local pubday = tonumber(args[4]) or tonumber(args.pubday)
	
	local template = args.template
	local no_notice = template == "PD-US-no-notice" or template == "PD-US-no-notice-post-1977"
	local post_1977 = template == "PD-US-no-notice-post-1977" or template == "PD-US-defective notice-post-1977"
	local film = args.film
	
	-- Is this template appropriate?
	local use_PD_US = (not post_1977 and 1977 < PD.PD_US_cutoff) or (pubyear and pubyear < PD.PD_US_cutoff)
	
	local template_does_not_apply = false
	if pubyear and post_1977 then
		template_does_not_apply = pubyear <= 1977 or pubyear > 1989 or (pubyear == 1989 and pubmonth and pubmonth > 3) or (pubyear == 1989 and pubmonth == 3 and pubday and pubday > 1)
	elseif pubyear then
		template_does_not_apply = pubyear > 1977
	end
	
	if use_PD_US then
		return require('Module:PD-US')._PD_US({['deathyear'] = deathyear, ['category'] = args.category})
	elseif template_does_not_apply then
		if post_1977 then
			return PD.error_text(template .. " only applies to works published between 1978 and March 1, 1989 (inclusive).", template)
		else
			return PD.error_text(template .. " only applies to works published before 1978.", template)
		end
	end
	
	return PD.license({
		['image'] = PD.PD_image,
		['image_r'] = PD.US_flag_image,
		['text'] = notice_basic_text(post_1977, no_notice, deathyear) .. PD.shorter_term_text(deathyear, film),
		['category'] = args.category or template
	})
end

function p.PD_US_notice(frame)
	return p._PD_US_notice(getArgs(frame))
end

return p