モジュール: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  .. (i18n.errorscode or code) .. 
	
end
function p.getPLlinks(frame)
	local PLstring = frame.args1
	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.args1
	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.args1
	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.claimsmw.wikibase.resolvePropertyId("P527") 
	end
	if not claims or not claims1 then
		if showerrors then return printError("needed-property-not-found") else return default end
	end
	
	result = {}
	
	for idx in pairs(claims) do
		local claim = claimsidx
		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.claimstemplate_propstemplate"property" then
			
			local result_temp = ""
			
			if idx ~= 1 then result_temp = "* " end
			
			local claims2 = entity2.claimstemplate_propstemplate"property"
			result_temp = result_temp .. 
			
			local property31 = entity2.claimsmw.wikibase.resolvePropertyId("P31")
			local isHuman = (property311.mainsnak.datavalue.value"numeric-id" == 5)
			
			if not isHuman then	result_temp = result_temp .. '\'\ end
			
			result_temp = result_temp ..  .. template_propstemplate"url"
			
			if template_propstemplate"sub_url" then 
				if isHuman then
					result_temp = result_temp .. template_propstemplate"sub_url""person"
				else
					result_temp = result_temp .. template_propstemplate"sub_url""film"
				end
			end
			
			result_temp = result_temp .. claims21.mainsnak.datavalue.value .. '/ ' .. label .. 
		
			if not isHuman then	result_temp = result_temp .. '\'\ end
		
			result_temp = result_temp .. ' ' .. template_propstemplate"bind" .. ' '
			
			if idx == 1 then
				result_temp = result_temp ..  .. template_propstemplate"link" .. 
			else
				result_temp = result_temp .. template_propstemplate"link"
			end
			
			if template_propstemplate"lang" then
				result_temp = result_temp .. ' (' .. template_propstemplate"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