Modul:ExternalLinks

A Wikipédiából, a szabad enciklopédiából

ExternalLinks[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

require('strict')

local getArgs = require('Modul:Arguments').getArgs
local z = {}

local function simpletitle()
	return require('Modul:String').simpletitle()
end
 
local function IMDB(path, text)
	local frame = mw.getCurrentFrame()
	local pattern = '[https://www.imdb.com/%s %s] az [[Internet Movie Database]]-ben %s'
	return mw.ustring.format(pattern, path, text, frame:expandTemplate{title='en'} )
end

local function getWikidataID(typ)
	local item = mw.wikibase.getEntity()
	if not item then
		return nil
	end
	local ids = item:getBestStatements('P345')
	for _, id in pairs(ids) do
		if id and id.mainsnak.snaktype == 'value' then
			local idtext = id.mainsnak.datavalue.value
			if string.sub(idtext, 1, string.len(typ) ) == typ then
				return idtext
			end
		end
	end
	return nil
end

 
-- Az {{IMDb név}} sablon használja.
function z.IMDBname(frame)
	local args = getArgs(frame)
	local ID = args.id or args.ID or args[1]
	ID = (ID and 'nm' .. ID) or getWikidataID('nm') or ''
	local Name = args["név"] or args[2] or simpletitle()
	return IMDB("name/" .. ID, Name)
end
 
-- Az  {{IMDB díj}} sablon használja.
function z.IMDBaward(frame)
	local args = getArgs(frame)
	local dirs = { nm = 'name', tt = 'title' }
	local ID = args.id or args.ID or args[1] or ''
	local typ = (args['név'] and 'nm') or (args['cím'] and 'tt') or ''
	if ID ~= '' and typ == '' then
		return error("Ha megadsz azonosítót, akkor meg kell adnod a nevet vagy címet is")
	end
	local name = args['név'] or args['cím'] or simpletitle()
	if ID ~= '' then
		return IMDB(dirs[typ] .. '/' .. typ .. ID .. '/awards', name .. ' díjai')
	end
	ID = getWikidataID(typ)
	if ID then
		typ = string.sub(ID, 1, 2)
		if dirs[typ] then
			return IMDB(dirs[typ] .. '/' .. ID .. '/awards', name .. ' díjai')
		end
	end
	return nil
end
 
-- Az {{IMDb cím}} sablon használja.
--Paraméterek:
  --  @id – a film azonosítószáma az IMDb-n (az oldal URL-jéből olvasható ki,
                -- pl. https://imdb.com/title/tt0110912/ esetén az id 0110912)
--    @cím – a film címe, alapértelmezésben azonos a szócikk nevével
    --@leírás (opcionális) – a cím után jelenik meg, pl. itt adható meg az évszám, 
    --                       ha több azonos nevű film is van
 
-- A paraméterek ebben a sorrendben névtelenül is megadhatóak.
function z.IMDBtitle(frame)
	local args = getArgs(frame)
	local ID = args.id or args.ID or args[1]
	ID = (ID and 'tt' .. ID) or getWikidataID('tt')
	--local section = args.section
	local Title = args['cím'] or args[2] or simpletitle()
	local Description = args['leírás'] or args[3]
	Description = (Description and ' ' .. Description) or ''
	local Name = "''" .. Title .. "''" .. Description
	if ID then
		return IMDB("title/" .. ID, Name)
	else
		return IMDB("find?q=" .. mw.uri.encode(Title), Name)
	end
end

return z