Content deleted Content added
mNo edit summary |
Replaced flag 'unit' with flag 'raw', added flag 'mdy', fixed aliases for function 'label' |
||
Line 32:
stt.period = 0
stt.propertyWithQualifier = false
stt.
stt.rawValue = false
stt.shortName = false
stt.singleValue = false
stt.mdyDate = false
stt.langCode = mw.language.getContentLanguage().code
Line 133 ⟶ 134:
end
function State:convertUnit(unit,
local itemID, label, target
Line 150 ⟶ 151:
target = nil
if
target = mw.wikibase.sitelink(itemID)
end
if
if target then
return " " .. "[[" .. target .. "|" .. (label or target) .. "]]"
Line 160 ⟶ 161:
if not label then
return " " .. "[[
end
end
Line 193 ⟶ 194:
end
function State:getValue(snak,
if snak.snaktype == 'value' then
Line 210 ⟶ 211:
local value = mw.ustring.gsub(snak.datavalue.value['amount'], "^\+(.+)$", "%1")
if
local unit = self:convertUnit(snak.datavalue.value['unit'],
if unit then
value = value .. unit
Line 219 ⟶ 220:
return value
elseif snak.datavalue.type == 'time' then
local y, m, d, p, yDiv, yRound, yFull, value, calendarID, dateStr
local yFactor = 1
local sign = 1
Line 255 ⟶ 256:
yRound = math.ceil(yDiv)
if
if precision == 6 then
suffix = " millennium"
Line 264 ⟶ 265:
suffix = self:getOrdinalSuffix(yRound) .. suffix
else
-- if
-- (e.g. 1901 for 20th century or 2001 for 3rd millennium)
yRound = (yRound - 1) * yFactor + 1
Line 273 ⟶ 274:
yRound = math.floor(yDiv) * yFactor
if
suffix = "s"
end
end
if
-- if BCE then compensate for "counting backwards"
-- (e.g. -2019 for 2010s BCE, -2000 for 20th century BCE or -3000 for 3rd millennium BCE)
Line 338 ⟶ 339:
end
if
if precision == 3 then
suffix = " million years"
Line 364 ⟶ 365:
if calendarID and calendarID == aliasesQ.prolepticJulianCalendar then
if
if
calendar = " ([[Julian calendar|Julian]])"
else
Line 376 ⟶ 377:
end
if
local ce = nil
Line 386 ⟶ 387:
if ce then
if
ce = "[[Common Era|" .. ce .. "]]"
end
Line 395 ⟶ 396:
if m then
if d then
dateStr = dateStr .. " " .. d .. ","
else
dateStr = d .. " " .. dateStr
end
end
value = dateStr .. " " .. value
end
Line 430 ⟶ 437:
local partsGlue = ", "
if
degSymbol = "/"
minSymbol = "/"
Line 492 ⟶ 499:
value = latValue .. partsGlue .. lonValue
if
globe = self:parseWikidataURL(snak.datavalue.value['globe'])
Line 509 ⟶ 516:
local target = nil
local itemID = "Q" .. snak.datavalue.value['numeric-id']
if raw then
if link then
return "[[d:" .. itemID .. "|" .. itemID .. "]]"
else
return itemID
end
end
if self.shortName then
Line 518 ⟶ 533:
end
if
target = mw.wikibase.sitelink(itemID)
end
if
if target then
value = "[[" .. target .. "|" .. (value or target) .. "]]"
elseif not value then
value = "[[
end
elseif not value then
Line 537 ⟶ 552:
end
elseif snak.snaktype == 'somevalue' then
if raw then
return " " -- single space represents 'somevalue'
else
return "unknown"
end
elseif snak.snaktype == 'novalue' then
if raw then
return "" -- empty value represents 'novalue'
else
return "none"
end
else
return nil
end
end
Line 563 ⟶ 574:
if qualifiers and qualifiers[1] then
return self:
else
return nil
Line 570 ⟶ 581:
function State:snakEqualsValue(snak, value)
local snakValue = self:
if snakValue and snak.snaktype == 'value' and snak.datavalue.type == 'wikibase-entityid' then value = value:upper() end
Line 805 ⟶ 816:
self.linked = true
return true
elseif flag == "
self.
return true
elseif flag == "short" then
Line 813 ⟶ 824:
elseif flag == "single" then
self.singleValue = true
return true
elseif flag == "mdy" then
self.mdyDate = true
return true
elseif flag == "best" or flag:match('^preferred[+-]?$') or flag:match('^normal[+-]?$') or flag:match('^deprecated[+-]?$') then
Line 866 ⟶ 880:
rankPos = _:convertRank(v.rank)
if _:rankMatches(rankPos) and _:timeMatches(v) then
value = _:getValue(v.mainsnak, _.
if value then
done = _:appendOutput(value, rankPos)
Line 955 ⟶ 969:
if _.propertyWithQualifier then
-- get the property value first
outValue = _:getValue(v.mainsnak, _.
end
Line 962 ⟶ 976:
-- get a bare qualifier, or the qualifiers connected to the property if it had a value
for i2, v2 in ipairs(qualifiers) do
outInter = _:getValue(v2, _.
if outInter then
if not _.propertyWithQualifier then
Line 1,006 ⟶ 1,020:
local _ = State.new()
_.propertyWithQualifier = true
return p._qualifier(args, _)
end
Line 1,017 ⟶ 1,030:
local _ = State.new()
local
local
local target = nil
local nextArg = mw.text.trim(args[1] or "")
local nextIndex = 2
Line 1,027 ⟶ 1,042:
end
if ID ~= "" then if
ID = aliasesP[ID]
end
ID = ID:upper()
-- check if this is a valid ID, and if the number is not larger than max int (to prevent error)
if not string.match(ID, '^[QP]%d+$') or tonumber(string.match(ID, '%d+')) > 2147483647 then
return ""
end
if _.rawValue then
if mw.wikibase.getEntity(ID) or mw.wikibase.resolvePropertyId(ID) then
if _.linked then
if ID:sub(1,1) == "P" then
value = "[[d:Property:" .. ID .. "|" .. ID .. "]]"
else
value = "[[d:" .. ID .. "|" .. ID .. "]]"
end
else
value = ID
end
end
else
if ID:sub(1,1) == "P" then
value = mw.wikibase.label(ID) or ""
if _.linked and value ~= "" then
value = "[[d:Property:" .. ID .. "|" .. value .. "]]"
end
else
if _.shortName then
value = _:getShortName(ID)
end
-- at this point, 'value' will be a string and not nil
if value == "" then
value = mw.wikibase.label(ID)
end
-- at this point, 'value' will be nil or a non-empty string
if _.linked or value == nil then
target = mw.wikibase.sitelink(ID)
end
if _.linked and target then
value = "[[" .. target .. "|" .. (value or target) .. "]]"
else
value = value or target or ""
end
end
end
else
if _.rawValue then
value = mw.wikibase.getEntityIdForCurrentPage() or ""
if
value = "[[d:" .. value .. "|" .. value .. "]]"
end
else
value = mw.wikibase.label()
if _.linked or
target = mw.
end
if _.linked
else
value = value or target
end
end
end
return value
end
|