Modul:Autorinfo

Z Wikizdrojů, volně dostupné knihovny

Účel[editovat]

Modul „Autorinfo“ poskytuje pomocné funkce pro {{Autorinfo}}.

Příklady použití[editovat]

Kód Výsledek Poznámka
copyrightStatus
{{#invoke:Autorinfo|copyrightStatus|31. března 1856}} Dílo je volné
{{#invoke:Autorinfo|copyrightStatus|31. března 2016}} Dílo není volné + Přidává kategorii Kategorie:Autoři:Volní od roku 2087
{{#invoke:Autorinfo|copyrightStatus|1234}} Dílo je volné
monitorArguments
{{#invoke:Autorinfo|monitorArguments}} Chyba skriptu: Funkce „monitorArguments“ neexistuje. Nezobrazí nic, protože jmenný prostor je jiný než 100. Je určeno pro volání z Template:Autorinfo.
monitorSorting
{{#invoke:Autorinfo|monitorSorting}} Chyba skriptu: Funkce „monitorSorting“ neexistuje. Nezobrazí nic, protože jmenný prostor je jiný než 100. Je určeno pro volání z Template:Autorinfo.
processBioDates
{{#invoke:Autorinfo|processBioDates|Narození|foo}} Nezobrazí nic. Neparsovatelné datum narození. Přidává automatickou kategorii Kategorie:Monitoring:Autorinfo/datum narození/(neparsovatelné).
{{#invoke:Autorinfo|processBioDates|Narození|2. července 1861}} Nezobrazí nic. Přidává automatické kategorie Kategorie:Metadata:Narození/rok/1861, Kategorie:Metadata:Narození/roky/1, Kategorie:Metadata:Narození/měsíc/07 a Kategorie:Metadata:Narození/datum/0702.
{{#invoke:Autorinfo|processBioDates|Narození|1922}} Nezobrazí nic. Přidává automatické kategorie Kategorie:Metadata:Narození/rok/1922, Kategorie:Metadata:Narození/roky/2 a Kategorie:Monitoring:Autorinfo/datum narození/(jen rok).

-- @brief
--  Backend for {{Autorinfo}}.
-- 
-- @author
--  [[meta:User:Danny B.]]
local _module = {}
----------------------------------------


local DateTime = require( "Module:DateTime" )


-- @brief
--  Processes the biographical dates.
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Preprocessed wikitext
function _module.processBioDates( frame )
	
	if mw.title.getCurrentTitle().namespace ~= 100 then
		return
	end
	
	local output = ""
	local moduleArgs = frame.args
	
	local variableName = mw.text.trim( moduleArgs[1] or "" )
	local value = mw.text.trim( moduleArgs[2] or "" )
	
	local day
	local month
	local year
	local dateType

	if value ~= "" then
		day, month, year, dateType = DateTime.parseVerbalDate( value )
		if dateType == "DMY" then
			output = output .. string.format( "[[Kategorie:Metadata:%s/rok/%d]]", variableName, year )
			output = output .. string.format( "[[Kategorie:Metadata:%s/roky/%d]]", variableName, year % 10 )
			output = output .. string.format( "[[Kategorie:Metadata:%s/měsíc/%02d]]", variableName, month )
			output = output .. string.format( "[[Kategorie:Metadata:%s/datum/%02d%02d]]", variableName, month, day )
		elseif dateType == "Y" then
			output = output .. string.format( "[[Kategorie:Metadata:%s/rok/%d]]", variableName, year )
			output = output .. string.format( "[[Kategorie:Metadata:%s/roky/%d]]", variableName, year % 10 )
			output = output .. string.format( "[[Kategorie:Monitoring:Autorinfo/datum %s/ = jen rok]]", mw.language.getContentLanguage():lc( variableName ) )
		else
			year = tonumber( mw.ustring.match( value, ".-(%d?%d?%d?%d)$" ) )
			if year then
				output = output .. string.format( "[[Kategorie:Metadata:%s/rok/%d]]", variableName, year )
				output = output .. string.format( "[[Kategorie:Metadata:%s/roky/%d]]", variableName, year % 10 )
				output = output .. string.format( "[[Kategorie:Monitoring:Autorinfo/datum %s/ = rok vyparsovaný z textu]]", mw.language.getContentLanguage():lc( variableName ) )
			else
				output = output .. string.format( "[[Kategorie:Monitoring:Autorinfo/datum %s/ = neparsovatelné]]", mw.language.getContentLanguage():lc( variableName ) )
			end
		end
	end
	
	output = frame:preprocess( output )
	
	return output
	
end


-- @brief
--  Checks the copyright status of the author.
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Preprocessed wikitext
function _module.copyrightStatus( frame )
	
	if mw.title.getCurrentTitle().namespace ~= 100 then
		return
	end
	
	local output = ""
	local moduleArgs = frame.args
	
	local copyrightPeriod = 70
	local ageReleasePeriod = 200
	local maxAge = 120
	
	local icon
	
	local deathDate = mw.text.trim( moduleArgs[1] or "" )
	local birthDate = mw.text.trim( moduleArgs[2] or "" )
	
	local currentYear = tonumber( os.date( "%Y", os.time() ) )
	local deathYear = tonumber( mw.ustring.match( deathDate, ".-(%d?%d?%d?%d)$" ) )
	local birthYear = tonumber( mw.ustring.match( birthDate, ".-(%d?%d?%d?%d)$" ) )
	
	local isFree = mw.ustring.match( deathDate, "př%. n%. l%.$" )
		or mw.ustring.match( deathDate, "BCE$" )
		or mw.ustring.match( birthDate, "př%. n%. l%.$" )
		or mw.ustring.match( birthDate, "BCE$" )
		or ( deathYear and currentYear > deathYear + copyrightPeriod )
		or ( birthYear and currentYear > birthYear + ageReleasePeriod )
	
	if isFree then
		icon = "PD-icon.svg"
		if deathYear then
			if currentYear == deathYear + copyrightPeriod + 1 then
				output = output .. string.format( "[[Kategorie:Autoři:Volní od letošního roku (%d let po úmrtí)]]", copyrightPeriod )
			else
				output = output .. string.format( "[[Kategorie:Autoři:Volní (%d let po úmrtí)]]", copyrightPeriod )
			end
		elseif birthYear then
			if currentYear == birthYear + ageReleasePeriod + 1 then
				output = output .. string.format( "[[Kategorie:Autoři:Volní od letošního roku (%d let po narození)]]", ageReleasePeriod )
			else
				output = output .. string.format( "[[Kategorie:Autoři:Volní (%d let po narození)]]", ageReleasePeriod )
			end
		else
			output = output .. "[[Kategorie:Autoři:Volní (př. n. l.)]]"
		end
	else
		icon = "Red copyright.svg"
		if deathYear then
			output = output .. string.format( "[[Kategorie:Autoři:Volní od roku %s]]", deathYear + copyrightPeriod + 1 )
		elseif birthYear and birthYear >= currentYear - maxAge then
			output = output .. "[[Kategorie:Autoři:Žijící]]"
		else
			output = output .. "[[Kategorie:Autoři:Volní od neznámého roku]]"
		end
	end
	
	output = output .. string.format( "[[Soubor:%s|16x16px|right|alt=|link=]]", icon )
	
	output = frame:preprocess( output )
	
	return output
	
end


-- @brief
--  Categorizes the author by alphabet and monitors the sorting type.
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Preprocessed wikitext
function _module.categorizeByAlphabet( frame )
	
	if mw.title.getCurrentTitle().namespace ~= 100 then
		return
	end
	
	local output = ""
	local templateArgs = frame:getParent().args
	
	local relevantArgs = {
		"jméno",
		"příjmení",
		"řazení"
	}
	local argVals = {}
	
	local sortString
	local letter
	local key
	local letterLength
	
	local sorting
	
	for _, arg in ipairs( relevantArgs ) do
		argVals[arg] = templateArgs[arg] and mw.text.trim( templateArgs[arg] )
		argVals[arg] = argVals[arg] ~= "" and argVals[arg] or nil
	end
	
	sortString = argVals["řazení"] 
		or argVals["příjmení"] and mw.ustring.format( "%s, %s", argVals["příjmení"], argVals["jméno"] )
		or argVals["jméno"]
	
	letterLength = mw.ustring.sub( sortString, 1, 2 ) == "Ch" and 2 or 1
	letter = mw.language.getContentLanguage():ucfirst( mw.ustring.sub( sortString, 1, letterLength ) )
	key = mw.ustring.sub( sortString, letterLength + 1 )
	
	output = mw.ustring.format( "[[Kategorie:Autoři:Abecedně/%s|%s]]", letter, key )
	
	if argVals["řazení"] then
		if argVals["řazení"] == mw.ustring.format( "%s, %s", argVals["příjmení"] or "", argVals["jméno"] or "" ) then
			sorting = "příjmení, jméno"
		elseif argVals["řazení"] == mw.ustring.format( "%s", argVals["jméno"] or "" ) then
			sorting = "jméno"
		elseif argVals["řazení"] == mw.ustring.format( "%s", argVals["příjmení"] or "" ) then
			sorting = "příjmení"
		else
			sorting = "vlastní"
		end
		output = output .. mw.ustring.format( "[[Kategorie:Monitoring:Autorinfo/řazení/ = %s]]", sorting )
	end
	
	output = frame:preprocess( output )
	
	return output
	
end


-- @brief
--  Temporary for {{IndexAutoři}} to link categories "Autor-*" to "Autoři:Abecedně/*"
-- 
-- @param
--  frame The current frame object
-- 
-- @return
--  Wikitext
function _module.printComplementaryCategoryName( frame )
	
	local title = mw.title.getCurrentTitle()
	
	if title.namespace ~= 14 then
		return
	end
	
	local output
	
	output = mw.ustring.gsub( title.prefixedText, "Autor%-", "Autoři:Abecedně/" )
	
	return output
	
end


----------------------------------------
return _module