Module:Sandbox/Zyxw/test
Appearance
< Module:Sandbox | Zyxw
-- This is the code to insert a template to indicate that the link is in English:
-- frame:expandTemplate{ title = "LANGUAGETEMPLATENAME", args = { "en" } }
-- It is obviously not used in the English Wikipedia itself.
local function linktext(s1,s2)
entity = mw.wikibase.getEntityObject()
if s2 == "" then
s2 = nil
end
if not entity then
label = s2 or mw.title.getCurrentTitle().text
else
label = s2 or mw.wikibase.label(entity.id) or mw.title.getCurrentTitle().text
end
if (s1 == nil) or (s1 == "") then
-- This text returns an error that says that the Sports Reference ID is neither
-- present on Wikidata nor in the article, and categorises the page as missing
-- the Wikidata property.
return "<span class='error'>Sports Reference ID is neither present in Wikidata nor the article!</span> \
[[Template:Sports-reference#Add ID in Wikidata|How do I fix this?]]\
[[Category:Sports Reference ID not in Wikidata]]"
else
-- This is the text that is returned if there is a Sports Reference ID on Wikidata or in the article.
return "[https://www.sports-reference.com/olympics/athletes/" .. s1 .. ".html " .. label .. "] at [[Sports Reference]]"
end
end
local p = {}
function p.link(frame)
-- If the optional first parameter contains ".html", remove it. Trim any leading or trailing spaces.
id = string.gsub((mw.text.trim(frame.args[1]) or ""), ".html", "")
-- Optional second parameter contains name
name = mw.text.trim(frame.args[2])
if not mw.wikibase then
return linktext(id,name)
end
local entity = mw.wikibase.getEntityObject()
if not entity then
-- Category for articles that don't have items in Wikidata.
return linktext(id,name) .. "[[Category:Articles without Wikidata item]]"
end
local claims = entity.claims or {}
local hasProp = claims["P1447"]
if not hasProp then
-- Category for articles that don't have the Sports Reference ID property on Wikidata.
return linktext(id,name) .. "[[Category:Sports Reference ID not in Wikidata]]"
end
local propValue = hasProp[1].mainsnak.datavalue.value
-- If ID is not provided in article, then use Sports Reference ID property on Wikidata.
if (id == nil) or (id == "") then
return linktext(propValue,name)
end
-- If ID is provided in article, then use it. Add category if it does not match property on Wikidata.
if id == propValue then
return linktext(id,name)
else
return linktext(id,name) .. "[[Category:Sports Reference ID different from Wikidata]]"
end
end
return p