Permanently protected module

Module:Wikibase

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Module documentation[create]
-- from https://www.wikidata.org/w/index.php?title=Module:Wikidata&action=edit for full details, please see there
--
-- null test
local p = {}
 

 
-- Return the label of a given data item.
function p.label(frame)
        if frame.args[1] == nil then
            entity = mw.wikibase.getEntityObject()
            if not entity then return nil end
 
            id = entity.id
        else
            id = frame.args[1]
        end
 
        return mw.wikibase.label( id )
end

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

function p.descriptions(frame)
	if frame.args[1] and frame.args[2] and mw.wikibase.getEntityObject(frame.args[1]) then
		local args2 = frame:preprocess( frame.args[2] )
		if mw.wikibase.getEntityObject(frame.args[1]).descriptions and mw.language.isKnownLanguageTag(args2) == true then
			local fallbacks = mw.language.getFallbacksFor( args2 )
			if mw.wikibase.getEntityObject(frame.args[1]).descriptions[args2] then
				return mw.wikibase.getEntityObject(frame.args[1]).descriptions[args2].value
			else
				for i, j in pairs (mw.language.getFallbacksFor(args2)) do
					description = mw.wikibase.getEntityObject(frame.args[1]).descriptions[j].value
					if description then
						return description
					end
				end
			end
		end
	end
end

return p