Modul:WikidataCheck
Vzhled
Převzato z anglické Wikipedie, dokumentaci vizte na en:Module:WikidataCheck.
local p = {}
function p.wikidatacheck(frame)
-- local pframe = frame:getParent()
-- local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local property = config.property
local value = config.value
local catbase = config.category
local namespaces = config.namespaces
local title = mw.title.getCurrentTitle()
local pagename = title.text
local ok = false -- one-way flag to check if we're in a good namespace
local ns = title.namespace
for v in mw.text.gsplit( namespaces, ",", true ) do
if tonumber(v) == ns then
ok = true
break
end
end
if not ok then -- not in one of the approved namespaces
return ""
end
local entity = config and config.entity or mw.wikibase.getEntityObject()
if not entity then -- no Wikidata item
return "[[Kategorie:Údržba:" .. catbase .. " není na Wikidatech]]"
end
local hasProp = entity.claims and entity.claims[property]
if not hasProp then -- no claim of that property
return "[[Kategorie:Údržba:" .. catbase .. " není na Wikidatech|" .. pagename .. "]]" -- bad. Bot needs to add the property
end
for _, statement in pairs(hasProp) do
if statement.mainsnak.snaktype == "value" then
if statement.mainsnak.datavalue.value == value then
return "[[Kategorie:Údržba:" .. catbase .. " odpovídá Wikidatům|" .. pagename .. "]]" -- yay!
end
end
end
--[==[ local datatype = mw.wikibase.getEntityObject(property).datatype
if datatype == "commonsMedia" or datatype == "string" or datatype == "url" then
for _, statement in pairs(hasProp) do
if statement.mainsnak.snaktype == "value" then
if statement.mainsnak.datavalue.value == value then
return "[[Kategorie:Údržba:" .. catbase .. " odpovídá Wikidatům|" .. pagename .. "]]" -- yay!
end
end
end
elseif datatype == "globe-coordinate" then
elseif datatype == "monolingualtext" then
for _, statement in pairs(hasProp) do
if statement.mainsnak.snaktype == "value" then
if statement.mainsnak.datavalue.value.text == value then
return "[[Kategorie:Údržba:" .. catbase .. " odpovídá Wikidatům|" .. pagename .. "]]" -- yay!
end
end
end
elseif datatype == "quantity" then
elseif datatype == "time" then
elseif datatype == "wikibase-item" then
local Pages, Sitelinks = {}, {}
for _, statement in pairs(hasProp) do
if statement.mainsnak.snaktype == "value" then
local sitelink = mw.wikibase.sitelink('Q' .. statement.mainsnak.datavalue.value["numeric-id"])
if sitelink then
table.insert( Sitelinks, sitelink )
end
end
end
if mw.ustring.match( value, '<[^<>%w]-br[^<>%w]->' ) then
for string in mw.text.gsplit( value, '<[^<>%w]-br[^<>%w]->' ) do
if mw.ustring.match( string, '%[%[[^%]%[]-%]%]' ) then
for page in mw.ustring.gmatch( value, "%[%[%s*([^|%]]-)%s*[|%]]" ) do
table.insert( Pages, page )
end
else
table.insert( Pages, mw.text.trim(string) )
end
end
elseif mw.ustring.match( value, '%[%[[^%]%[]-%]%]' ) then
for page in mw.ustring.gmatch( value, "%[%[%s*([^|%]]-)%s*[|%]]" ) do
table.insert( Pages, page )
end
end
return "[[Kategorie:Údržba:" .. catbase .. " odpovídá Wikidatům|" .. pagename .. "]]" -- yay!
end ]==]--
return "[[Kategorie:Údržba:" .. catbase .. " se liší od Wikidat|" .. pagename .. "]]" -- needs human review :(
end
return p