Module:Sandbox/marius851000/mkey

From Wikidata
Jump to navigation Jump to search
Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Sandbox/marius851000/mkey/doc

Code

r = {}

-- mkey : a string that is in one of the following format :
-- Q... for a QID
-- S... for a string (the string is everything after the S)
-- unknown for an unknwon propertie

r.mkeyToText = function(mkey) --TODO: properly localize
	if (#mkey == 0) then
		error("The key for mkeyToText is empty");
	end
	firstCharacter = string.sub(mkey, 1, 1);
	if (firstCharacter == "S") then
		return string.sub(mkey, 2);
	elseif (firstCharacter == "Q") then
		return mw.getCurrentFrame():expandTemplate{title = "LinkedLabel", args = { mkey }}
	elseif (mkey == "unknown") then
		return mw.getCurrentFrame():expandTemplate{title = "Label", args = { "Q4233718" }}
	else
		error("The given mkey ("..mkey..") isn't in a valid format");
	end
end

r.textToMkey = function(str)
	return "S"..str
end

r.qidToMkey = function(qid)
	return qid
end

r.unknownMkey = function()
	return "unknown"
end

return r