Mòdul:Wikidata: diferència entre les revisions

Contingut suprimit Contingut afegit
protecció a getSiteLink
actualització, corr. títol i tractament dates
Línia 1:
-- version 2019110620191111 from master @cawiki
 
local p = {}
Línia 27:
[10] = "F Y", -- precision: month
[11] = "F j, Y", -- precision: day
[12] = "F j, Y ga", -- precision: hour
[13] = "F j, Y g:ia", -- precision: minute
[14] = "F j, Y g:i:sa", -- precision: second
["beforenow"] = "$1 BCE", -- how to format negative numbers for precisions 0 to 5
["afternow"] = "$1 CE", -- how to format positive numbers for precisions 0 to 5
["bc"] = '$1 "BCE"', -- how print negative years
["ad"] = "$1", -- how print positive1st yearscentury AD dates
["bc-addon"] = " BC", -- suffix for negative dates
["ad-addon"] = "" -- suffix for 1st century AD dates
},
["monolingualtext"] = '<span lang="%language">%text</span>',
Linha 64 ⟶ 59:
{
langcode = mw.language.getContentLanguage().code,
module_title = mw.wikibase.getSitelink('Q12069631Module:Wikidata'), -- title of this module for access to its /subpages, change if necessary
}
 
Linha 410 ⟶ 405:
-- Dates and times are stored in ISO 8601 format
local timestamp = data.time
local sortkey = timestamppost_format
local addon = ""
local calendar_add = ""
-- check for negative date, ex. "-0027-01-16T00:00:00Z"
if string.sub(timestamp, 1, 1) == '-' then
addonpost_format = i18n.datetime["bc-addon"]
timestamp = '+' .. string.sub(timestamp, 2)
addon = i18n.datetime["bc-addon"]
elseif string.sub(timestamp, 2, 3) == '00' then
addonpost_format = i18n.datetime["ad-addon"]
else
-- calendar model
Linha 430 ⟶ 422:
end
end
local function d(f, t)
local ts = t or timestamp
local form = type(f) == "function" and f(ts) or f -- function in i18n.datetime[precision]
if string.sub(ts, 1, 1) == '-' then ts = '+' .. string.sub(ts, 2) end -- formatDate() only supports years from 0
return mw.language.new(parameters.lang[1]):formatDate(form, ts) .. addon .. calendar_add
end
local function postFormat(t)
if post_format and mw.ustring.find(post_format, "$1") then
return mw.ustring.gsub(post_format, "$1", t)
end
return t
end
local precision = data.precision or 11
local intyear = tonumber(mw.ustringstring.match(timestamp, "^\[+?-](%d+)"))
local ret = ""
Linha 443 ⟶ 445:
local y2 = math.ceil(math.abs(intyear) / factor)
local relative = mw.ustring.gsub(i18n.datetime[precision], "$1", tostring(y2))
if addonpost_format == i18n.datetime["bc-addon"] then
-- negative date
ret = mw.ustring.gsub(i18n.datetime.beforenow, "$1", relative)
else
Linha 456 ⟶ 457:
local card = math.floor((intyear - 1) / 1000) + 1
if mw.ustring.find(i18n.datetime[6], "$1") then
ret = mw.ustring.gsub(i18n.datetime[6], "$1", tostring(card)) .. addon .. calendar_add
else
ret = d(i18n.datetime[6], string.format("%04d", tostring(card)))
end
ret = postFormat(ret)
elseif precision == 7 then -- centuries
local card = math.floor((math.abs(intyear) - 1) / 100) + 1
if mw.ustring.find(i18n.datetime[7], "$1") then
ret = mw.ustring.gsub(i18n.datetime[7], "$1", tostring(card)) .. addon .. calendar_add
else
ret = d(i18n.datetime[7], string.format("%04d", tostring(card)))
end
ret = postFormat(ret) .. calendar_add
elseif precision == 8 then -- decades
local card = math.floor(math.abs(intyear) / 10) * 10
ret = postFormat(mw.ustring.gsub(i18n.datetime[8], "$1", tostring(card)) .. addon) .. calendar_add
elseif parameters.formattingprecision == 'Y'9 or precisionparameters.formatting == 9'Y' then -- precision is year
ret = postFormat(tostring(intyear) .. addon) .. calendar_add
elseif precision == 10 then -- month
timestamp = timestamp .. " + 1 day" -- formatDate yyyy-mm-00 returns the previous month
ret, _ = string.gsub(d(i18n.datetime[10]), " 0+", " ") -- supress leading zeros in year
ret = postFormat(ret) .. calendar_add
elseif parameters.formatting then
ret, _ = string.gsub(d(parameters.formatting)ret, "([ %[])0+", "%1") -- supress leading zeros in year, optionally linked
else -- precision 11, day
else
ret, _ = string.gsub(d(parameters.formatting or i18n.datetime[11]), " 0+", " ")
ret = postFormat(ret) .. calendar_add
ret, _ = string.gsub(ret, "([ %[])0+", "%1")
end
return ret, sortkeytimestamp
end
 
Linha 847 ⟶ 852:
local showerrors = args["showerrors"]
local default = args["default"]
if default then showerrors = nil end
local editicon = not (args.editicon == "false" or args.editicon == "no")
Linha 887 ⟶ 893:
blacklist, blacklisted = setWhiteOrBlackList("blacklist", #qualifierId, args)
end
if default then showerrors = nil end
-- fetch property