Modul:Film

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


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] .. '\n'
	
	local PLresult = PLstring
				:gsub ("DDR([,\n])", "[[Deutsche Demokratische Republik|DDR]]%1")
				:gsub("ČSSR([,\n])", "[[Tschechoslowakei|ČSSR]]%1")
				:gsub("UdSSR([,\n])", "[[Sowjetunion|UdSSR]]%1")
				:gsub("China([,\n])", "[[Volksrepublik China|China]]%1")
				:gsub("Taiwan([,\n])", "[[Republik China (Taiwan)|Taiwan]]%1")
				:gsub("USA([,\n])", "[[Vereinigte Staaten|USA]]%1")
				:gsub("Großbritannien([,\n])", "[[Vereinigtes Königreich|Großbritannien]]%1")

	return (mw.ustring.gsub(PLresult, "(%u[%w%s%-]+)([,\n])", "[[%1]]%2"))
	
end


-- Ausnahmen für automatische Sprachlinks
function p.getOSlinks(frame)
	local OSstring = frame.args[1] .. '\n'
	
	local OSresult = OSstring
				:gsub("Schweizerdeutsch([,\n])", "[[Schweizerdeutsch]]%1")
				:gsub("Tagalog([,\n])", "[[Tagalog]]%1")
				:gsub("Somali([,\n])", "[[Somali (Sprache)|Somali]]%1")
				:gsub("Swahili([,\n])", "[[Swahili (Sprache)|Swahili]]%1")
				:gsub("Hindi([,\n])", "[[Hindi]]%1")
				:gsub("Maori([,\n])", "[[Maorische Sprache|Maori]]%1")
				:gsub("Mandarin([,\n])", "[[Mandarin (Sprache)|Mandarin]]%1")
				:gsub("Latein([,\n])", "[[Latein]]%1")
				:gsub("Afrikaans([,\n])", "[[Afrikaans]]%1")
				:gsub("Schottisch%-Gälisch([,\n])", "[[Schottisch-gälische Sprache|Schottisch-Gälisch]]%1")
				:gsub("Khmer([,\n])", "[[Khmer-Sprache|Khmer]]%1")
				:gsub("Igbo([,\n])", "[[Igbo (Sprache)|Igbo]]%1")
				:gsub("Quechua([,\n])", "[[Quechua]]%1")
				:gsub("Filipino([,\n])", "[[Filipino]]%1")
				:gsub("El Silbo([,\n])", "[[El Silbo]]%1")
				:gsub("Wolof([,\n])", "[[Wolof (Sprache)|Wolof]]%1")
				:gsub("Xhosa([,\n])", "[[isiXhosa|Xhosa]]%1")
				:gsub("Chichewa([,\n])", "[[Chichewa]]%1")
				:gsub("ASL([,\n])", "[[American Sign Language|ASL]]%1")
				:gsub("Farsi([,\n])", "[[Persische Sprache|Farsi]]%1")
				:gsub("Urdu([,\n])", "[[Urdu]]%1")
				:gsub("Yolngu Matha([,\n])", "[[Yolngu#Sprache|Yolngu Matha]]%1")
				:gsub("Jiddisch([,\n])", "[[Jiddisch]]%1")
				:gsub("Neapolitanisch([,\n])", "[[Neapolitanisch]]%1")
				:gsub("Hochchinesisch([,\n])", "[[Hochchinesisch]]%1")
				:gsub("Nouchi([,\n])", "[[Nouchi]]%1")
				:gsub("Dioula([,\n])", "[[Dioula]]%1")
				:gsub("Shona([,\n])", "[[Shona (Sprache)|Shona]]%1")
				:gsub("Kirundi([,\n])", "[[Kirundi]]%1")
				:gsub("Kinyarwanda([,\n])", "[[Kinyarwanda]]%1")
				:gsub("Tamil([,\n])", "[[Tamil]]%1")
				:gsub("Talisch([,\n])", "[[Talisch]]%1")
				:gsub("Ladino([,\n])", "[[Judenspanisch|Ladino]]%1")
				:gsub("Lingala([,\n])", "[[Lingala]]%1")
				:gsub("Maschi([,\n])", "[[Naki (Sprache)|Maschi]]%1")
				:gsub("Gujarati([,\n])", "[[Gujarati]]%1")
				:gsub("Miskito([,\n])", "[[Miskito (Sprache)|Miskito]]%1")
				:gsub("Chinesisch([,\n])", "[[Chinesische Sprachen|Chinesisch]]%1")
				:gsub("Kurdisch([,\n])", "[[Kurdische Sprachen|Kurdisch]]%1")
				:gsub("Mapudungun([,\n])", "[[Mapudungun]]%1")
				:gsub("Mixtekisch([,\n])", "[[Mixtekisch]]%1")
				:gsub("Navajo([,\n])", "[[Navajo (Sprache)|Navajo]]%1")
				:gsub("Mòoré([,\n])", "[[Mòoré]]%1")
				:gsub("Gan([,\n])", "[[Gan (Sprache)|Gan]]%1")
				:gsub("Marathi([,\n])", "[[Marathi]]%1")
				:gsub("Fulfulde([,\n])", "[[Fulfulde]]%1")
				:gsub("Panjabi([,\n])", "[[Panjabi]]%1")
				
	return (mw.ustring.gsub(OSresult, "(%w+)([,\n])", "[[%1e Sprache|%1]]%2"))
	
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

-- Fehlermeldungen, die nur in der Vorschau sichtbar sind
function p.errorMessage(frame)
	local errortext = frame.args[1]
	if frame:preprocess( "{{REVISIONID}}" ) == "" then
    	return errortext
    end
end

return p