Module:Wd: Difference between revisions
m
1 revision imported
Johnrdorazio (talk | contribs) No edit summary |
Johnrdorazio (talk | contribs) m (1 revision imported) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 68: | Line 68: | ||
local aliasesP = { | local aliasesP = { | ||
coord = " | coord = "P625", | ||
----------------------- | ----------------------- | ||
image = " | image = "P18", | ||
author = " | author = "P50", | ||
publisher = " | publisher = "P123", | ||
importedFrom = " | importedFrom = "P143", | ||
statedIn = " | statedIn = "P248", | ||
pages = " | pages = "P304", | ||
language = " | language = "P407", | ||
hasPart = " | hasPart = "P527", | ||
publicationDate = " | publicationDate = "P577", | ||
startTime = " | startTime = "P580", | ||
endTime = " | endTime = "P582", | ||
chapter = " | chapter = "P792", | ||
retrieved = " | retrieved = "P813", | ||
referenceURL = " | referenceURL = "P854", | ||
sectionVerseOrParagraph = " | sectionVerseOrParagraph = "P958", | ||
archiveURL = " | archiveURL = "P1065", | ||
title = " | title = "P1476", | ||
formatterURL = " | formatterURL = "P1630", | ||
quote = " | quote = "P1683", | ||
shortName = " | shortName = "P1813", | ||
definingFormula = " | definingFormula = "P2534", | ||
archiveDate = " | archiveDate = "P2960", | ||
inferredFrom = " | inferredFrom = "P3452", | ||
typeOfReference = " | typeOfReference = "P3865", | ||
column = " | column = "P3903" | ||
} | } | ||
local aliasesQ = { | local aliasesQ = { | ||
percentage = " | percentage = "Q11229", | ||
prolepticJulianCalendar = " | prolepticJulianCalendar = "Q1985786", | ||
citeWeb = " | citeWeb = "Q5637226", | ||
citeQ = " | citeQ = "Q22321052" | ||
} | } | ||
Line 194: | Line 194: | ||
cfg.langObj = mw.language.new(cfg.langCode) | cfg.langObj = mw.language.new(cfg.langCode) | ||
cfg.siteID = mw.wikibase. | cfg.siteID = mw.wikibase.getGlobalSiteId() | ||
cfg.states = {} | cfg.states = {} | ||
Line 653: | Line 653: | ||
function Config:getLabel(id, raw, link, short) | function Config:getLabel(id, raw, link, short) | ||
local label = nil | local label = nil | ||
local title | local prefix, title= "", nil | ||
if not id then | if not id then | ||
Line 670: | Line 669: | ||
if mw.wikibase.isValidEntityId(id) and mw.wikibase.entityExists(id) then | if mw.wikibase.isValidEntityId(id) and mw.wikibase.entityExists(id) then | ||
label = id | label = id | ||
end | end | ||
prefix = "d:" | prefix, title = "d:Special:EntityPage/", label -- may be nil | ||
else | else | ||
-- try short name first if requested | -- try short name first if requested | ||
Line 691: | Line 684: | ||
-- get label | -- get label | ||
if not label then | if not label then | ||
label = mw.wikibase.getLabelByLang(id, self.langCode) | label = mw.wikibase.getLabelByLang(id, self.langCode) -- XXX: should use fallback labels? | ||
end | end | ||
end | end | ||
Line 704: | Line 697: | ||
elseif id:sub(1,1) == "P" then | elseif id:sub(1,1) == "P" then | ||
-- properties have no sitelink, link to Wikidata instead | -- properties have no sitelink, link to Wikidata instead | ||
title | prefix, title = "d:Special:EntityPage/", id | ||
end | end | ||
end | end | ||
label = mw.text.nowiki(label) -- escape raw label text so it cannot be wikitext markup | |||
if title then | if title then | ||
label = buildWikilink(prefix .. title, label) | label = buildWikilink(prefix .. title, label) | ||
Line 740: | Line 733: | ||
end | end | ||
value = "[[File:OOjs UI icon edit-ltr-progressive.svg|frameless|text-top|10px|alt=" .. i18n['info']['edit-on-wikidata'] .. "|link=https:// | value = "[[File:OOjs UI icon edit-ltr-progressive.svg|frameless|text-top|10px|alt=" .. i18n['info']['edit-on-wikidata'] .. "|link=https://www.wikidata.org/wiki/" .. prefix .. self.entityID .. "?uselang=" .. self.langCode | ||
if self.propertyID then | if self.propertyID then | ||
Line 2,541: | Line 2,534: | ||
-- main function that is supposed to be used by wrapper templates | -- main function that is supposed to be used by wrapper templates | ||
function p.main(frame) | function p.main(frame) | ||
if not mw.wikibase then return nil end | |||
local f, args | local f, args | ||