Модул:PD

Од Wikisource

Документацијата за овој модул можете да ја создадете на Модул:PD/док

--[=[
Implements PD templates
]=]
local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local error_function = require('Module:Error')['error']
local license_scope = require('Module:License_scope')._license_scope
local license_grammar = require('Module:License_scope')._license_grammar

--p.license = require('Module:License')._license -- not working yet
function p.license(args)
	return mw.getCurrentFrame():expandTemplate {
		['title'] = 'License',
		['args'] = args
	}
end

p.currentyear = tonumber(os.date("%Y"))
p.currentmonth = tonumber(os.date("%m"))
p.currentday = tonumber(os.date("%d"))
p.PD_US_cutoff = math.min(p.currentyear - 95, 1978)
p.namespace = mw.title.getCurrentTitle().nsText
p.PD_image = 'PD-icon.svg'
p.US_flag_image = 'Flag of the United States.svg'

--[=[
Generates error license
]=]
function p.error_text(text, basecat)
	local category
	if basecat then
		category = basecat .. "-possible-copyright-violations"
	else
		category = "Possible copyright violations"
	end
	local frame = mw.getCurrentFrame()
	return p.license({
		['image'] = 'PDmaybe-icon.svg',
		['category'] = category,
		['text'] = error_function({text})
	})
end

--[=[
Handle year bucketing
]=]
function p.year_floor(cutoffs, year)
	if year then
		table.sort(cutoffs, function(a, b) return a > b end)
		for k, cutoff in pairs(cutoffs) do
			if p.currentyear - year > cutoff then
				return cutoff
			end
		end
	end
	return nil
end

--[=[
[category]-[year bucket] or [category]
]=]
function p.category_with_year_floor(category, cutoffs, year)
	local year_floor = p.year_floor(cutoffs, year)
	if year_floor then
		return category .. "-" .. year_floor
	else
		return category
	end
end

--[=[
[category]-old-[year bucket] or [category]
]=]
function p.category_with_deathyear_floor(category, year)
	local year_floor = p.year_floor({100, 99, 96, 95, 80, 75, 70, 60, 50, 30, 25}, year)
	if year_floor then
		return category .. "-old-" .. year_floor
	else
		return category
	end
end

function p.frame_category_with_deathyear_floor(frame)
	local args = getArgs(frame)
	return p.category_with_deathyear_floor(args[1] or args.category, args[2] or args.year or args.deathyear)
end

--[=[
Text about where else a work is PD
]=]
function p.shorter_term_text(deathyear)
	local text = "\n----\n"
	if deathyear then
		text = text .. "Авторот починал во " .. deathyear .. ", така што " .. license_grammar({"ова дело е", "овие дела се"}) .. " во '''јавна сопственост''' во земји и области каде што авторското право трае ''' " .. p.currentyear - deathyear - 1 .. " години од смртта на авторот или помалку'''. "
	end
	text = text .. license_grammar({"Ова дело", "These works"}) .. " можеби е во '''јавна сопственост''' во земји и области каде што авторските права за ''странски дела'' траат пократко."
	return text
end

return p