Modul:Film

Modul:Film

Modul:Film
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("USA([,\n])", "[[Vereinigte Staaten|USA]]%1")
				:gsub("DDR([,\n])", "[[Deutsche Demokratische Republik|DDR]]%1")
				:gsub("Großbritannien([,\n])", "[[Vereinigtes Königreich|Großbritannien]]%1")
				:gsub("UK([,\n])", "[[Vereinigtes Königreich|UK]]%1")
				:gsub("China([,\n])", "[[Volksrepublik China|China]]%1")
				:gsub("Taiwan([,\n])", "[[Republik China (Taiwan)|Taiwan]]%1")
				:gsub("UdSSR([,\n])", "[[Sowjetunion|UdSSR]]%1")
				:gsub("ČSSR([,\n])", "[[Tschechoslowakei|ČSSR]]%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("Hindi([,\n])", "[[Hindi]]%1")
				:gsub("Urdu([,\n])", "[[Urdu]]%1")
				:gsub("Tamil([,\n])", "[[Tamil]]%1")
				:gsub("Panjabi([,\n])", "[[Panjabi]]%1")
				:gsub("Mandarin([,\n])", "[[Mandarin (Sprache)|Mandarin]]%1")
				:gsub("Hochchinesisch([,\n])", "[[Hochchinesisch]]%1")
				:gsub("Chinesisch([,\n])", "[[Chinesische Sprachen|Chinesisch]]%1")
				:gsub("Farsi([,\n])", "[[Persische Sprache|Farsi]]%1")
				:gsub("Jiddisch([,\n])", "[[Jiddisch]]%1")
				:gsub("Kurdisch([,\n])", "[[Kurdische Sprachen|Kurdisch]]%1")
				:gsub("Swahili([,\n])", "[[Swahili (Sprache)|Swahili]]%1")
				:gsub("Latein([,\n])", "[[Latein]]%1")
				:gsub("Tagalog([,\n])", "[[Tagalog]]%1")
				:gsub("Somali([,\n])", "[[Somali (Sprache)|Somali]]%1")
				:gsub("Wolof([,\n])", "[[Wolof (Sprache)|Wolof]]%1")
				:gsub("Maori([,\n])", "[[Maorische Sprache|Māori]]%1")
				:gsub("Filipino([,\n])", "[[Filipino]]%1")
				:gsub("Afrikaans([,\n])", "[[Afrikaans]]%1")
				:gsub("ASL([,\n])", "[[American Sign Language|ASL]]%1")
				:gsub("Igbo([,\n])", "[[Igbo (Sprache)|Igbo]]%1")
				:gsub("Navajo([,\n])", "[[Navajo (Sprache)|Navajo]]%1")
				:gsub("Quechua([,\n])", "[[Quechua]]%1")
				:gsub("Marathi([,\n])", "[[Marathi]]%1")
				:gsub("Dioula([,\n])", "[[Dioula]]%1")
				:gsub("Romani([,\n])", "[[Romani]]%1")
				:gsub("Shona([,\n])", "[[Shona (Sprache)|Shona]]%1")
				:gsub("Xhosa([,\n])", "[[isiXhosa|Xhosa]]%1")
				:gsub("Schottisch%-Gälisch([,\n])", "[[Schottisch-gälische Sprache|Schottisch-Gälisch]]%1")
				:gsub("Ladino([,\n])", "[[Judenspanisch|Ladino]]%1")
				:gsub("Gujarati([,\n])", "[[Gujarati]]%1")
				:gsub("Mapudungun([,\n])", "[[Mapudungun]]%1")
				:gsub("Chichewa([,\n])", "[[Chichewa]]%1")
				:gsub("Yolngu Matha([,\n])", "[[Yolngu#Sprache|Yolngu Matha]]%1")
				:gsub("Nouchi([,\n])", "[[Nouchi]]%1")
				:gsub("Kirundi([,\n])", "[[Kirundi]]%1")
				:gsub("Kinyarwanda([,\n])", "[[Kinyarwanda]]%1")
				:gsub("Talisch([,\n])", "[[Talisch]]%1")
				:gsub("Mixtekisch([,\n])", "[[Mixtekisch]]%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


local function getChrono(pid)
	local entity = mw.wikibase.getEntity()
	
	if not entity then
		return printError("entity-not-found")
	end
	
	-- prefer predecessor/successor
	local qid, result
	local chrono =
	{
		P155 = entity:getBestStatements('P155'),
		P156 = entity:getBestStatements('P156')
	}
	
	if next(chrono["P155"])~=nil or next(chrono["P156"])~=nil then
		if next(chrono[pid])~=nil then
			qid = chrono[pid][1].mainsnak.datavalue.value.id
		end
	else
		local series = entity:getBestStatements('P179')
		qid = series[1].qualifiers[pid][1].datavalue.value.id
	end

	if qid then
		result = mw.wikibase.getLabel(qid)
		local sitelink = mw.wikibase.getSitelink(qid)
		local title = mw.wikibase.getBestStatements(qid, 'P1476')
		
		if next(title)~=nil and string.find(result,title[1].mainsnak.datavalue.value.text,0,true) then
			result = title[1].mainsnak.datavalue.value.text
		end
		
		if sitelink then
			result = '[[' ..sitelink .. '|' .. result .. ']]'
		end
		
		result = '<span class="wikidata-content">' .. result .. '</span>'
	end
	
	return result
end


function p.getPred(frame)
	e,v = pcall(getChrono, 'P155')
	if e then
		return v
	end
end

function p.getSucc(frame)
	e,v = pcall(getChrono, 'P156')
	if e then
		return v
	end
end


return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.