Module:Sports reference
| This Lua module is used on approximately 5,200 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:
local function category(s)
if mw.title.getCurrentTitle().namespace ~= 0 then
return ""
end
return "[[Category:Sports-Reference template " .. s .. "]]"
end
local function linktext(s1,s2,s3)
if (s3 == nil) or (s3 == "") then
return "[https://web.archive.org/web/20161204/https://www.sports-reference.com/olympics/athletes/" .. s1 .. ".html " .. s2 .. "] at [[Sports Reference#Olympics|Olympics at Sports-Reference.com]] (archived)" .. category("missing archive parameter")
else
return "[https://web.archive.org/web/" .. s3 .. "/https://www.sports-reference.com/olympics/athletes/" .. s1 .. ".html " .. s2 .. "] at [[Sports Reference#Olympics|Olympics at Sports-Reference.com]] (archived)"
end
end
local p = {}
function p.link(frame)
-- Optional first parameter contains ID portion of Sports-Reference URL.
-- Trim any leading or trailing spaces. If it contains ".html", remove it.
local id = string.gsub((mw.text.trim(frame.args[1]) or ""), ".html", "")
-- Optional second parameter contains name for link. Trim leading or trailing spaces.
-- If name is not provided, use article name without disambiguation.
local name = mw.text.trim(frame.args[2])
if (name == nil) or (name == "") then
name = string.gsub(mw.title.getCurrentTitle().text, "%s+%b()$", "", 1)
end
-- Optional third parameter contains date/time portion of Archive.org URL.
local archive = mw.text.trim(frame.args[3])
-- For articles without Wikidata property:
-- if ID not provided, return error text and tracking category
-- if ID is provided, return link and tracking category
local entity = mw.wikibase.getEntityObject() or {}
local claims = entity.claims or {}
local hasProp = claims["P1447"]
if not hasProp then
if (id == nil) or (id == "") then
return "<span class='error'>Sports-Reference template missing ID and not present in Wikidata.</span> [[Template:Sports reference#Add ID in Wikidata|How do I fix this?]]" .. category("missing ID and not in Wikidata")
else
return linktext(id,name,archive) .. category("with ID not in Wikidata")
end
end
-- For articles with Wikidata property:
-- if ID not provided, return link (using Wikidata) and tracking category
-- if ID is provided, return link (using ID) and one of two tracking categories
local propValue = hasProp[1].mainsnak.datavalue.value
if (id == nil) or (id == "") then
return linktext(propValue,name,archive) .. " [[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=Edit this at Wikidata |link=https://www.wikidata.org/wiki/" .. entity.id .. "#P1447|Edit this at Wikidata]]" -- .. category("using Wikidata")
end
for i, v in ipairs(hasProp) do
propValue = (v.mainsnak.datavalue or {}).value
if id == propValue then
return linktext(id,name,archive) -- .. category("with ID same as Wikidata")
end
end
return linktext(id,name,archive) .. category("with ID different from Wikidata")
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.