Modul:RelatedSites
Věci přenesené přes šablony z cs:wiki
local p = {}
local Wikidata = require 'Modul:Wikidata'
function p.link(frame)
local site = frame.args[1] or frame.args.site
if not site or site == '' then return error("Nezadán projekt!") end
local entity = mw.wikibase.getEntityObject()
if not entity then
return ''
end
local p373 = Wikidata.formatStatementsFromLua{ entity = entity, property = "p373", limit = 1 }
local p935 = Wikidata.formatStatementsFromLua{ entity = entity, property = "p935", limit = 1 }
local commonswiki = Wikidata.getSitelinkFromLua{ site = "commonswiki" }
local link = ""
-- Wikimedia Commons
if site == "commons" then
if commonswiki then
if mw.ustring.find(commonswiki,"Category:") then
if p935 then
link = link .. p935
else return '' end
else
link = link .. commonswiki
end
elseif p935 then
link = link .. p935
else return '' end
elseif site == "commonscat" then
if commonswiki then
if mw.ustring.find(commonswiki,"Category:") then
link = link .. mw.ustring.sub(commonswiki,10)
elseif p373 then
link = link .. p373
end
elseif p373 then
link = link .. p373
end
end
return link
end
function p.subst(frame)
if not mw.isSubsting() then return error("Modul je nutné vkládat substitucí!") end
local site = frame.args[1] or frame.args.site
if not site or site == '' then return error("Nezadán projekt!") end
local entity = mw.wikibase.getEntityObject()
if not entity then
return ''
end
local p373 = Wikidata.formatStatementsFromLua{ entity = entity, property = "p373", limit = 1 }
local p691 = Wikidata.formatStatementsFromLua{ entity = entity, property = "p691", limit = 1 }
local p935 = Wikidata.formatStatementsFromLua{ entity = entity, property = "p935", limit = 1 }
local p998 = Wikidata.formatStatementsFromLua{ entity = entity, property = "p998", limit = 1 }
local commonswiki, cswikisource, cswikiquote, cswikinews
if entity.sitelinks.commonswiki then
commonswiki = entity.sitelinks.commonswiki.title
end
if entity.sitelinks.cswikisource then
cswikisource = entity.sitelinks.cswikisource.title
end
if entity.sitelinks.cswikiquote then
cswikiquote = entity.sitelinks.cswikiquote.title
end
if entity.sitelinks.cswikinews then
cswikinews = entity.sitelinks.cswikinews.title
end
local link = ""
-- Wikimedia Commons
if site == "commons" then
if commonswiki then
if string.find(commonswiki,"Category:") then
if p935 then
link = link .. "galerie=" .. p935
else return ''
end
else link = link .. "galerie=" .. commonswiki
end
elseif p935 then
link = link .. "galerie=" .. p935
else return ''
end
elseif site == "commonscat" then
if commonswiki then
if string.find(commonswiki,"Category:") then
link = link .. "kategorie=" .. string.sub(commonswiki,10)
elseif p373 then
link = link .. "kategorie=" .. p373
end
elseif p373 then
link = link .. "kategorie=" .. p373
end
-- Wikisource
elseif site == "wikisource" then
if cswikisource then
if string.find(cswikisource,"Kategorie:") then
link = link .. "kategorie=" .. string.sub(cswikisource,11)
elseif string.find(cswikisource,"Autor:") then
link = link .. "autor=" .. string.sub(cswikisource,7)
else link = link .. "dílo=" .. cswikisource
end
end
-- Wikiquote
elseif site == "wikiquote" then
if cswikiquote then
if string.find(cswikiquote,"Kategorie:") then
link = link .. "kategorie=" .. string.sub(cswikiquote,11)
elseif string.find(cswikiquote,"Dílo:") then
link = link .. "dílo=" .. string.sub(cswikiquote,6)
elseif entity.claims[31][0].mainsnak.datavalue.value == 5 or entity.claims[21][0].mainsnak.datavalue.value or entity.claims[106][0].mainsnak.datavalue.value then
link = link .. "osoba=" .. cswikiquote
else
link = link .. "téma=" .. cswikiquote
end
end
-- NKČR
elseif site == "nkcr" then
if p691 then
link = link .. p691 .. "|" .. entity:getLabel( 'cs' )
end
-- Open Directory
elseif site == "dmoz" then
if p998 then
link = link .. "* [[Dmoz:" .. p998 .. "]]\n"
end
end
return link
end
return p