Dokumentado Dokumentado


Ŝablona programado Diskutoj Lua Testoj Subpaĝoj
Modulo Esperanto English

Modulo: Dokumentado


Se vi havas demandon pri ĉi tiu Lua-modulo, tiam vi povas demandi en la diskutejo pri Lua-moduloj. La Intervikiaj ligiloj estu metataj al Vikidatumoj. (Vidu Helpopaĝon pri tio.)
local export = {}

function export.show(frame)
	local id = mw.wikibase.getEntityIdForCurrentPage()

	local months = {"januaro", "februaro", "marto", "aprilo", "majo", "junio", "julio", "aŭgusto", "septembro", "oktobro", "novembro", "decembro"}

	local categories = ""
	local birth = {}
	local death = {}
	local living = true

	local nameArg = frame.args[1] or ""
	local birthArg = string.lower(frame.args[2] or "")
	local deathArg = string.lower(frame.args[3] or "")

	if nameArg ~= "" then
		categories = categories .. frame:preprocess("{{DEFAULTSORT:" .. nameArg .. "}}")
	end

	if birthArg ~= "" then
		for w in birthArg:gmatch("([^/]+)") do
			table.insert(birth, w)
		end

		birth[2] = tonumber(birth[2])
	elseif id ~= nil then
		local birthTable = mw.wikibase.getBestStatements(id, "P569")

		if #birthTable == 1 and birthTable[1]["mainsnak"]["datavalue"] ~= nil and string.sub(birthTable[1]["mainsnak"]["datavalue"]["value"]["time"], 1, 1) == "+" then
			table.insert(birth, birthTable[1]["mainsnak"]["datavalue"]["value"]["time"])
			table.insert(birth, birthTable[1]["mainsnak"]["datavalue"]["value"]["precision"])
		end
		
		if birthArg == "nekonata" then
			categories = categories .. "[[Kategorio:Naskiĝjaro nekonata]]"
		end
		
	end

	if deathArg ~= "" then
		for w in deathArg:gmatch("([^/]+)") do
			table.insert(death, w)
		end

		death[2] = tonumber(death[2])
	elseif id ~= nil then
		local deathTable = mw.wikibase.getBestStatements(id, "P570")

		if #deathTable == 1 and deathTable[1]["mainsnak"]["datavalue"] ~= nil and string.sub(deathTable[1]["mainsnak"]["datavalue"]["value"]["time"], 1, 1) == "+" then
			table.insert(death, deathTable[1]["mainsnak"]["datavalue"]["value"]["time"])
			table.insert(death, deathTable[1]["mainsnak"]["datavalue"]["value"]["precision"])
		end
	end

	if id ~= nil then
		local genderTable = mw.wikibase.getBestStatements(id, "P21")

		for k, v in pairs(genderTable) do
			if v["mainsnak"]["datavalue"] ~= nil then
				local genderId = v["mainsnak"]["datavalue"]["value"]["id"]

				if genderId == "Q6581097" or genderId == "Q2449503" then
					categories = categories .. "[[Kategorio:Viroj]]"
				elseif genderId == "Q6581072" or genderId == "Q1052281" then
					categories = categories .. "[[Kategorio:Virinoj]]"
				elseif genderId == "Q1097630" then
					categories = categories .. "[[Kategorio:Interseksuloj]]"
				elseif genderId == "Q48270" or genderId == "Q505371" or genderId == "Q7130936" then
					categories = categories .. "[[Kategorio:Neduumuloj]]"
				end
			end
		end
	end

	if #birth == 2 then
		local timeValue = birth[1]
		local precision = birth[2]

		if precision >= 9 then -- year
			local year = tonumber(string.sub(timeValue, 2, 5))
			categories = categories .. "[[Kategorio:Naskiĝintoj en " .. year .. "]]"

			if year < 1905 then
				living = false
			end

			if precision >= 11 then -- year, month, day
				local month = tonumber(string.sub(timeValue, 7, 8))
				local day = tonumber(string.sub(timeValue, 10, 11))
				categories = categories .. "[[Kategorio:Naskiĝintoj la " .. day .. "-an de " .. months[month] .. "]]"
			end
		elseif precision == 8 then -- decade
			local decade = string.sub(timeValue, 2, 4):gsub('0*', '', 1)
			categories = categories .. "[[Kategorio:Naskiĝintoj en " .. decade .. "0-" .. decade .. "9]]"
		elseif precision == 7 then -- century
			local century = math.floor((tonumber(string.sub(timeValue, 2, 5))+99)/100)
			categories = categories .. "[[Kategorio:Naskiĝintoj en la " .. century .. "-a jarcento]]"
		end
	end

	if #death == 2 then
		local timeValue = death[1]
		local precision = death[2]

		if precision >= 9 then -- year
			local year = tonumber(string.sub(timeValue, 2, 5))
			categories = categories .. "[[Kategorio:Mortintoj en " .. year .. "]]"

			if precision >= 11 then -- year, month, day
				local month = tonumber(string.sub(timeValue, 7, 8))
				local day = tonumber(string.sub(timeValue, 10, 11))
				categories = categories .. "[[Kategorio:Mortintoj la " .. day .. "-an de " .. months[month] .. "]]"
			end
		elseif precision == 8 then -- decade
			local decade = string.sub(timeValue, 2, 4):gsub('0*', '', 1)
			categories = categories .. "[[Kategorio:Mortintoj en " .. decade .. "0-" .. decade .. "9]]"
		elseif precision == 7 then -- century
			local century = math.floor((tonumber(string.sub(timeValue, 2, 5))+99)/100)
			categories = categories .. "[[Kategorio:Mortintoj en la " .. century .. "-a jarcento]]"
		end

		living = false
	elseif living then
		if deathArg == "nekonata" then
			categories = categories .. "[[Kategorio:Mortojaro nekonata]]"
		elseif deathArg == "mankanta" then
			categories = categories .. "[[Kategorio:Mortojaro mankanta]]"			
		else	
			categories = categories .. "[[Kategorio:Vivantaj homoj]]"
		end
	end

	return categories
end

return export