Module:Sports reference
Appearance
| This Lua module is used on approximately 5,600 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
Usage
This module returns a link to Olympics at Sports-Reference.com. The module only has one function, link, which returns the external link text ready for use.
{{#invoke:Sports reference|link|id (optional)|name (optional)}}
For complete usage and examples, see the {{Sports reference}} template:
-- 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(s)
entity = mw.wikibase.getEntityObject()
if not entity then
label = mw.title.getCurrentTitle().text
else
label = mw.wikibase.label(entity.id) or mw.title.getCurrentTitle().text
end
if (s == nil) or (s == "") 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 not on Wikidata]]"
else
-- This is the text that is returned if there is a Sports Reference ID on Wikidata or in the article.
return "[http://www.sports-reference.com/olympics/athletes/" .. s .. ".html " .. label .. "] at [[Sports Reference]]"
end
end
local p = {}
function p.link(frame)
id = string.gsub((frame.args[1] or ""), ".html", "")
if not mw.wikibase then
return linktext(id)
end
local entity = mw.wikibase.getEntityObject()
if not entity then
-- This is the place to insert a category for articles that don't have items in Wikidata.
-- enwiki doesn't seem to have such a category, so in this case it is empty.
-- For other wikis, just remove the two comment dashes and insert the correct category name.
return linktext(id) -- .. "[[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 property on Wikidata.
return linktext(id) .. "[[Category:Sports Reference not on Wikidata]]"
end
local propValue = hasProp[1].mainsnak.datavalue.value
return linktext(propValue)
end
return p