Modul:FilmRef
Zur Navigation springen
Zur Suche springen
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
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',
P3138 = '[[OFDb.de]]: [https://www.ofdb.de/film/%s,',
P3933 = '[[Cinema]]: [https://www.cinema.de/%s',
P4947 = '[[The Movie Database|TMDb]]: [https://www.themoviedb.org/movie/%s',
P5786 = '[[Moviepilot]]: [https://www.moviepilot.de/movies/%s',
P8531 = '[[Filmstarts]]: [https://www.filmstarts.de/kritiken/%s.html'
}
local function byWD(frame)
local wdo = frame.args.wdObject
if not wdo then wdo = frame.args[1] end
if wdo then wdo = wdo:match('Q%d*')
else 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 = ''
if regie and regie ~= '' then
result = result .. 'Film von ' .. regie .. ': '
else result = result .. 'Film: ' end
result = result .. tSource:titleLink() .. '. '
if country then
if year then
result = result .. country .. ' ' .. year:format('yyyy') .. ', '
else
result = result .. country .. ', '
end
elseif year then
result = result .. year:format('yyyy') .. ', '
end
result = result .. ' ' .. table.concat(IDs, ', ')
local b = tSource:infoBrace(nil, nil, 1)
if b and b ~= '' then result = result .. ' ' .. b end
return result
end
local function message(frame)
mw.logObject(frame.args, 'message with')
local data = frame.args[1]
if not data or data == '' then
data = frame.args.wdObject
end
if data then mw.log('data is "' .. data .. '"') end
if not data or data == '' then
data = 'Bitte Datenobjekt angeben!'
elseif not data:match('Q%d+') then
data = 'Bitte Wikidata Datenobjekt (Q123...) angeben!'
else
data = 'Bitte im Datenobjekt [[d:' .. data:match('Q%d+')
.. ']] einen Titel ([[d:Property:P1476|P1476]]) angeben!'
end
data = frame:extensionTag('span', data, { style="color:#f00;" })
return data
end
p.ref = function(frame)
local data = byWD(frame)
if not data or data == '' then data = message(frame) end
local result
if frame.args.name and frame.args.name ~= '' then
if frame.args.group and frame.args.group ~= '' then
result = '<ref name="' .. frame.args.name .. '" group="'
.. frame.args.group .. '">' .. data .. '</ref>'
else
result = '<ref name="' .. frame.args.name .. '">' .. data
.. '</ref>'
end
else
if frame.args.group and frame.args.group ~= '' then
result = '<ref group="' .. frame.args.group .. '">' .. data
.. '</ref>'
else
result = '<ref>' .. data .. '</ref>'
end
end
return frame:preprocess(result)
end
p.entry = function(frame)
local data = byWD(frame)
if not data or data == '' then return message(frame) end
mw.log(data)
return data
end
p.weblinks = function(frame)
local wdo = mw.wikibase.getEntityIdForCurrentPage()
if not wdo then return '' end
local tSource = mw.title.getCurrentTitle()
if not tSource then return '' end
local title = tSource.text
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
return title .. ' in...<ul><li>' .. table.concat(IDs, '</li><li>')
.. '</li></ul>'
end
return p