Modulu:Wikidata: berrikuspenen arteko aldeak
Ezabatutako edukia Gehitutako edukia
update from ca.wiki |
No edit summary Etiketa: Manual revert |
||
1. lerroa:
-- version
local p = {}
31. lerroa:
[10] = "F Y", -- precision: month
[11] = "F j, Y", -- precision: day
},
41 ⟶ 39 lerroa:
},
["cite"] = { --
["
["
["
["
["
["archive-date"]= "archive-date",
["
["
["
["
["
["
},
78 ⟶ 70 lerroa:
local untranslated -- used in infobox modules: nil or true
-- Module local functions --------------------------------------------
84 ⟶ 75 lerroa:
-- Credit to http://stackoverflow.com/a/1283608/2644759, cc-by-sa 3.0
local function tableMerge(t1, t2)
for k,
if type(v) == "table" then
if type(t1[k] or false) == "table" then
99 ⟶ 90 lerroa:
local function loadI18n(lang)
local
if lang ~= wiki.langcode then i18n_title = "/i18n/" .. lang end
local exist, res = pcall(require, wiki.module_title .. i18n_title)
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
cases = res.cases
end
if lang ~= wiki.langcode and cases.location == nil then
cases.locationcontext = require(wiki.module_title .. '/i18n').cases.locationcontext
end
end
158 ⟶ 148 lerroa:
return label
end
176 ⟶ 156 lerroa:
for _, l in ipairs(languages) do
if l == wiki.langcode then
-- using getLabelWithLang when possible instead of getLabelByLang
label, l = mw.wikibase.getLabelWithLang(id)
else
187 ⟶ 167 lerroa:
end
return label, lang
end
209 ⟶ 172 lerroa:
local function feminineGender(id)
local claims = mw.wikibase.getBestStatements(id or mw.wikibase.getEntityIdForCurrentPage(),'P21')
if #claims == 0 then
return false
elseif claims[1].mainsnak.datavalue == nil then -- novalue or somevalue
return false
else
222 ⟶ 187 lerroa:
-- Fetch female form of label
local function feminineForm(id, lang)
local feminine_claims =
for _, feminine_claim in ipairs(feminine_claims) do
if
return feminine_claim.mainsnak.datavalue.value.text
end
end
end
-- get safely a serialized snak
local function getSnak(statement, snaks)
local ret = statement
for i, v in ipairs(snaks) do
if ret == nil then return end
ret = ret[v]
end
return ret
end
254 ⟶ 229 lerroa:
local ret = ''
if i18n.addpencil and parameters.editicon and parameters.id and parameters.property then
ret = ' <span data-bridge-edit-flow="
.. "[[File:Arbcom ru editing.svg|10px|baseline|"
.. mw.message.new('Editlink'):inLanguage(parameters.lang[1]):plain()
335 ⟶ 310 lerroa:
local function resolveEntityId(id)
if not id or not mw.wikibase.isValidEntityId(id) then return id end
-- if no label in
-- not using mw.title.new(id).isRedirect as it is expensive
if mw.wikibase.getLabel(id) == nil then
local entity = mw.wikibase.getEntity(id) -- expensive function
if not entity then return nil end
347 ⟶ 321 lerroa:
require(wiki.module_title .. '/debug').track('redirect/' .. id)
else
-- no redirect and no
require(wiki.module_title .. '/debug').track('label')
require(wiki.module_title .. '/debug').track('label/' .. id)
370 ⟶ 344 lerroa:
end
-- format data
local function
if mw.ustring.find((parameters.formatting or ''), '$1', 1, true) then -- formatting = a pattern
return expandBraces(mw.ustring.gsub(parameters.formatting, '$1', {['$1'] = data}), parameters.formatting)
elseif parameters.case then
return case(parameters.case, data, parameters.lang[1])
end
return data
395 ⟶ 364 lerroa:
return '[' .. data .. ' ' .. label .. ']'
end
return
end
417 ⟶ 373 lerroa:
icon = "no-icon"
end
return
end
-- format data
local function
local function globes(globe_id)
local globes = {['Q3134']='callisto',['Q596']='ceres',['Q15040']='dione',['Q2']='earth',['Q3303']='enceladus',
474 ⟶ 430 lerroa:
if unit_symbol == '' then
-- fetch it
local claims =
if
local langclaims = {}
table.insert(lang, 'mul') -- multilingual as last try
518 ⟶ 474 lerroa:
end
local function
-- rounds out_num with significant figures of in_num (default precision)
-- first, count digits after decimal mark, handling cases like '12.345e6'
local exponent, prec
548 ⟶ 500 lerroa:
end
-- format data
local function
local amount = data.amount
amount = mw.ustring.gsub(amount, "%+", "")
local suffix = ""
local conv_amount, conv_suffix
if string.sub(parameters.formatting or '', 1, 4) == "unit
-- example "unit": "http://www.wikidata.org/entity/Q174728"
local unit_id = data.unit
unit_id = mw.ustring.sub(unit_id, mw.ustring.find(unit_id, "Q"), -1)
566 ⟶ 519 lerroa:
end
elseif string.sub(parameters.convert or '', 1, 1) == "Q" then
convert_to =
end
if convert_to and convert_to ~= unit_id then
581 ⟶ 532 lerroa:
conv_amount = math.floor(tonumber(amount_f) + 0.5)
else
local conversions =
table.insert(conversions, mw.wikibase.getBestStatements(unit_id, 'P2370')[1]) -- conversion to SI unit
for _, conv in ipairs(conversions) do
if conv.mainsnak.snaktype == 'value' then -- no somevalue nor novalue
if conv.mainsnak.datavalue.value.unit == "http://www.wikidata.org/entity/" .. convert_to then
conv_amount =
break
end
603 ⟶ 554 lerroa:
local lang_obj = mw.language.new(parameters.lang[1])
local sortkey = string.format("%019d", tonumber(amount) * 1000)
if parameters.case then
amount = case(parameters.case, amount, parameters.lang[1])
646 ⟶ 571 lerroa:
end
-- format data
local function
-- Dates and times are stored in ISO 8601 format
local timestamp = data.time
725 ⟶ 650 lerroa:
elseif precision == 9 or parameters.formatting == 'Y' then -- precision is year
ret = formatTime(i18n.datetime[9], intyear)
ret = postFormat(ret) .. calendar_add
elseif precision == 10 then -- month
739 ⟶ 661 lerroa:
end
-- format data value
local function
local entity_id = data['id']
if parameters.formatting == 'raw' then
if data['entity-type'] == 'item' then
entity_id = resolveEntityId(entity_id)
end
return entity_id, entity_id
end
795 ⟶ 720 lerroa:
end
-- format data
local function
-- data fields: language [string], text [string]
814 ⟶ 739 lerroa:
end
return result
end
local function printError(key)
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
-- the "qualifiers" and "snaks" field have a respective "qualifiers-order" and "snaks-order" field
-- use these as the second parameter and this function instead of the built-in "pairs" function
-- to iterate over all qualifiers and snaks in the intended order.
local function orderedpairs(array, order)
if not order then return pairs(array) end
-- return iterator function
local i = 0
return function()
i = i + 1
if order[i] then
return order[i], array[order[i]]
end
end
end
function findClaims(entityId, property)
if not property or not entityId then return end
if not mw.ustring.match(property, "^P%d+$") then
-- get property id for the given label
property = mw.wikibase.resolvePropertyId(property)
if not property then return end
end
local claims = mw.wikibase.getAllStatements(entityId, property)
if #claims == 0 then
claims = nil
end
return claims
end
local function getSnakValue(snak, parameters)
if snak.snaktype == 'value' then
-- call the respective snak parser
if snak.datatype ==
return printDatatypeMath(snak.datavalue.value)
elseif snak.datatype == 'musical-notation' then
return printDatatypeMusical(snak.datavalue.value, parameters.formatting)
elseif snak.datatype == "url" then
return printDatatypeUrl(snak.datavalue.value, parameters)
elseif snak.datatype == "commonsMedia" then
return printDatatypeMedia(snak.datavalue.value, parameters)
return printDatavalueString(snak.datavalue.value, parameters)
return printDatavalueCoordinate(snak.datavalue.value, parameters.formatting)
return printDatavalueQuantity(snak.datavalue.value, parameters)
return printDatavalueTime(snak.datavalue.value, parameters)
elseif snak.datavalue.type == 'wikibase-entityid' then
return printDatavalueEntity(snak.datavalue.value, parameters)
elseif snak.datavalue.type == 'monolingualtext' then
return printDatavalueMonolingualText(snak.datavalue.value, parameters)
end
elseif snak.snaktype == 'novalue' then
852 ⟶ 808 lerroa:
end
return mw.wikibase.renderSnak(snak)
end
888 ⟶ 840 lerroa:
end
local snak, error = getQualifierSnak(claim, qualifierId, parameters)
if not snak then
return nil, nil, error
elseif snak[1] then -- a multi qualifier
local result
local
for idx in pairs(snak) do
result[#result + 1], sortkey[#sortkey + 1] = getSnakValue(snak[idx], parameters)
end
return mw.text.listToText(result, parameters.qseparator, parameters.qconjunction), sortkey[1]
924 ⟶ 875 lerroa:
end
local function getReferences(claim)
local notproperref = {
["P143"] = true, -- imported from
938 ⟶ 888 lerroa:
local refs = {}
local validref = true
-- traverse through all parts of the current reference
for snakkey, snakval in pairs(claim.references[ref].snaks or {}) do
950 ⟶ 899 lerroa:
for snakidx = 1, #snakval do
if snakidx > 1 then refparts = refparts .. ", " end
refparts = refparts or '' .. getSnakValue(snakval[snakidx], {lang=
end
refs[snakkey] = refparts
refparts = nil
end
end
-- get title of general template for citing web references
local template = mw.wikibase.getSitelink('Q5637226') or ""
template = mw.text.split(template, ":")[2] -- split off namespace from front
-- if both "reference URL" and "title" (or "stated in") are present, then use local cite web template
if refs['P854'] and (refs['P1476'] or refs['P248']) and
local citeParams = {}
citeParams[i18n['cite']['url']] = refs['P854']
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['
citeParams[i18n['cite']['language']] = refs['P2439']
citeParams[i18n['cite']['publisher']] = refs['P123']
citeParams[i18n['cite']['date']] = refs['P577']
1.003 ⟶ 925 lerroa:
citeParams[i18n['cite']['archive-date']] = refs['P2960']
citeParams[i18n['cite']['quote']] = refs['P1683']
refparts = mw.getCurrentFrame():expandTemplate{title=
else
-- raw ouput
local italics = "''"
for
if
refparts = refparts and refparts .. " " or ""
refparts = refparts .. mw.ustring.gsub(
refparts = refparts .. italics ..
italics = ""
end
end
end
if refparts then result = result .. mw.getCurrentFrame():extensionTag("ref", refparts
end
return result
1.053 ⟶ 951 lerroa:
listed = true
list[tostring(i)] = {}
for _, v in ipairs(values) do
list[tostring(i)][v] = true
list[tostring(i)][resolveEntityId(v)] = true
end
1.091 ⟶ 991 lerroa:
-- on debug console use: =p.claim{item="Q...", property="P...", ...}
function p.claim(frame)
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).claim(frame)
end
1.116 ⟶ 1.015 lerroa:
i = i + 1
end
local formatting =
local convert =
local case = args.case
local list = args.list or true; if (list == "false" or list == "no") then list = false end
local sorting_col = args.tablesort
local sorting_up = (args.sorting or "") ~= "-1"
1.136 ⟶ 1.034 lerroa:
["separator"] = separator, ["conjunction"] = conjunction, ["qseparator"] = separator, ["qconjunction"] = conjunction}
parameters.lang = findLang(args.lang)
-- defaults for table
1.184 ⟶ 1.068 lerroa:
whitelist, whitelisted = setWhiteOrBlackList("whitelist", #qualifierId, args)
blacklist, blacklisted = setWhiteOrBlackList("blacklist", #qualifierId, args)
end
-- fetch property
local claims
for p in string.gmatch(property, 'P%d+') do
claims = findClaims(id, p)
if claims and claims[1] then
parameters.property = p
break
end
end
if not claims or not claims[1] then
if showerrors then return printError("property-not-found") else return default end
end
-- set feminine case if gender is requested
local itemgender = args
local idgender
if itemgender then
1.245 ⟶ 1.142 lerroa:
local sortkeys = {}
local refs = {}
local firstrank = parameters.list == "firstrank" and claims[sortindices[1]].rank or ''
local rowlist = {} -- rows to list with whitelist or blacklist
for idx in pairs(claims) do
1.250 ⟶ 1.148 lerroa:
local reference = {}
if not whitelisted then rowlist[idx] = true end
if firstrank ~= '' and firstrank ~= claim.rank then
break
end
if parameters.formatting == "table" then
local params = tableParameters(args, parameters, "0")
1.276 ⟶ 1.177 lerroa:
valueq, sortkeyq, valueraw = getValueOfParentClaim(claim, q, params)
elseif string.find(q, "^/.+") then
local claim2 =
if
valueq, sortkeyq, _ = getValueOfClaim(claim2[1], nil, params)
end
1.318 ⟶ 1.219 lerroa:
end
if sorting_col then
local sorting_table = mw.text.split(sorting_col, '
local comparator = function(a, b)
local valuea, valueb
1.335 ⟶ 1.236 lerroa:
table.sort(sortindices, comparator)
end
result = {}
for idx in pairs(values) do
local valuerow = values[sortindices[idx]]
local reference = getReferences({["references"] = refs[sortindices[idx]]["col0"]}
value = valuerow["col0"]
1.372 ⟶ 1.272 lerroa:
if isSet(value) then
result[#result + 1] = value
if not parameters.list
break
end
1.386 ⟶ 1.286 lerroa:
local claim = claims[sortindices[1]]
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result and references then result = result .. getReferences(claim
end
if isSet(result) then
if i18n.addpencil and not (parameters.formatting == 'table' or (result2 and result2 == 'no-icon')) then
-- add edit icon, except table added previously and except explicit no-icon
result = result .. addEditIcon(parameters)
end
1.397 ⟶ 1.297 lerroa:
if showerrors then result = error else result = default end
end
return result,
end
1.432 ⟶ 1.332 lerroa:
local function getPropertyValue(id, property, parameter, langs, editicon, case)
local snaks = mw.wikibase.getBestStatements(id, property)
local mysnak
if
mysnak = snaks[1].mainsnak
else
return
end
1.445 ⟶ 1.347 lerroa:
return entity_id, result
end
local function contains(tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
1.462 ⟶ 1.374 lerroa:
include_self)
if (upto_linkId == nil) then upto_linkId = "" end
local upto_link_ids =
local lastlabel = uc_first(upto or '')
local maxloop = tonumber(upto) or
local labelFilter = {}
if labelShow then
for
labelFilter[uc_first(v)] = true
end
1.483 ⟶ 1.392 lerroa:
local result = {}
local label, link, linktext
for iter = 1, maxloop do
local
for _, propertySup in pairs(propertySups) do
_id, _link = getPropertyValue(id, propertySup, prop_format, languages, editicon, grammatical_case)
if _id and _link then id = _id
end
1.500 ⟶ 1.411 lerroa:
end
_, label = getPropertyValue(id, propertyLabel, label_format, languages,
if labelShow == nil or labelFilter[label] then
1.510 ⟶ 1.421 lerroa:
end
if not tonumber(upto) and label == lastlabel
break
end
if contains(upto_link_ids, id) then
break
end
1.572 ⟶ 1.487 lerroa:
if isSet(args.uptolabelid) then
upto
end
if isSet(args.showlabelid) then
local showLabelList = {}
for substring in mw.text.gsplit(args.showlabelid, '[
table.insert(showLabelList,
end
if #showLabelList > 0 then
1.595 ⟶ 1.510 lerroa:
editicon,
upto,
last_only,
case,
1.616 ⟶ 1.531 lerroa:
-- Link with a parent label --------------------
function p.linkWithParentLabel(frame)
if not required and frame.args and
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).linkWithParentLabel(frame)
end
1.633 ⟶ 1.548 lerroa:
-- get id value of property/qualifier
local largs = mw.clone(args)
largs.list =
largs.formatting = "raw"
largs.separator = "/·/"
largs.editicon = "false"
local items_list
if not isSet(items_list) then return end
local items_table = mw.text.split(items_list, "/·/", true)
1.643 ⟶ 1.558 lerroa:
-- get internal link of property/qualifier
largs.formatting = "internallink"
local link_list
local link_table = mw.text.split(link_list, "/·/", true)
-- get label of parent property
local parent_claim = getSnak(
if parent_claim == 'monolingualtext' then
largs.formatting = nil
1.659 ⟶ 1.574 lerroa:
for i, v in ipairs(items_table) do
largs.item = v
local link_label
if isSet(link_label) then
link_table[i] = mw.ustring.gsub(link_table[i] or '', "%[%[(.*)%|.+%]%]", "[[%1|" .. link_label .. "]]")
1.756 ⟶ 1.671 lerroa:
end
if not isSet(yo_pl) then
yo_pl
yo_sg = yo_pl
end
1.800 ⟶ 1.715 lerroa:
if label == nil then
if
label, lang = getLabelByLangs(new_id, languages)
if args.itemgender and feminineGender(args.itemgender) then
label = feminineForm(new_id, lang) or label
end
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
end
label_icon = addLabelIcon(new_id or id, lang, languages[1], editicon)
end
end
end
1.813 ⟶ 1.731 lerroa:
local linked = args.linked
if isSet(linked) and linked ~= "no" then
local article = mw.wikibase.getSitelink(id) or ("d:
return "[[" .. article .. "|" .. (label or id) .. "]]" .. label_icon, not required and '' or untranslated
else
1.841 ⟶ 1.759 lerroa:
function p.numStatements(frame)
local id = getEntityId(frame)
if id == nil then
return 0 end
local args = frame.args
local prop = mw.text.trim(args[1])
local num = mw.wikibase.getBestStatements(id, prop)
return #num
end
1.861 ⟶ 1.773 lerroa:
local item = getEntityId(frame)
if item == nil then return end
local
if #properties == 0 then return end
return properties[1].mainsnak.datavalue and true or nil
end
|