Zum Inhalt springen

Modul:FilmRef

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 10. November 2022 um 18:19 Uhr durch Vollbracht (Diskussion | Beiträge). Sie kann sich erheblich von der aktuellen Version unterscheiden.
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

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


--[=[ FilmRef 2022-11-10
	reference for films by Wikidata

	Autor: Vollbracht
	
]=]

local p = {}

local _, SDA = pcall(require, "Modul:SimpleDataAccess")
local _, t = pcall(require, "Modul:Title")
local Title = t.service

PREF_LANG = 'Deutsch'
IDbase = {
	P345  = '[[Internet Movie Database|IMDb]]: [https://www.imdb.com/title/%s',
	P2639 = '[[filmportal.de]]: [https://www.filmportal.de/%s',
	P3107 = '[[Lexikon des internationalen Films|LdiF]]: [https://www.filmdiens'
		..	't.de/film/details/%s',
	P3933 = '[[Cinema]]: [https://www.cinema.de/%s',
	P8531 = '[[Filmstarts]]: [https://www.filmstarts.de/kritiken/%s.html'
}

p.ref = function(frame)
	local wdo = frame.args.wdObject
	if not wdo then wdo = frame.args[1] end
	if not wdo:match('Q%d*') then return '' end
	if not wdo then wdo = mw.wikibase.getEntityIdForCurrentPage() end
	if not wdo then return '' end
	local IDs = {}
	for k, v in pairs(IDbase) do
		local ID = SDA.MainSnackValue(wdo, k)
		if ID and ID ~= '' then
			table.insert(IDs, string.format(v, ID) .. ' ' .. ID .. ']')
		end
	end
	if #IDs == 0 then return '' end
	local tSource = Title:new(wdo)
	if not tSource then return '' end
	local title = tSource.title.text
	local regie = SDA.MainSnackValue(wdo, 'P57')
	local country = SDA.MainSnackValue(wdo, 'P495')
	local year = SDA.MainSnackValue(wdo, 'P577')
	local result = '<ref'
	local group = frame.args.group
	if group and group ~= '' then
		result = result .. ' group="' .. group .. '"'
	end
	local name = frame.args.name
	if name and name ~= '' then
		result = result .. ' name="' .. name .. '"'
	end
	result = result .. '>'
	if regie and regie ~= '' then
		result = result .. 'Film von ' .. regie .. ': '
	else result = result .. 'Film: ' end
	result = result .. tSource:titleLink() .. '. '
	if country or year then
		result = result .. table.concat({country, year}, ' ') .. ', '
	end
	result =	result .. ' ' .. table.concat(IDs, ', ')
	local b = tSource:infoBrace(nil, nil, 1)
	if b and b ~= '' then result = result .. ' ' .. b end
	return frame:preprocess(result .. '.</ref>')
end

return p