Modul:IMDBref

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:IMDBref/Doku erstellt werden

--[=[ IMDBref 2022-11-04
	reference for Internet Movie Database by Wikidata
	
	Autor: Vollbracht
	
]=]

--Module globals

local p = {}

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

PREF_LANG = 'Deutsch'

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 imdbID = SDA.MainSnackValue(wdo, 'P345')
	if not imdbID then return '' end
	if imdbID == '' 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 .. ' ' .. '[[Internet Movie Database|IMDb]]: [https://ww'
			..	'w.imdb.com/title/' .. imdbID .. ' ' .. imdbID .. ']'
	local b = tSource:infoBrace(nil, nil, 1)
	if b and b ~= '' then result = result .. ' ' .. b end
	return frame:preprocess(result .. '.</ref>')
end

return p