Modul:WikidataCheck

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 i, statement in pairs(hasProp) do
		if statement.mainsnak.datavalue.value == value then
			return "[[Kategorie:Monitoring:" .. catbase .. " odpovídá Wikidatům|" .. pagename .. "]]" -- yay!
		end
	end
	return "[[Kategorie:Údržba:" .. catbase .. " se liší od Wikidat|" .. pagename .. "]]" -- needs human review :(
end

return p