Modulis:IMDb
Izskats

Iespējams, vēlies izveidot dokumentāciju šim modulim Vari eksperimentēt šī moduļa smilšu kastes (izveidot | spoguļversija) un testu (izveidot) lapā Lūdzu, kategorijas pievieno dokumentācijas apakšlapā. Moduļa apakšlapas. |
local messages = {
notFormat = "Lapas ar IMDb veidni, kam ir nederīga vērtība";
wdDiff = "P345: nesakrīt ar vērtību Vikidatos";
notWD = "P345: nav Vikidatos";
noValue = "Lapas ar IMDb veidni, kam ir nederīga vērtība"
}
local p = {}
local categories = {}
local entity = mw.wikibase.getEntityObject()
local yesno = require('Module:Yesno')
local getArgs = require('Module:Arguments').getArgs
function formatValue(str, len)
firsttwo = string.sub( str, 1,2 )
if firsttwo=='tt' or firsttwo=='nm' or firsttwo=='ch' or firsttwo=='co' or firsttwo=='ev' then
str = string.sub(str, 3)
end
return string.rep('0', len - #str) .. str
end
function checkFormat(fullprofile)
firsttwo = string.sub( fullprofile, 1,2 )
if firsttwo ~= 'ev' then
formatmatch = string.match(formatValue(fullprofile, 7), "^%d%d%d%d%d%d%d$")--(tt|nm|ch|co|ev)
else
formatmatch = string.match(fullprofile, "^ev%d%d%d%d%d%d%d/?%d?%d?%d?%d?$")--@todo: fix!
end
if not formatmatch then
table.insert(categories, messages.notFormat)
end
return link
end
function makeLink(fullprofile)
firsttwo = string.sub( fullprofile, 1,2 )
--@todo: pārveidot par switch?
if firsttwo=='tt' then link = "http://www.imdb.com/title/" .. fullprofile .. "/"
elseif firsttwo=='nm' then link = "http://www.imdb.com/name/" .. fullprofile .. "/"
elseif firsttwo=='ch' then link = "http://www.imdb.com/character/" .. fullprofile .. "/"
elseif firsttwo=='co' then link = "http://www.imdb.com/company/" .. fullprofile .. "/"
elseif firsttwo=='ev' then link = "http://www.imdb.com/event/" .. fullprofile .. "/"
--elseif ielikt kaut kādu kategoriju/parastu saiti
end
return link
end
function final(link, name)
finallink = '[' .. makeLink(link) .. ' ' .. name .. '] ' .. mw.getCurrentFrame():expandTemplate{ title="en ikona" }
return finallink
end
function p._main(args)
local value
local param = args[1] or args.id
local nowikidata = yesno(args.nowd, false)
local pagetype = args.type--ch/tt etc.
local name = args[2] or "''IMDb'' profils"
if param then
value = pagetype .. formatValue(args.param, 7)
else
if nowikidata == true then
table.insert(categories, messages.noValue)
end
end
if entity then
if entity.claims["P345"] then
local mainsnak = entity.claims["P345"][1].mainsnak
if mainsnak.snaktype == 'value' then
wdvalue = mainsnak.datavalue.value
if not value then value = wdvalue elseif wdvalue ~= value and nowikidata~=true then
table.insert(categories, messages.wdDiff)
end
end
else
table.insert(categories, messages.notWD)
end
end
if value and makeLink(value) then
finallink = final(value,name)
checkFormat(value)
end
for i, cat in ipairs(categories) do
categories[i] = string.format('[[Kategorija:%s]]', cat)
--categories[i] = cat
end
return (finallink or value or '') .. ' ' .. table.concat(categories)
end
function p.main(frame)
local args = getArgs(frame, {
wrappers = "Veidne:IMDB",
"Veidne:IMDB filma",
"Veidne:IMDB sērija",
"Veidne:IMDB sērijas",
"Veidne:IMDB tēls",
"Veidne:IMDB uzņēmums",
"Veidne:IMDb profils"
})
return p._main(args)
end
return p