Module

Wikibase

Revision as of 02:45, 24 December 2018 by 0x010C (talk | contribs) (Created page with "---------- Module:Wikibase ---------------- local p = {} -- Return the label of a given data item, or of connected page -- if no argument is provided to this method. function...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Wikibase/doc

---------- Module:Wikibase ----------------
local p = {}

-- Return the label of a given data item, or of connected page
-- if no argument is provided to this method.
function p.label(frame)
	id = mw.text.trim(frame.args[1])
	return mw.wikibase.label( id )
end

-- Return the description of a given data item, or of connected page
-- if no argument is provided to this method.
function p.description(frame)
	id = mw.text.trim(frame.args[1])
	return mw.wikibase.description( id )
end

-- Return the data type of a property
function p.datatype(frame)
	if frame.args[1] and string.find(frame.args[1], "Property:P") then
		if mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P"))  then
			return mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P") ).datatype
		end
	elseif frame.args[1] and string.find(frame.args[1], "P") then
		if mw.wikibase.getEntityObject(frame.args[1])  then
			return mw.wikibase.getEntityObject(frame.args[1]).datatype
		end
	end
end

-- Return the description of a given data item, or of connected page
-- if no argument is provided to this method.
function p.formatedStatement(frame)
	qid = mw.text.trim(frame.args[1])
	property = mw.text.trim(frame.args[2])
	statement = mw.wikibase.getBestStatements( qid, property )
	stype = statement[1]["mainsnak"]["datavalue"]["type"]
	
	if stype == "wikibase-entityid" then
		return "[["..qid.."|"..mw.wikibase.getLabel(statement[1]["mainsnak"]["datavalue"]["value"]["id"]).."]]"
	end

	return statement[1]["mainsnak"]["datavalue"]["value"]
end

return p