Module:Wd: Difference between revisions

Content deleted Content added
Increased efficiency a bit
Fix for decades/centuries/millenniums and other minor edits
Line 211:
-- if precision is tens/hundreds/thousands of years
if precision >= 6 then
-- if unit added then round centuries/millenniums up (e.g. 21st century or 3rd millennium, but 2010s for decade)
mayAddCalendar = true
if addUnit then
if precision <= 7 then
-- if unit added then round centuries/millenniums up (e.g. 21st20th century or 3rd millennium, but 2010s for decade)
yRound = math.ceil(yDiv)
if addUnit then
if precision == 6 then
suffix = " millennium"
Line 225 ⟶ 226:
suffix = self:getOrdinalSuffix(yRound) .. suffix
else
-- if no unit added, take the first year of the century/millennium
yRound = math.floor(yDiv) * yFactor
-- (e.g. 1901 for 20th century or 2001 for 3rd millennium)
suffix = "s"
yRound = math.floor(yDivyRound - 1) * yFactor + 1
end
else
-- precision == 8
-- round decades down (e.g. 2010s)
yRound = math.floor(yDiv) * yFactor
if addUnit then
suffix = "s"
end
end
if not addUnit and sign < 0 then
-- if BCE then compensate for "counting backwards"
-- (e.g. -2019 for 2010s BCE, -2000 for 20th century BCE or -3000 for 3rd millennium BCE)
yRound = yRound + yFactor - 1
end
else
Line 415 ⟶ 429:
 
function State:getRawValue(snak)
local temp, value
if snak.snaktype == 'value' and snak.datavalue.type == 'wikibase-entityid' then
return "Q" .. snak.datavalue.value['numeric-id']
elseif snak.snaktype == 'somevalue' then
if value ==return " " then -- single space represents 'somevalue'
elseif snak.snaktype == 'novalue' then
if value ==return "" then -- empty value represents 'novalue'
else
return self:getValue(snak, false, false)
Line 424 ⟶ 441:
 
function State:snakEqualsValue(snak, value)
local snakValue = self:getRawValue(snak)
if snak.snaktype == 'value' then
local snakValue = self:getRawValue(snak)
if snakValue and snak.datavalue.type == 'wikibase-entityid' then value = value:upper() end
if snakValue and snak.datavalue.type == 'wikibase-entityid' then value = value:upper() end
return snakValue == value
return snakValue == value
elseif snak.snaktype == 'somevalue' then
if value == " " then -- single space represents 'somevalue'
return true
else
return false
end
elseif snak.snaktype == 'novalue' then
if value == "" then -- empty value represents 'novalue'
return true
else
return false
end
else
return false
end
end
 
Line 627 ⟶ 628:
if entity and entity.claims then claims = entity.claims[propertyID] end
if claims then
for ki, v in pairsipairs(claims) do
rankPos = _:convertRank(v.rank)
if _:rankMatches(rankPos) then
Line 652 ⟶ 653:
_ = _ or State.new()
local entity, propertyID, propertyValue, qualifierID, claims, qualifiers, rankPos, outValue, outInter, outQualifier, doneoutQualifiers
local done = false
local nextArg = mw.text.trim(args[1] or "")
local nextIndex = 2
Line 693 ⟶ 696:
if entity and entity.claims then claims = entity.claims[propertyID] end
if claims then
for ki, v in pairsipairs(claims) do
rankPos = _:convertRank(v.rank)
if propertyValue == nil or _:snakEqualsValue(v.mainsnak, propertyValue) then
Line 699 ⟶ 702:
outValue = nil
outInter = nil
outQualifieroutQualifiers = {}
if _.propertyWithQualifier then
Line 708 ⟶ 711:
if v.qualifiers then qualifiers = v.qualifiers[qualifierID] end
if (not _.propertyWithQualifier or outValue) and qualifiers then
-- get a bare qualifier, or qualifierthe qualifiers connected to the property if it had a value
for k2i2, v2 in pairsipairs(v.qualifiers[qualifierID]) do
outInter = _:getValue(v2, _.withUnit, _.linked)
if outInter then
Line 718 ⟶ 721:
end
else
outQualifieroutQualifiers[#outQualifieroutQualifiers + 1] = outInter
end
end
Line 725 ⟶ 728:
if _.propertyWithQualifier and outValue then
outQualifieroutQualifiers = table.concat(outQualifieroutQualifiers, ", ")
if outQualifieroutQualifiers ~= "" then
outQualifieroutQualifiers = " <span style=\"font-size:smaller\">(" .. outQualifieroutQualifiers .. ")</span>"
outValue = outValue .. outQualifieroutQualifiers
end