Content deleted Content added
Remove commented-out code, comments at top (moved to doc page), and "untested" warning (it's used in a high-risk template. Does that not count as "tested" enought?) |
catch pages that have no connected WIkidata entity |
||
(2 intermediate revisions by the same user not shown) | |||
Line 2:
p.main = function ( frame )
local
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return nil end
local prevalenceClaims = mw.wikibase.getBestStatements(qid, "P1193")
-- Run through all prevalence claims - the table prevalenceClaims always exists but may be empty
▲ local pRange = ''
▲ for i, prevalenceClaim in pairs( prevalenceClaims ) do
▲ local prevalenceValue = prevalenceClaim.mainsnak.datavalue.value
-- Split multiple claims
▲ if prevalenceValue then
▲ if string.len( pRange ) > 0 then
▲ -- Maybe line break instead?
pRange = pRange .. ', '▼
end▼
▲ local upperBound = prevalenceValue.upperBound * 100
if lowerBound ~= upperBound then
▲ pRange = pRange .. lowerBound
▲ if lowerBound ~= upperBound then
end
▲ pRange = pRange .. ' to ' .. upperBound
local amount = prevalenceValue.amount * 100
end
if prevalenceClaim.qualifiers then▼
pRange = pRange .. '%'
-- Qualifiers for prevalence are currently unstandardized.▼
-- Keep guessing until the right one is found.▼
local quals = prevalenceClaim.qualifiers.P276 or -- ___location▼
prevalenceClaim.qualifiers.P1001 or -- applies to jurisdiction▼
if quals then▼
pRange = pRange .. ' ('▼
local link = mw.wikibase.sitelink( 'Q' .. qualId )▼
local label = ({▼
-- Certain geographic locales might need a▼
-- manual-ish override for labels. ▼
[ 132453 ] = 'developed world'▼
})[ qualId ] or mw.wikibase.label( 'Q' .. qualId )▼
label = '[[' .. link .. '|' .. label .. ']]'▼
▲ pRange = pRange .. label
end
local qualId = qual.datavalue.value[ 'numeric-id' ]
▲ end
end
end
--[[▼
-- Todo: References▼
if prevalenceClaim.references then ▼
▲ end
end
end
end
return
end
|