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 FORMAT_CATEGORY = "Lapas ar IMDb veidni, kam ir nederīga vērtība"
local WD_DIFFERENT_CATEGORY = "P345: nesakrīt ar vērtību Vikidatos"
local NOT_IN_WD_CATEGORY = "P345: nav Vikidatos"
local NO_VALUE = "Nav vērtības"
local p = {}
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 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 pad(str, len, char)
if char == nil then char = ' ' end
return string.rep(char, len - #str) .. str
end
]=]
function p._main(args)
local categories = {}
local value
local param = args.param
--format = "(ch|tt)%d*" (ev\d{7}/\d{4})|((tt|nm|ch|co|ev)\d{7})
local nowikidata = false
local nowd = yesno(args.nowd)
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, NO_VALUE)
end
end
if nowikidata == false then
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 then
table.insert(categories, WD_DIFFERENT_CATEGORY)
end
end
else
table.insert(categories, NOT_IN_WD_CATEGORY)
end
end
end--"if nowikidata == false then" beigas
if value and makeLink(value) then
finallink = '[' .. makeLink(value) .. ' ' .. name .. '] ' .. mw.getCurrentFrame():expandTemplate{ title="en ikona" }
formatmatch = string.match(formatValue(param, 7), "%d%d%d%d%d%d%d")--(tt|nm|ch|co|ev)
if not formatmatch then
table.insert(categories, FORMAT_CATEGORY)
end
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)
--[=[require('Module:Arguments').getArgs(frame, {
wrappers = "Veidne:IMDB",
"Veidne:IMDB filma",
"Veidne:IMDB sērija",
"Veidne:IMDB sērijas",
"Veidne:IMDB tēls",
"Veidne:IMDB uzņēmums"
+IMDb profils
})]=]
return p._main(args)
end
return p