モジュール:Film

モジュールの解説[作成]
local i18n = {
	["errors"] = {
		["entity-not-found"] = "Wikidata-Eintrag nicht gefunden.",
		["needed-property-not-found"] = "Benötigte Eigenschaft P527 nicht gefunden.",
		["child-item-without-given-property"] = "Abgefragte Eigenschaft im via P527 untergeordneten Element nicht gefunden."
	}
}

local p = {};

local function printError(code)
	
	return '<span class="error">' .. (i18n.errors[code] or code) .. '</span>'
	
end

function p.getPLlinks(frame)
	local PLstring = frame.args[1]
	local PLresult
	
	PLresult = string.gsub(PLstring, "DDR,", "[[ドイツ民主共和国|DDR]],")
	PLresult = string.gsub(PLresult, "ČSSR,", "[[チェコスロバキア|ČSSR]],")
	PLresult = string.gsub(PLresult, "UdSSR,", "[[ソビエト連邦|UdSSR]],")
	PLresult = string.gsub(PLresult, "China,", "[[中華人民共和国|China]],")        
	PLresult = string.gsub(PLresult, "Taiwan,", "[[中華民国|Taiwan]],")
	PLresult = string.gsub(PLresult, "USA,", "[[アメリカ合衆国|USA]],")
	PLresult = string.gsub(PLresult, "Großbritannien,", "[[イギリス|Großbritannien]],")

	return PLresult
	
end

function p.getOSlinks(frame)
	local OSstring = frame.args[1]
	local OSresult
	
	OSresult = string.gsub(OSstring, "Schweizerdeutsch,", "[[スイスドイツ語|Schweizerdeutsch]],")
	OSresult = string.gsub(OSresult, "Tagalog,", "[[タガログ語|Tagalog]],")
	OSresult = string.gsub(OSresult, "Somali,", "[[ソマリ語|Somali]],")
	OSresult = string.gsub(OSresult, "Swahili,", "[[スワヒリ語|Swahili]],")        
	OSresult = string.gsub(OSresult, "Hindi,", "[[ヒンディー語|Hindi]],")
	OSresult = string.gsub(OSresult, "Maori,", "[[[[マオリ語|Maori]],")

	return OSresult
	
end

function p.getChildItems(frame)
	
	local template = frame.args[1]
	local id = frame.args["id"]
	local showerrors = frame.args["showerrors"]
	local default = frame.args["default"]
	if default then showerrors = nil end
	
	local template_props = {
		["IMDb"] = {
			["property"] = "P345",
			["url"] = "https://www.imdb.com/",
			["sub_url"] = {
				["person"] = "name/",
				["film"] = "title/"
				},
			["bind"] = "in der",
			["link"] = "Internet Movie Database",
			["lang"] = "englisch"
		},
		["Rotten Tomatoes"] = {
			["property"] = "P1258",
			["url"] = "https://www.rottentomatoes.com/",
			["bind"] = "bei",
			["link"] = "Rotten Tomatoes",
			["lang"] = "englisch"
		},
		["Filmportal"] = {
			["property"] = "P2639",
			["url"] = "https://www.filmportal.de/",
			["sub_url"] = {
				["person"] = "person/",
				["film"] = "film/"
				},
			["bind"] = "bei",
			["link"] = "filmportal.de"
		}
	}
	
	-- get wikidata entity
	local entity = mw.wikibase.getEntity(id)
	
	if not entity then
		if showerrors then return printError("entity-not-found") else return default end
	end
	
	-- fetch the first claim of satisfying the needed property
	local claims
	if entity.claims then 
		claims = entity.claims[mw.wikibase.resolvePropertyId("P527")] 
	end
	if not claims or not claims[1] then
		if showerrors then return printError("needed-property-not-found") else return default end
	end
	
	result = {}
	
	for idx in pairs(claims) do
		local claim = claims[idx]
		value = claim.mainsnak.datavalue.value["numeric-id"]
		
		local entity2 = mw.wikibase.getEntity("Q" .. value)
		local label = mw.wikibase.label("Q" .. value)
		
		if entity2 and entity2.claims and entity2.claims[template_props[template]["property"]] then
			
			local result_temp = ""
			
			if idx ~= 1 then result_temp = "* " end
			
			local claims2 = entity2.claims[template_props[template]["property"]]
			result_temp = result_temp .. '<span class="wikidata-content">'
			
			local property31 = entity2.claims[mw.wikibase.resolvePropertyId("P31")]
			local isHuman = (property31[1].mainsnak.datavalue.value["numeric-id"] == 5)
			
			if not isHuman then	result_temp = result_temp .. '\'\'' end
			
			result_temp = result_temp .. '[' .. template_props[template]["url"]
			
			if template_props[template]["sub_url"] then 
				if isHuman then
					result_temp = result_temp .. template_props[template]["sub_url"]["person"]
				else
					result_temp = result_temp .. template_props[template]["sub_url"]["film"]
				end
			end
			
			result_temp = result_temp .. claims2[1].mainsnak.datavalue.value .. '/ ' .. label .. ']'
		
			if not isHuman then	result_temp = result_temp .. '\'\'' end
		
			result_temp = result_temp .. '</span> ' .. template_props[template]["bind"] .. ' '
			
			if idx == 1 then
				result_temp = result_temp .. '[[' .. template_props[template]["link"] .. ']]'
			else
				result_temp = result_temp .. template_props[template]["link"]
			end
			
			if template_props[template]["lang"] then
				result_temp = result_temp .. ' (' .. template_props[template]["lang"] .. ')'
			end
			result[#result + 1] = result_temp
			
		else
			
			return printError("child-item-without-given-property") 
			
		end
	end

	return table.concat(result, '\n')
	
end

return p