Module:Getlabel

From Wikispecies
Jump to navigation Jump to search

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

-- - getLabel returns the label for a Qid
-- if label doesn't exist, it returns the Qid
-- The label in a Wikidata item is subject to vulnerabilities 
-- that an attacker might try to exploit.
-- It needs to be 'sanitised' by removing any wikitext before use.
-- If it doesn't exist, just return the id for the item
-- to use elsewhere:
-- 1. {{#invoke:NameOfModule |getLabel}}
-- 2. {{#invoke:NameOfModule |getLabel | QidOfRequiredItem}}
-- 3. {{#invoke:NameOfModule |getLabel | qid=QidOfRequiredItem}}
-- 1 returns the label from the current asociated page on Wikidata
-- 2 and 3 both return the label for the given Qid.

p = {}

p.getLabel = function(frame)
 local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
 if itemID == "" then itemID = nil end
 local label = mw.wikibase.label(itemID)
 if label then
  label = mw.text.nowiki(label)
 else
  label = itemID
 end
 return label
end

return p