Modul:Film

aus Wikipedia, der freien Enzyklopädie
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 = {};

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


-- Ausnahmen für automatische Länderlinks
function p.getPLlinks(frame)
	local PLstring = frame.args[1]
	local PLresult
	
	PLresult = PLstring
				:gsub ("DDR,", "[[Deutsche Demokratische Republik|DDR]],")
				:gsub("ČSSR,", "[[Tschechoslowakei|ČSSR]],")
				:gsub("UdSSR,", "[[Sowjetunion|UdSSR]],")
				:gsub("China,", "[[Volksrepublik China|China]],")
				:gsub("Taiwan,", "[[Republik China (Taiwan)|Taiwan]],")
				:gsub("USA,", "[[Vereinigte Staaten|USA]],")
				:gsub("Großbritannien,", "[[Vereinigtes Königreich|Großbritannien]],")

	return PLresult
	
end


-- Ausnahmen für automatische Sprachlinks
function p.getOSlinks(frame)
	local OSstring = frame.args[1]
	local OSresult
	
	OSresult = OSstring
				:gsub("Schweizerdeutsch,", "[[Schweizerdeutsch]],")
				:gsub("Tagalog,", "[[Tagalog]],")
				:gsub("Somali,", "[[Somali (Sprache)|Somali]],")
				:gsub("Swahili,", "[[Swahili (Sprache)|Swahili]],")
				:gsub("Hindi,", "[[Hindi]],")
				:gsub("Maori,", "[[Maorische Sprache|Maori]],")
				:gsub("Mandarin,", "[[Mandarin (Sprache)|Mandarin]],")
				:gsub("Latein,", "[[Latein]],")
				:gsub("Afrikaans,", "[[Afrikaans]],")
				:gsub("Schottisch%-Gälisch,", "[[Schottisch-gälische Sprache|Schottisch-Gälisch]],")
				:gsub("Khmer,", "[[Khmer-Sprache|Khmer]],")
				:gsub("Igbo,", "[[Igbo (Sprache)|Igbo]],")
				:gsub("Quechua,", "[[Quechua]],")
				:gsub("Filipino,", "[[Filipino]],")
				:gsub("El Silbo,", "[[El Silbo]],")
				:gsub("Wolof,", "[[Wolof (Sprache)|Wolof]],")
				:gsub("Xhosa,", "[[isiXhosa|Xhosa]],")
				:gsub("Chichewa,", "[[Chichewa]],")
				:gsub("ASL,", "[[American Sign Language|ASL]],")
				:gsub("Farsi,", "[[Persische Sprache|Farsi]],")
				:gsub("Urdu,", "[[Urdu]],")
				:gsub("Yolngu Matha,", "[[Yolngu#Sprache|Yolngu Matha]],")
				:gsub("Jiddisch,", "[[Jiddisch]],")
				:gsub("Neapolitanisch,", "[[Neapolitanisch]],")
				:gsub("Hochchinesisch,", "[[Hochchinesisch]],")
				:gsub("Nouchi,", "[[Nouchi]],")
				:gsub("Dioula,", "[[Dioula]],")
				:gsub("Shona,", "[[Shona (Sprache)|Shona]],")
				:gsub("Kirundi,", "[[Kirundi]],")
				:gsub("Kinyarwanda,", "[[Kinyarwanda]],")
				:gsub("Tamil,", "[[Tamil]],")
				:gsub("Talisch,", "[[Talisch]],")
				:gsub("Ladino,", "[[Judenspanisch|Ladino]],")
				:gsub("Lingala,", "[[Lingala]],")
				:gsub("Maschi,", "[[Naki (Sprache)|Maschi]],")
				:gsub("Gujarati,", "[[Gujarati]],")
				:gsub("Miskito,", "[[Miskito (Sprache)|Miskito]],")
				:gsub("Chinesisch,", "[[Chinesische Sprachen|Chinesisch]],")
	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