Modul:Wikidata: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
k uji coba
Nyilvoskt (bicara | kontrib)
Membalikkan revisi 26004704 oleh Nyilvoskt (bicara)
Tag: Pembatalan Suntingan perangkat seluler Suntingan peramban seluler Suntingan seluler lanjutan
 
(18 revisi perantara oleh 4 pengguna tidak ditampilkan)
Baris 1:
-- version 2020070120231204 from master @cawiki
-- changes from previous version: whitelist, blacklist, ignorevalue and selectvalue work with multivalue qualifiers
 
local p = {}
 
Baris 35:
},
["years-old"] = {"", ""}, -- year(s) old, as in {{PLURAL:$1|singular|plural}}
-- two values for most languages, up to six values for some languages
["singular"] = "", -- year old, as in {{PLURAL:$1|singular|plural}}
-- see documentation of PLURAL magic word in your language, examples:
["plural"] = "", -- years old
-- ["years-old"] = {"singular", "paucal", "plural"} in Russian and other Slavic languages
["paucal"] = "", -- for languages with 3 plural forms as in {{PLURAL:$1|singular|paucal|plural}}
-- ["years-old"] = {"zero", "one", "two", "few 3-10", "many 11-99", "other 100-102"} in Arabic
},
["cite"] = { -- cite parameters
Baris 62:
},
-- default local wiki settings
["addpencil"] = false, -- adds a pencil icon linked to Wikidata statement, planned to overwrite by Wikidata Bridge
["categorylabels"] = "", -- Category:Pages with Wikidata labels not translated (void for no local category)
["categoryprop"] = "", -- Category:Pages using Wikidata property $1 (void for no local category)
["addfallback"] = {} -- additional fallback language codes
["categoryref"] = "", -- Category:Pages with references from Wikidata (void for no local category)
["addfallback"] = {}, -- additional fallback language codes
["suppressids"] = {}, -- list of Qid values to suppress
["qidlabels"] = true -- show labels as Qid if no fallback translation is available
}
 
Baris 110 ⟶ 114:
tableMerge(cases, res.cases)
end
end
i18n.suppress = {}
for _, id in ipairs(i18n.suppressids) do
i18n.suppress[id] = true
end
end
Baris 121 ⟶ 129:
if mw.language.isKnownLanguageTag(langcode or '') == false then
if not mw.title.getCurrentTitle().isContentPage then
langcode = cframe:preprocesscallParserFunction('{{int:', {'lang}}'})
end
if mw.language.isKnownLanguageTag(langcode or '') == false then
Baris 144 ⟶ 152:
-- Argument is 'set' when it exists (not nil) or when it is not an empty string.
local function isSet(var)
return not (not var == nil or (type(var) == 'string' and mw.text.trim(var) == ''))
end
 
Baris 151 ⟶ 159:
if not isSet(label) then return label end
if type(localcase) == "smallcapsfunction" then
return localcase(label)
elseif localcase == "smallcaps" then
return '<span style="font-variant: small-caps;">' .. label .. '</span>'
elseif cases[localcase] then
Baris 176 ⟶ 186:
for _, l in ipairs(languages) do
if l == wiki.langcode then
-- using getLabelWithLang when possible instead of getLabelByLang, do not solve redirects pending phab:T157868
label, l = mw.wikibase.getLabelWithLang(id)
else
Baris 209 ⟶ 219:
local function feminineGender(id)
local claims = mw.wikibase.getBestStatements(id or mw.wikibase.getEntityIdForCurrentPage(),'P21')
iflocal gender_id = getSnak(claims, {1, "mainsnak", "datavalue"}), == nil then -- no claim"value", novalue or somevalue"id"})
if gender_id == "Q6581072" or gender_id == "Q1052281" or gender_id == "Q43445" then -- female, transgender female, female organism
return false
return true
else
local genderId = claims[1].mainsnak.datavalue.value.id
if genderId == "Q6581072" or genderId == "Q1052281" or genderId == "Q43445" then -- female, transgender female, female organism
return true
end
end
return false
Baris 238 ⟶ 244:
end
if label_id and (lang == nil or lang ~= uselang) then
local namespace = ''
if string.sub(label_id, 1, 1) == 'P' then
namespace = 'Property:'
end
ret_icon = " [[File:OOjs_UI_icon_tag-rtl-progressive.svg|10px|baseline|"
.. mw.message.new('Translate-taction-translate'):inLanguage(uselang):plain()
.. "|link=https://www.wikidata.org/wiki/Special:EntityPage/" .. namespace .. label_id .. "?uselang=" .. uselang .. "]]"
untranslated = true
end
Baris 251 ⟶ 261:
 
-- editicon values: true/false (no=false), right, void defaults to i18n.addpencil
-- labelicon only by parameter
local function setEditIcon(param)
local function setIcons(arg, parg)
if not isSet(param) then return i18n.addpencil end
iflocal paramval == "false" or paramarg == "no"nil thenand returnparg falseor endarg
local edit_icon, label_icon
return param
if not isSet(val) then
edit_icon, label_icon = i18n.addpencil, true
elseif val == false or val == "false" or val == "no" then
edit_icon, label_icon = false, false
else
edit_icon, label_icon = val, true
end
return edit_icon, label_icon
end
 
-- Add an icon for editing a statement with requirements for future Wikidata Bridge
local function addEditIcon(parameters)
local ret = ''
if parameters.editicon and parameters.id and parameters.property then
local bridge_flow = parameters.editbridge and ' data-bridge-edit-flow="single-best-value"' or ''
local icon_style = parameters.editicon == "right" and ' style="float: right;"' or ''
ret = ' <span class="penicon" data-bridge-edit-flow="single-best-value"' .. bridge_flow .. icon_style .. '>'
.. "[[File:OOjs UI icon edit-ltr-progressive.svg|10px|baseline|"
.. string.gsub(mw.message.new('Wikibase-client-data-bridge-bailout-suggestion-go-to-repo-button'):inLanguage(parameters.lang[1]):plain(), '{{WBREPONAME}}', 'Wikidata')
.. "|link=https://www.wikidata.org/wiki/" .. parameters.id .. "?uselang=" .. parameters.lang[1] .. "#" .. parameters.property .. "]]"
.. "</span>"
if isSet(i18n.categoryprop) then
ret = ret .. "[[" .. string.gsub(i18n.categoryprop, '$1', parameters.property) .. "]]"
end
end
return ret
Baris 318 ⟶ 340:
local subparts = mw.ustring.find(parts[i], "=")
if subparts then
parameters[local param_name = mw.ustring.sub(parts[i], 1, subparts - 1)]
local param_value = mw.ustring.sub(parts[i], subparts + 1, -1)
-- reconstruct broken links by parts
else
if i < #parts and mw.ustring.find(param_value, "[[", 1, true) and not mw.ustring.find(param_value, "]]", 1, true) then
parameters[param_name] = param_value
local part_next = i + 1
while parts[part_next] and mw.ustring.find(parts[part_next], "]]", 1, true) do
parameters[param_name] = parameters[param_name] .. "|" .. parts[part_next]
part_next = part_next + 1
end
else
parameters[param_name] = param_value
end
elseif not mw.ustring.find(parts[i], "]]", 1, true) then
table.insert(parameters, parts[i])
end
Baris 338 ⟶ 372:
return text
end
 
-- Resolve Wikidata redirects, pending phab:T157868
local function resolveEntityId(id)
if not id or not mw.wikibase.isValidEntityId(id) then return id end
-- if no label in English, maybe it is a redirect
-- not using mw.title.new(id).isRedirect as it is expensive
-- currently getLabelByLang does not follows redirects
if mw.wikibase.getLabelByLang(id, 'en') == nil then
local entity = mw.wikibase.getEntity(id) -- expensive function
if not entity then return nil end
if id ~= entity.id then
-- Qid redirected to be fixed
-- see [[Special:WhatLinksHere/Template:Track/wikidata/redirect]]
require(wiki.module_title .. '/debug').track('redirect')
require(wiki.module_title .. '/debug').track('redirect/' .. id)
else
-- no redirect and no English label, fix it to avoid expensive functions
require(wiki.module_title .. '/debug').track('label')
require(wiki.module_title .. '/debug').track('label/' .. id)
end
return entity.id
end
return id
end
 
Baris 383 ⟶ 393:
return expandBraces(mw.ustring.gsub(parameters.formatting, '$1', {['$1'] = data}), parameters.formatting)
elseif parameters.case then
return case(parameters.case, data, parameters.lang[1], feminineGender(parameters.id))
end
local data_number = string.match(data, "^%d+")
Baris 391 ⟶ 401:
end
return data
end
 
-- format data type tabular-data
local function printDatatypeTabular(data, parameters)
local icon
if parameters.formatting == 'raw' then
icon = "no-icon"
data = string.gsub(data, '^Data:', '') -- remove prefix, i.e. see Module:Tabular data
end
return printDatatypeString(data, parameters), icon
end
 
Baris 419 ⟶ 439:
end
 
-- format data type commonsMedia and geo-shape
local function printDatatypeMedia(data, parameters)
local icon
if not string.find((parameters.formatting or ''), '$1', 1, true) then
icon = "no-icon"
if not string.find(data, '^Data:') then
data = mw.uri.encode(data, 'PATH') -- encode special characters in filename
end
end
return printDatatypeString(data, parameters), icon
Baris 504 ⟶ 527:
local function getUnit(amount, id, parameters) -- get unit symbol or name
local suffix = ''
if string.sub(parameters.formatting or '', 1, 8) == "unitcode" then
-- get unit symbol
local unit_symbol = unitSymbol(id, parameters.lang)
if isSet(unit_symbol) then
if string.sub(parameters.formatting or '', -6) == "linked" then
suffix = unit_symbol
suffix = "[[" .. (mw.wikibase.getSitelink(id) or "d:" .. id) .. "|" .. unit_symbol .. "]]"
else
suffix = unit_symbol
end
end
end
if suffix == '' then -- formatting=unit, or formatting=unitcode not found
-- get unit namelabel
local unit_label, lang = getLabelByLangs(id, parameters.lang)
if lang == wiki.langcode and pcall(require, wiki.module_title .. "/Units") then
suffix = require(wiki.module_title .. "/Units").getUnit(amount, unit_label, id, false)
if string.sub(parameters.formatting or '', -6) == "linked" then
suffix = "[[" .. (mw.wikibase.getSitelink(id) or "d:" .. id) .. "|" .. suffix .. "]]"
end
else
suffix = (unit_label or id) .. addLabelIcon(id, lang, parameters.lang[1], parameters.editiconlabelicon)
end
end
Baris 529 ⟶ 559:
-- rounds out_num with significant figures of in_num (default precision)
local out_num = in_num * factor
if factor/60 == math.floor(factor/60) or out_num == 0 then -- sexagesimal integer or avoiding NaN
return out_num
end
Baris 570 ⟶ 600:
if parameters.convert == "default" or parameters.convert == "default2" then
local exist, units = pcall(require, wiki.module_title .. "/Units")
if exist and units.convert_default and next(units.convert_default) ~= nil then
convert_to = units.convert_default[unit_id]
end
elseif string.sub(parameters.convert or '', 1, 1) == "Q" then
convert_to = resolveEntityId(parameters.convert)
elseif string.sub(parameters.formatting or '', 1, 8) == "duration" then
convert_to = 'Q11574' -- seconds
Baris 606 ⟶ 636:
conv_amount = math.floor(amount/10^6 + 0.5)
conv_suffix = ' M' .. string.sub(suffix, 2)
end
if conv_amount and parameters.formatting == 'raw' then
amount = conv_amount
suffix = ""
conv_amount = nil
end
end
Baris 613 ⟶ 648:
if string.sub(parameters.formatting or '', 1, 8) == "duration" then
local sec = tonumber(conv_amount or amount)
if parameters.formatting == 'durationhms' or parameters.formatting == 'durationh:m:sduration' then
return lang_obj:formatDuration(sec)
elseif parameters.formatting == 'durationm:s' then
local mm = math.floor(sec / 60)
local ss = sec - (mm * 60)
return string.format("%02d:%02d", mm, ss)
else -- durationhms or durationh:m:s
local intervals = {"hours", "minutes", "seconds"}
local sec2table = lang_obj:getDurationIntervals(sec, intervals)
Baris 633 ⟶ 674:
end
return duration
else
return lang_obj:formatDuration(sec)
end
end
if parameters.case then
amount = case(parameters.case, amount, parameters.lang[1], feminineGender(parameters.id))
elseif parameters.formatting ~= 'raw' then
else
if parameters.numformat then
amount = lang_obj:formatNum(tonumber(amount))
amount = lang_obj:formatNum(tonumber(string.format(parameters.numformat, amount)))
else
amount = lang_obj:formatNum(tonumber(amount))
end
end
if conv_amount then
local conv_sortkey = string.format("%019d", tonumber(conv_amount) * 1000)
conv_amount = lang_obj:formatNum(tonumber(conv_amount))
if parameters.convert == 'default2' then
return conv_amount .. conv_suffix .. ' (' .. amount .. suffix .. ')', conv_sortkey
Baris 650 ⟶ 693:
return conv_amount .. conv_suffix, conv_sortkey
end
elseif mw.ustring.find((parameters.formatting or ''), '$1', 1, true) then -- formatting with pattern
amount = mw.ustring.gsub(parameters.formatting, '$1', {['$1'] = amount})
end
return amount .. suffix, sortkey
Baris 693 ⟶ 738:
end
local ret = mw.language.new(parameters.lang[1]):formatDate(pattern, stamp)
ret = string.gsub(ret, "^(%[?%[?)0+", "%1") -- supresssuppress leading zeros
ret = string.gsub(ret, "( %[?%[?)0+", "%1")
return ret
Baris 744 ⟶ 789:
end
 
-- format data value wikibase-entityid: with data types wikibase-item, or wikibase-property
local function printDatatypeEntity(data, parameters)
local entity_id = data['id']
Baris 760 ⟶ 805:
if parameters.case ~= 'gender' then
labelcase = case(parameters.case, labelcase, lang, parameters.lang[1], entity_id, parameters.id)
end
if labelcase == nil and i18n.qidlabels == false then
return
end
local ret1, ret2
Baris 792 ⟶ 840:
ret2 = labelcase
else
ret1 = '[[d:' .. entity_page .. '|<span style="color:#5f9cbb;">' .. (labelcase or entity_id) .. '</span>]]'
ret2 = labelcase or entity_id
end
end
return ret1 .. addLabelIcon(entity_id, lang, parameters.lang[1], parameters.editiconlabelicon), ret2
end
 
-- format data type wikibase-lexeme
local function printDatatypeLexeme(data, parameters)
local entity_id = data['id']
if parameters.formatting == 'raw' then
return entity_id, entity_id
end
local lemmas = mw.wikibase.getEntity(entity_id):getLemmas()
if parameters.list == 'lang' and lemmas[1][2] ~= parameters.lang[1] then
return
end
local ret = '[[d:Special:EntityPage/' .. entity_id .. '|<span style="color:#5f9cbb;">' .. lemmas[1][1] .. '</span>]]'
if parameters.list ~= 'lang' or (parameters.list == 'lang' and lemmas[1][2] ~= wiki.langcode) then
ret = ret .. " <sup>(" .. lemmas[1][2] .. ")</sup>"
end
return ret, entity_id
end
 
Baris 805 ⟶ 870:
if parameters.list == "lang" and data["language"] ~= parameters.lang[1] then
return
elseif parameters.list == "notlang" and data["language"] == parameters.lang[1] then
return
elseif parameters.formatting == "language" or parameters.formatting == "text" then
Baris 822 ⟶ 889:
 
local function getSnakValue(snak, parameters)
parameters.editbridge = false
if snak.snaktype == 'value' then
if snak.snaktype == 'value' then -- see Special:ListDatatypes
-- data value string
if snak.datatype == "string" then
parameters.editbridge = true -- Wikidata Bridge currently only for string values
return printDatatypeString(snak.datavalue.value, parameters)
elseif snak.datatype == "commonsMedia" or snak.datatype == "geo-shape" then
-- other data value string, tabular-data not implemented
elseif snak.datatype == "commonsMedia" then
return printDatatypeMedia(snak.datavalue.value, parameters)
elseif snak.datatype == "tabular-data" then
return printDatatypeTabular(snak.datavalue.value, parameters)
elseif snak.datatype == "url" then
return printDatatypeUrl(snak.datavalue.value, parameters)
Baris 837 ⟶ 907:
elseif snak.datatype == 'musical-notation' then
return printDatatypeMusical(snak.datavalue.value, parameters.formatting)
-- other data types other than string value
elseif snak.datatype == 'wikibase-item' or snak.datatype == 'wikibase-property' then
if i18n.suppress[snak.datavalue.value.id] then
return
end
return printDatatypeEntity(snak.datavalue.value, parameters)
elseif snak.datatype == 'wikibase-lexeme' then
return printDatatypeLexeme(snak.datavalue.value, parameters)
elseif snak.datatype == 'monolingualtext' then
return printDatatypeMonolingual(snak.datavalue.value, parameters)
Baris 853 ⟶ 928:
return mw.message.new('Wikibase-snakview-snaktypeselector-novalue'):inLanguage(parameters.lang[1]):plain()
elseif snak.snaktype == 'somevalue' then
if parameters.formatting == 'raw' or parameters.showsomevalue == false then return end
return mw.message.new('Wikibase-snakview-snaktypeselector-somevalue'):inLanguage(parameters.lang[1]):plain()
end
Baris 890 ⟶ 965:
-- otherwise return the main snak
return claim.mainsnak
end
end
 
local function getValue(entity, claims, propertyID, delim, labelHook)
if labelHook == nil then
labelHook = function (qnumber)
return nil;
end
end
if isType(claims, "wikibase-entityid") then
local out = {}
for k, v in pairs(claims) do
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
local sitelink = mw.wikibase.getSitelink(qnumber)
local label = labelHook(qnumber) or mw.wikibase.getLabel(qnumber) or qnumber
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = "[[:d:" .. qnumber .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return table.concat(out, delim)
else
-- just return best values
return entity:formatPropertyValues(propertyID).value
end
end
Baris 924 ⟶ 974:
elseif snak[1] then -- a multi qualifier
local result, sortkey = {}, {}
local maxvals = tonumber(parameters.listlistmax)
for idx in pairs(snak) do
result[#result + 1], sortkey[#sortkey + 1] = getSnakValue(snak[idx], parameters)
Baris 962 ⟶ 1.012:
 
-- see d:Help:Sources
local function getReferences(claim, langparameters)
if not (parameters.references or parameters.onlysourced) then
return '', false
end
local lang = parameters.lang
local maxrefs = tonumber(parameters.references) or 1
local notproperref = {
["P143"] = true, -- imported from
Baris 969 ⟶ 1.024:
["P4656"] = true -- Wikimedia import URL
}
local result = ""{}
-- traverse through all references
for ref in pairs(claim.references or {}) do
Baris 975 ⟶ 1.030:
local refs = {}
local validref = true
local ref_nameref_id
-- traverse through all parts of the current reference
for snakkey, snakval in pairs(claim.references[ref].snaks or {}) do
Baris 987 ⟶ 1.042:
for snakidx = 1, #snakval do
if snakidx > 1 then refparts = refparts .. ", " end
refpartsif = refparts or '' .. getSnakValue(snakval[snakidx],.datatype {lang=lang})= 'external-id' then
refparts = refparts or '' .. (getSnakValue(snakval[snakidx], {formatting='externalid', property=snakval[snakidx].property, lang=lang}) or '')
else
refparts = refparts or '' .. (getSnakValue(snakval[snakidx], {lang=lang}) or '')
end
end
refs[snakkey] = refparts
refparts = nil
if snakkey == "P248" then -- stated in
ref_nameref_id = getSnak(snakval[, {1]., "datavalue.", "value.", "id"})
end
end
Baris 998 ⟶ 1.057:
-- fill missing values with parent item
if ref_nameref_id then
local function refParent(qid, pid, formatting)
local snak = getSnak(mw.wikibase.getBestStatements(qid, pid), {1, "mainsnak"})
Baris 1.004 ⟶ 1.063:
end
refs['P50'] = refs['P50'] or refParent(ref_nameref_id, 'P50', 'label') -- author
refs['P407'] = refs['P407'] or refParent(ref_nameref_id, 'P407', 'label') -- language of work
refs['P123'] = refs['P123'] or refParent(ref_nameref_id, 'P123', 'label') -- publisher
refs['P577'] = refs['P577'] or refParent(ref_nameref_id, 'P577') -- date
refs['P1433'] = refs['P1433'] or refParent(ref_nameref_id, 'P1433', 'label') -- published in
refs['P304'] = refs['P304'] or refParent(ref_nameref_id, 'P304') -- page(s)
refs['P433'] = refs['P433'] or refParent(ref_nameref_id, 'P433') -- issue
refs['P236'] = refs['P236'] or refParent(ref_nameref_id, 'P236') -- ISSN
refs['P356'] = refs['P356'] or refParent(ref_nameref_id, 'P356') -- DOI
end
Baris 1.077 ⟶ 1.136:
end
end
if refparts then result = mw.getCurrentFrame():extensionTag("ref", refparts, {name=ref_name}) end
if refparts then
local ref_name = claim.references[ref].hash
result[#result + 1] = mw.getCurrentFrame():extensionTag("ref", refparts, {name=ref_name})
if maxrefs and maxrefs == #result then break end
end
end
return result
if #result > 0 then
if parameters.references then
if isSet(i18n.categoryref) then
result[#result + 1] = "[[" ..i18n.categoryref .. "]]"
end
return table.concat(result), true
else
return '', true
end
end
return '', false
end
 
Baris 1.089 ⟶ 1.164:
if isSet(args[k .. i]) then
lists[k][tostring(i)] = {}
forlocal qpattern in string.gmatch(args[k .. i],= 'Q%d+') do
if string.sub(args[k .. i], 1, 1) ~= 'Q' then
lists[k][tostring(i)][resolveEntityId(q)] = true
pattern = '[^%p%s]+'
end
for q in string.gmatch(args[k .. i], pattern) do
lists[k][tostring(i)][q] = true
end
end
Baris 1.122 ⟶ 1.201:
end
return id
end
 
local function getArg(value, default, aliases)
if type(value) == 'boolean' then return value
elseif value == "false" or value == "no" then return false
elseif value == "true" or value == "yes" then return true
elseif value and aliases and aliases[value] then return aliases[value]
elseif isSet(value) then return value
elseif default then return default
else return nil
end
end
 
Baris 1.143 ⟶ 1.233:
-- arguments
local idparameters = getEntityId(args, pargs){}
parameters.id = getEntityId(args, pargs)
if id == nil then return end
if parameters.id == nil then return end
local property = string.upper(args.property or "")
parameters.property = string.upper(args.property or "")
local qualifierId = {}
qualifierId[1] = isSetgetArg(args.qualifier) and string.upper(args.qualifier) or nilargs.qualifier1 or ""))
local i = 2
while isSet(args["qualifier" .. i]) do
Baris 1.153 ⟶ 1.244:
i = i + 1
end
local parameters.formatting = isSetgetArg(args.formatting) and args.formatting or nil
local parameters.convert = isSetgetArg(args.convert) and args.convert or nil
parameters.numformat = getArg(args.numformat)
local case = args.case
parameters.case = args.case
local list = args.list or true; if (list == "false" or list == "no") then list = false end
if parameters.list == 'firstrank'getArg(args.list, then listtrue, {firstrank= 'bestrank' end -- alias})
parameters.listmax = args.listmax
local shownovalue = args.shownovalue or true; if (shownovalue == "false" or shownovalue == "no") then shownovalue = false end
parameters.listrank = getArg(args.listrank)
if type(parameters.list) == "number" then -- backwards compatibility
parameters.listmax = parameters.listmax or parameters.list
parameters.list = true
elseif parameters.list == "bestrank" then
parameters.listrank = parameters.listrank or "bestrank"
parameters.list = true
end
parameters.shownovalue = getArg(args.shownovalue, true)
parameters.showsomevalue = getArg(args.showsomevalue, true)
parameters.separator = getArg(args.separator)
parameters.conjunction = getArg(args.conjunction, parameters.separator)
parameters.qseparator = getArg(args.qseparator, parameters.separator)
parameters.qconjunction = getArg(args.qconjunction, parameters.conjunction)
local sorting_col = args.tablesort
local sorting_up = (args.sorting or "") ~= "-1"
local separator = isSet(args.separator) and args.separator
local conjunction = isSet(args.conjunction) and args.conjunction or separator
local rowformat = args.rowformat
local parameters.references = getArg(args.references, false)
parameters.onlysourced = getArg(args.onlysourced, false)
local showerrors = args.showerrors
local default = args.default
if default then showerrors = nil end
local parameters = {["id"] = id, ["property"] = property, ["formatting"] = formatting, ["convert"] = convert,
["list"] = list, ["case"] = case, ["shownovalue"] = shownovalue,
["separator"] = separator, ["conjunction"] = conjunction, ["qseparator"] = separator, ["qconjunction"] = conjunction}
parameters.lang = findLang(args.lang)
if parameters.editicon = formatting ~== "raw" and setEditIcon(args.editicon or pargs.editicon) or false -- needs loadI18n by findLandthen
parameters.editicon, parameters.labelicon = false, false
else
parameters.editicon, parameters.labelicon = setIcons(args.editicon, pargs.editicon) -- needs loadI18n by findLand
end
-- fetch property
local claims = {}
local bestrank = (parameters.list == false or parameters.listlistrank == 'bestrank') and parameters.list ~= 'lang'
for p in string.gmatch(parameters.property, 'P%d+') do
claims = getStatements(parameters.id, p, bestrank)
if #claims > 0 then
parameters.property = p
Baris 1.186 ⟶ 1.290:
end
if #claims == 0 then
iflocal ret = showerrors then returnand printError("property-not-found") else returnor default end
return ret, args.query == 'num' and 0 or ''
end
Baris 1.196 ⟶ 1.301:
parameters.separator = parameters.separator or "<br />"
parameters.conjunction = parameters.conjunction or "<br />"
parameters.qseparator = "getArg(args.qseparator, "mw.message.new('Comma-separator'):inLanguage(parameters.lang[1]):plain())
parameters.qconjunction = "getArg(args.qconjunction, "parameters.qseparator)
if not rowformat then
rowformat = "$0 ($1"
Baris 1.230 ⟶ 1.335:
if itemgender then
if string.match(itemgender, "^P%d+$") then
local snak_id = getSnak(mw.wikibase.getBestStatements(parameters.id, itemgender), {1, "mainsnak", "datavalue", "value", "id"})
if snak_id then
idgender = snak_id
Baris 1.250 ⟶ 1.355:
end
if gender_requested then
if feminineGender(idgender or parameters.id) then
parameters.gender = "feminineform"
end
Baris 1.269 ⟶ 1.374:
table.sort(sortindices, comparator)
local result, result2, result_query
local error
if parameters.list or parameters.formatting == "table" then
Baris 1.315 ⟶ 1.420:
valueq, sortkeyq, valueraw = getValueOfParentClaim(claim, q, params)
elseif string.find(q, "^/.+") then
local claim2 = getStatements(parameters.id, string.sub(q, 2), bestrank)
if #claim2 > 0 then
-- only first value of a property as alternative to a qualifier
-- multiple values may not be related to a given raw of the table
valueq, sortkeyq, _ = getValueOfClaim(claim2[1], nil, params)
end
Baris 1.322 ⟶ 1.429:
valueq, sortkeyq, _ = getValueOfClaim(claim, q, params)
end
if valueq then break end
qual = q
break
end
end
end
Baris 1.328 ⟶ 1.438:
sortkeys[#sortkeys]["col" .. j] = sortkeyq or valueq
if whitelist[j] or blacklist[j] or ignorevalue[j] or selectvalue[j] then
valueq = valueraw or getValueOfClaim(claim, qual, {["formatting"]="raw", ["lang"]=params.lang, ["list"]=params.list})
if whitelist[j] and whitelist[j][valueq or ""] then
rowlistif whitelist[#valuesj] = truethen
for k, v in pairs(whitelist[j]) do
elseif blacklist[j] and blacklist[j][valueq or ""] then
if v and string.find(valueq, k, 1, true) then
rowlist[#values] = false
rowlist[#values] = true
elseif ignorevalue[j] and ignorevalue[j][valueq or ""] then
end
values[#values]["col" .. j] = nil
end
elseif selectvalue[j] and not selectvalue[j][valueq or ""] then
valueselseif blacklist[#values]["col" .. j] = nilthen
for k, v in pairs(blacklist[j]) do
if v and string.find(valueq, k, 1, true) then
rowlist[#values] = false
end
end
elseif ignorevalue[j] then
for k, v in pairs(ignorevalue[j]) do
if v and string.find(valueq, k, 1, true) then
values[#values]["col" .. j] = nil
end
end
elseif selectvalue[j] then
local selected
for k, v in pairs(selectvalue[j]) do
if v and string.find(valueq, k, 1, true) then
selected = true
end
end
if selected == nil then
values[#values]["col" .. j] = nil
end
end
end
end
Baris 1.349 ⟶ 1.481:
if not value and showerrors then value = error end
if value then
if (parameters.references andor claimparameters.referencesonlysourced) then reference =and claim.references endthen
reference = claim.references
end
refs[#refs]["col0"] = reference
values[#values]["col0"] = value
Baris 1.378 ⟶ 1.512:
table.sort(sortindices, comparator)
end
local maxvals = tonumber(parameters.listlistmax)
result = {}
for idx in pairs(values) do
local valuerow = values[sortindices[idx]]
local reference, valid_ref = getReferences({["references"] = refs[sortindices[idx]]["col0"]}, parameters.lang)
value = valuerow["col0"]
Baris 1.390 ⟶ 1.524:
else
local rowformatting = rowformat .. "$" -- fake end character added for easy gsub
value = mw.ustring.gsub(rowformatting, "$0", {["$0"] = value})
value = mw.ustring.gsub(value, "$R0", reference) -- add reference
for i, _ in ipairs(qualifierId) do
Baris 1.413 ⟶ 1.547:
value = value .. reference
end
if isSet(value) and (not parameters.onlysourced or (parameters.onlysourced and valid_ref)) then
result[#result + 1] = value
if not parameters.list or (maxvals and maxvals == #result) then
Baris 1.420 ⟶ 1.554:
end
end
-- in a table, add edit icon on last element
if parametersargs.formattingquery == 'tablenum' then
resultresult_query = addEditIconTable(#result, parameters)
end
if #result > 0 then
if parameters.formatting == 'table' then
result = addEditIconTable(result, parameters) -- in a table, add edit icon on last element
end
result = preformat .. mw.text.listToText(result, parameters.separator, parameters.conjunction) .. postformat
else
result = ''
end
result = preformat .. mw.text.listToText(result, parameters.separator, parameters.conjunction) .. postformat
else
-- return first element
local claim = claims[sortindices[1]]
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result then
if result and references then result = result .. getReferences(claim, parameters.lang) end
local ref, valid_ref = getReferences(claim, parameters)
if parameters.onlysourced and valid_ref == false then
result = nil
else
result = result .. ref
end
end
if args.query == 'num' then result_query = result and 1 or 0 end
end
Baris 1.440 ⟶ 1.589:
if showerrors then result = error else result = default end
end
returnif result,args.query == 'untranslated' and (required and not is_sandbox) and untranslated or ''then
result_query = untranslated
end
return result, result_query or ''
end
 
Baris 1.446 ⟶ 1.598:
 
local function uc_first(word)
if word == nil then return end
return mw.ustring.upper(mw.ustring.sub(word, 1, 1)) .. mw.ustring.sub(word, 2)
end
 
local function getPropertyValue(id, property, parameter, langs, editiconlabelicon, case)
local snaks = mw.wikibase.getBestStatements(id, property)
local mysnak = getSnak(snaks, {1, "mainsnak"})
Baris 1.460 ⟶ 1.613:
if mysnak.datavalue then
entity_id = "Q" .. tostring(mysnak.datavalue.value['numeric-id'])
result, _ = getSnakValue(mysnak, {formatting=parameter, lang=langs, editiconlabelicon=editiconlabelicon, case=case})
end
Baris 1.473 ⟶ 1.626:
propertyLabel,
propertyLink,
label_show,
labelShow,
labelicon0,
editicon,
labelicon1,
upto,
upto_number,
upto_linkId,
upto_label,
upto_value,
last_only,
grammatical_case,
include_self)
if upto_linkId == nil then upto_linkId = "" end
local upto_link_ids = {}
for q in mw.text.gsplit(upto_linkId, '[^Q%d]') do
upto_link_ids[resolveEntityId(q)] = true
end
local propertySups = mw.text.split(propertySupString, '[^P%d]')
local lastlabelmaxloop = uc_first(upto or '')10
if upto_number then
local maxloop = tonumber(upto) or ((lastlabel .. upto_linkId) == '' and 10 or 50)
maxloop = tonumber(upto_number)
elseif next(upto_label) or next(upto_value) then
local labelFilter = {}
maxloop = 50
if labelShow then
for _, v in ipairs(mw.text.split(labelShow, "/")) do
labelFilter[uc_first(v)] = true
end
end
local labels_filter = next(label_show)
local label_self
_, label_self = getPropertyValue(id, propertyLabel, label_format, languages)
local result = {}
local id_value = id
for iter = 1, maxloop do
local link, label, linktextlabelwicon, _idlinktext, _linkid_label
for _, propertySup in pairs(propertySups) do
_idlocal _id_value, _link = getPropertyValue(idid_value, propertySup, prop_format, languages, editiconlabelicon1, grammatical_case)
if _id_id_value and _link then idid_value = _id_id_value; link = _link break end
end
if not idid_value or not link then break end
if propertyLink then
_, linktext = getPropertyValue(idid_value, propertyLink, "label", languages)
if linktext then
link = mw.ustring.gsub(link, "%[%[(.*)%|.+%]%]", "[[%1|" .. linktext .. "]]")
Baris 1.519 ⟶ 1.665:
end
_id_label, label = getPropertyValue(idid_value, propertyLabel, label_format, languages, false, "infoboxlabel")
if labelicon0 then
_, labelwicon = getPropertyValue(id_value, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
else
labelwicon = label
end
if labelShowlabels_filter == nil or labelFilter(label_show[id_label] or label_show[label]) then
result[#result + 1] = {labellabelwicon, link}
label_show[id_label or 'none'], label_show[label or 'none'] = nil, nil -- only first label found
if label then
labelFilter[label] = nil -- only first label found
end
end
if labelupto_label[id_label] ==or lastlabelupto_label[label] or upto_link_idsupto_value[idid_value] then
break
end
Baris 1.538 ⟶ 1.686:
end
if include_self then table.insert(result, 1, {label_self, mw.title.getCurrentTitle().text}) end
local label_self, link_self
_, label_self = getPropertyValue(id, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
link_self, _ = getLabelByLangs(id, languages)
table.insert(result, 1, {label_self, link_self})
end
return result
Baris 1.555 ⟶ 1.708:
for i = first, last, iter do
local rowtext = mw.ustring.gsub(rowformat, "$[01]", {["$0"] = result[i][1], ["$1"] = result[i][2]})
ret[#ret + 1] = expandBraces(rowtext, rowformat)
end
if cascade then
local direction = mw.language.new(wiki.langcode):isRTL() and "right" or "left"
local prefix = ""
local suffix = ""
for i = 1, #ret do
ret[i] = prefix'<ul style="line-height:100%; margin-' .. "•direction .. ':0.45em; padding-' .. direction .. ':0;"><li>' .. ret[i]
prefixsuffix = prefixsuffix .. "&nbsp;"'</li></ul>'
end
ret[#ret] = ret[#ret] .. suffix
end
Baris 1.569 ⟶ 1.724:
end
 
-- Returns pairs of instanceparent label and property value fetching a recursive tree
function p.getParentValues(frame)
local args = frame.args or frame -- via invoke or require
Baris 1.579 ⟶ 1.734:
if id == nil then return end
local languages = findLang(args.lang)
local propertySup = getArg(args.property; if not isSet(propertySup) then propertySup =, "P131" end) --administrative entity
local propertyLabel = getArg(args.label; if not isSet(propertyLabel) then propertyLabel =, "P31" end) --instance
local propertyLink = getArg(args.valuetext; if propertyLink == "" then propertyLink = nil end --internallink)
local property_format = getArg(args.formatting; if property_format == "" then property_format = nil end)
local label_format = getArg(args.labelformat; if not isSet(label_format) then label_format =, "label" end)
local uptoupto_number = getArg(args.upto; if upto == "" then upto = nil end)
local last_only = getArg(args.last_only, == "true" or args.last_only == "yes"false)
local editicon, labelicon = setIcons(args.editicon, pargs.editicon)
local labelShow = args.labelshow; if labelShow == "" then labelShow = nil end
local editiconinclude_self = setEditIcongetArg(args.editiconinclude_self, or pargs.editiconfalse)
local case = getArg(args.case)
local include_self = (args.include_self == "true" or args.include_self == "yes")
local case = args.case; if case == "" then case = nil end
local upto_label = {}
if isSet(args.uptolabelid) then
upto, for _q =in getLabelByLangsstring.gmatch(args.uptolabelid or '', languages'Q%d+') do
upto_label[q] = true
end
if type(upto_number) == 'string' then
upto_label[uc_first(upto_number)] = true
upto_number = nil
require(wiki.module_title .. '/debug').track('upto') -- replace upto by uptolabelid
end
local upto_value = {}
if isSet(args.showlabelid) then
for q in string.gmatch(args.uptovalueid or args.uptolinkid or '', 'Q%d+') do
local showLabelList = {}
upto_value[q] = true
for substring in mw.text.gsplit(args.showlabelid, '[^Q%d]') do
end
table.insert(showLabelList, (getLabelByLangs(substring, languages)))
end
local label_show = {}
if #showLabelList > 0 then
for q in string.gmatch(args.showlabelid or '', 'Q%d+') do
labelShow = table.concat(showLabelList,"/")
label_show[q] = true
end
for _, v in ipairs(mw.text.split(args.labelshow or '', "/")) do
if v ~= '' then
label_show[uc_first(v)] = true
require(wiki.module_title .. '/debug').track('labelshow') -- replace labelshow by showlabelid
end
end
local rowformat = args.rowformat; if not isSet(rowformat) then rowformat = "$0 = $1" end
local labelicon0, labelicon1 = labelicon, labelicon
if string.find(label_format, '{{.*$0.*}}') or (string.find(rowformat, '{{.*$0.*}}') and label_format ~= 'raw') then
labelicon0 = false
end
Baris 1.612 ⟶ 1.784:
propertyLabel,
propertyLink,
labelShowlabel_show,
editiconlabelicon0,
uptolabelicon1,
upto_number,
args.uptovalueid or args.uptolinkid,
upto_label,
upto_value,
last_only,
case,
Baris 1.621 ⟶ 1.795:
if #result == 0 then return end
local rowformat = args.rowformat; if not isSet(rowformat) then rowformat = "$0 = $1" end
local separator = args.separator; if not isSet(separator) then separator = "<br />" end
local sorting = args.sorting; if sorting == "" then sorting = nil end
Baris 1.654 ⟶ 1.827:
-- get id value of property/qualifier
local largs = mw.clone(args)
largs.list = tonumber(args.list) and args.list or "true"
largs.formatting = "raw"
largs.separator = "/·/"
largs.editicon = "false"
local items_list, _ = p.claim(largs)
if not isSet(items_list) then return end
Baris 1.674 ⟶ 1.847:
else
largs.formatting = "label"
largs.list = "false"
end
largs.property = args.parent
Baris 1.685 ⟶ 1.858:
end
end
args.editicon, _ = setEditIconsetIcons(args.editicon or, pargs.editicon)
args.id = getEntityId(args, pargs)
args.lang = findLang(args.lang)
Baris 1.699 ⟶ 1.872:
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs)
if id == nil then return end
local lang = mw.language.new('en')
local function getBestValue(id, prop)
local snak_value =return getSnak(mw.wikibase.getBestStatements(id, prop), {1, "mainsnak", "datavalue", "value"})
return snak_value
end
Baris 1.720 ⟶ 1.893:
dates[1] = {['min'] = {}, ['max'] = {}, ['precision'] = birth.precision}
dates[1].min.year = tonumber(mw.ustring.match(birth.time, "^[+-]?%d+"))
dates[1].min.month = tonumber(mw.ustring.match(birth.time, "\-(%d%d)\-"))
dates[1].min.day = tonumber(mw.ustring.match(birth.time, "\-(%d%d)T"))
dates[1].max = mw.clone(dates[1].min)
dates[2] = {['min'] = {}, ['max'] = {}, ['precision'] = death.precision}
dates[2].min.year = tonumber(mw.ustring.match(death.time, "^[+-]?%d+"))
dates[2].min.month = tonumber(mw.ustring.match(death.time, "\-(%d%d)\-"))
dates[2].min.day = tonumber(mw.ustring.match(death.time, "\-(%d%d)T"))
dates[2].max = mw.clone(dates[2].min)
Baris 1.771 ⟶ 1.944:
if args.formatting == 'unit' then
local langs = findLang(args.lang)
local yo, yo_sg, yo_pl, yo_pau
local yo_pl = {}
if langs[1] == wiki.langcode then
yo_sgyo_pl = i18n["years-old"].singular
yo_pl = i18n["years-old"].plural
yo_pau = i18n["years-old"].paucal
end
if not isSet(yo_pl[2]) then
yo_pllocal yo_label, _ = getLabelByLangs('Q24564698', langs)
yo_pl = {yo_label, yo_label}
yo_sg = yo_pl
end
yo = mw.language.new(langs[1]):plural(old_max, yo_pl)
if not isSet(yo_pau) then
yo_pau = yo_pl
end
yo = mw.language.new(langs[1]):plural(old_max, {yo_sg, yo_pau, yo_pl})
if mw.ustring.find(yo, '$1', 1, true) then
old_expr = mw.ustring.gsub(yo, "$1", old)
Baris 1.809 ⟶ 1.978:
if id == nil then return end
local languages = findLang(args.lang)
local labelicon = false
local editicon = mw.wikibase.isValidEntityId(id) and setEditIcon(args.editicon or pargs.editicon) or false
if mw.wikibase.isValidEntityId(id) then
_, labelicon = setIcons(args.editicon, pargs.editicon)
end
local label_icon = ''
Baris 1.818 ⟶ 1.990:
-- exceptions or labels fixed
local exist, labels = pcall(require, wiki.module_title .. "/labels" .. (languages[1] == wiki.langcode and '' or '/' .. languages[1]))
if exist and labels.infoboxLabelsFromId and next(labels.infoboxLabelsFromId) ~= nil then
label = labels.infoboxLabelsFromId[id]
end
Baris 1.825 ⟶ 1.997:
label, lang = getLabelByLangs(id, languages)
if label then
if isSet(args.itemgender) and feminineGender(args.itemgender) then
label = feminineForm(id, lang) or label
end
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
if args.case then
label = case(args.case, label, lang)
end
end
label_icon = addLabelIcon(id, lang, languages[1], editiconlabelicon)
end
end
local linked = args.linked
local ret2 = required and untranslated or ''
if isSet(linked) and linked ~= "no" then
local article = mw.wikibase.getSitelink(id) or ("d:Special:EntityPage/" .. id)
return "[[" .. article .. "|" .. (label or id) .. "]]" .. label_icon, not required and '' or untranslatedret2
else
return (label or id) .. label_icon, not required and '' or untranslatedret2
end
end
Baris 1.851 ⟶ 2.027:
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs, 1)
if id == nil then return end
return mw.wikibase.getSitelink(id, mw.text.trim(args[2] or ''))
return
end
return mw.wikibase.getSitelink(id, mw.text.trim(frame.args[2] or ''))
end
 
Baris 1.869 ⟶ 2.043:
local id = getEntityId(args, pargs)
if id == nil then return 0 end
local prop = mw.text.trim(args[1] or '')
local num = {}
if args[2]not isSet(prop) then -- qualifier
local largs = {}
for k, v in pairs(pargs) do
largs[k] = v
end
for k, v in pairs(args) do
largs[k] = v
end
largs.query = 'num'
_, num = p.claim(largs)
return num
elseif args[2] then -- qualifier
local qual = mw.text.trim(args[2])
local values = p.claim{item=id, property=prop, qualifier=qual, formatting='raw', separator='/·/'}
Baris 1.903 ⟶ 2.088:
param.property = args.property
param.lang = findLang(args.lang)
param.editicon, _ = setEditIconsetIcons(args.editicon)
return addEditIcon(param)
end
 
function p.formatNum(frame)
-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidata (fix missing page id on some infobox from enwiki)
local num = tonumber(mw.text.trim(frame.args[1]))
local lang = findLang(mw.text.trim(frame.args[2]))
return mw.language.new(lang[1]):formatNum(num)
end
 
-- [[Modul:Wikidata/Legacy]] compatibility
-- look into entity object
function p.ViewSomething(frame)
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent()
local id = f.args.id
if id and (#id == 0) then
id = nil
end
local data = mw.wikibase.getEntity(id)
if not data then
return nil
end
 
local i = 1
while true do
local index = f.args[i]
if not index then
if type(data) == "table" then
return mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY)
else
return tostring(data)
end
end
 
data = data[index] or data[tonumber(index)]
if not data then
return
end
 
i = i + 1
end
end
 
function p.getImageLegend(frame)
-- look for named parameter id; if it's blank make it nil
local id = frame.args.id
if id and (#id == 0) then
id = nil
end
 
-- look for named parameter lang
-- it should contain a two-character ISO-639 language code
-- if it's blank fetch the language of the local wiki
local lang = frame.args.lang
if (not lang) or (#lang < 2) then
lang = mw.language.getContentLanguage().code
end
 
-- first unnamed parameter is the local parameter, if supplied
local input_parm = mw.text.trim(frame.args[1] or "")
if input_parm == "FETCH_WIKIDATA" then
local ent = mw.wikibase.getEntity(id)
local imgs
if ent and ent.claims then
imgs = ent.claims.P18
end
local imglbl
if imgs then
-- look for an image with 'preferred' rank
for k1, v1 in pairs(imgs) do
if v1.rank == "preferred" and v1.qualifiers and v1.qualifiers.P2096 then
local imglbls = v1.qualifiers.P2096
for k2, v2 in pairs(imglbls) do
if v2.datavalue.value.language == lang then
imglbl = v2.datavalue.value.text
break
end
end
end
end
-- if we don't find one, look for an image with 'normal' rank
if (not imglbl) then
for k1, v1 in pairs(imgs) do
if v1.rank == "normal" and v1.qualifiers and v1.qualifiers.P2096 then
local imglbls = v1.qualifiers.P2096
for k2, v2 in pairs(imglbls) do
if v2.datavalue.value.language == lang then
imglbl = v2.datavalue.value.text
break
end
end
end
end
end
end
return imglbl
else
return input_parm
end
end
 
-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidata
function p.pageId(frame)
local entity =return mw.wikibase.getEntityObjectgetEntityIdForCurrentPage()
if not entity then return nil else return entity.id end
end