Módulo:WBHacks

Fonte: Enciclopédia de conhecimento da Igreja de Deus
Revisão em 01h36min de 14 de maio de 2024 por Jaewoo (discussão | contribs) (Criou a página com "JSON = require('Module:JSON') local p = {} function p.get( id ) --this just returns the json object of the id local id = id if string.find(id, "P") ~= nil then if string.find(id, "Property") == nil then id = "Property:" .. id end end local pg = mw.title.new(id):getContent() return pg and JSON:decode(pg) end function p.thing(obj, typ, lang) -- Can be used to fetch either label or description, depends on what you...")
(dif) ← Revisão anterior | Revisão atual (dif) | Revisão seguinte → (dif)
Saltar para a navegação Saltar para a pesquisa

A documentação para este módulo pode ser criada na página Módulo:WBHacks/doc

JSON = require('Module:JSON')
local p = {}
	
	function p.get( id )
				--this just returns the json object of the id
				local id = id
				if string.find(id, "P") ~= nil then
								if string.find(id, "Property") == nil then
												id = "Property:" .. id
								end
				end
				local pg = mw.title.new(id):getContent()
				return pg and JSON:decode(pg)
end
function p.thing(obj, typ, lang)
				-- Can be used to fetch either label or description, depends on what you want.
				local x = obj[typ][lang]
				if x == nil then
								x = obj[typ].en -- fallback to english
				end
				return x
end
function p.label(frame)
				local config = frame.args
	
				local qid = config.qid
				local lang = config.lang
				local obj = p.get(qid)
				return obj and p.thing(obj, "label", lang) or "(no label)"
end
	
	function p.description(frame)
				local config = frame.args
	
				local qid = config.qid
				local lang = config.lang
				local obj = p.get(qid)
				return p.thing(obj, "description", lang)
end
	function p.howmany(frame)
				local config = frame.args
	
				local qid = config.qid
				local obj = p.get(qid)
				local count = 0
				for language,value in pairs(obj[config.what]) do
								count=count+1
				end
				return count
end
	function p.datatype(frame)
				local config = frame.args
	
				local qid = config.qid
				local obj = p.get(qid)
				return obj["datatype"]
end
return p