Modul:Wikidata: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
k uji coba |
Tag: Pembatalan Suntingan perangkat seluler Suntingan peramban seluler Suntingan seluler lanjutan |
||
(18 revisi perantara oleh 4 pengguna tidak ditampilkan) | |||
Baris 1:
-- version
-- 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
-- see documentation of PLURAL magic word in your language, examples:
-- ["years-old"] = {"singular", "paucal", "plural"} in Russian and other Slavic languages
-- ["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)
["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:
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 (
end
Baris 151 ⟶ 159:
if not isSet(label) then return label end
if type(localcase) == "
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
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')
if gender_id == "Q6581072" or gender_id == "Q1052281" or gender_id == "Q43445" then -- female, transgender female, female organism
return true
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
untranslated = true
end
Baris 251 ⟶ 261:
-- editicon values: true/false (no=false), right, void defaults to i18n.addpencil
-- labelicon only by parameter
local function setIcons(arg, parg)
local edit_icon, label_icon
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
.. "[[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
local param_value = mw.ustring.sub(parts[i], subparts + 1, -1) -- reconstruct broken links by parts
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
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 = "[[" .. (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
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.
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 =
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 == '
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
end
end
if parameters.case then
amount = case(parameters.case, amount, parameters.lang[1], feminineGender(parameters.id))
elseif parameters.formatting ~= 'raw' then
if parameters.numformat then
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",
conv_amount = lang_obj:formatNum
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") --
ret = string.gsub(ret, "( %[?%[?)0+", "%1")
return ret
Baris 744 ⟶ 789:
end
-- format data value wikibase-entityid
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.
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
-- 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
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)
--
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
Baris 924 ⟶ 974:
elseif snak[1] then -- a multi qualifier
local result, sortkey = {}, {}
local maxvals = tonumber(parameters.
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,
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
-- 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
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
end
end
Baris 998 ⟶ 1.057:
-- fill missing values with parent item
if
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(
refs['P407'] = refs['P407'] or refParent(
refs['P123'] = refs['P123'] or refParent(
refs['P577'] = refs['P577'] or refParent(
refs['P1433'] = refs['P1433'] or refParent(
refs['P304'] = refs['P304'] or refParent(
refs['P433'] = refs['P433'] or refParent(
refs['P236'] = refs['P236'] or refParent(
refs['P356'] = refs['P356'] or refParent(
end
Baris 1.077 ⟶ 1.136:
end
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
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)] = {}
if string.sub(args[k .. i], 1, 1) ~= 'Q' then
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
parameters.id = getEntityId(args, pargs)
if parameters.id == nil then return end
parameters.property = string.upper(args.property or "")
local qualifierId = {}
qualifierId[1] =
local i = 2
while isSet(args["qualifier" .. i]) do
Baris 1.153 ⟶ 1.244:
i = i + 1
end
parameters.numformat = getArg(args.numformat)
parameters.case = args.case
parameters.listmax = args.listmax
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 rowformat = args.rowformat
parameters.onlysourced = getArg(args.onlysourced, false)
local showerrors = args.showerrors
local default = args.default
if default then showerrors = nil end
parameters.lang = findLang(args.lang)
if parameters.
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 =
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
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 =
parameters.qconjunction =
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
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
for k, v in pairs(whitelist[j]) do
if v and string.find(valueq, k, 1, true) then
rowlist[#values] = true
end
end
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
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.
result = {}
for idx in pairs(values) do
local valuerow = values[sortindices[idx]]
local reference, valid_ref = getReferences({["references"] = refs[sortindices[idx]]["col0"]}, parameters
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
if
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
else
-- return first element
local claim = claims[sortindices[1]]
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result then
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
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,
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,
end
Baris 1.473 ⟶ 1.626:
propertyLabel,
propertyLink,
label_show,
labelicon0,
labelicon1,
upto_number,
upto_label,
upto_value,
last_only,
grammatical_case,
include_self)
local propertySups = mw.text.split(propertySupString, '[^P%d]')
local
if upto_number then
maxloop = tonumber(upto_number)
elseif next(upto_label) or next(upto_value) then
maxloop = 50
end
local labels_filter = next(label_show)
local result = {}
local id_value = id
for iter = 1, maxloop do
local link, label,
for _, propertySup in pairs(propertySups) do
if
end
if not
if propertyLink then
_, linktext = getPropertyValue(
if linktext then
link = mw.ustring.gsub(link, "%[%[(.*)%|.+%]%]", "[[%1|" .. linktext .. "]]")
Baris 1.519 ⟶ 1.665:
end
if labelicon0 then
_, labelwicon = getPropertyValue(id_value, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
else
labelwicon = label
end
if
result[#result + 1] = {
label_show[id_label or 'none'], label_show[label or 'none'] = nil, nil -- only first label found
end
if
break
end
Baris 1.538 ⟶ 1.686:
end
if include_self then
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 suffix = ""
for i = 1, #ret do
ret[i] =
end
ret[#ret] = ret[#ret] .. suffix
end
Baris 1.569 ⟶ 1.724:
end
-- Returns pairs of
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
local propertyLabel = getArg(args.label
local propertyLink = getArg(args.valuetext
local property_format = getArg(args.formatting
local label_format = getArg(args.labelformat
local
local last_only = getArg(args.last_only,
local editicon, labelicon = setIcons(args.editicon, pargs.editicon)
local
local case = getArg(args.case)
local upto_label = {}
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 = {}
for q in string.gmatch(args.uptovalueid or args.uptolinkid or '', 'Q%d+') do
upto_value[q] = true
end
local label_show = {}
for q in string.gmatch(args.showlabelid or '', 'Q%d+') do
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,
upto_number,
upto_label,
upto_value,
last_only,
case,
Baris 1.621 ⟶ 1.795:
if #result == 0 then return 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
largs.formatting = "raw"
largs.separator = "/·/"
largs.editicon =
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 =
end
largs.property = args.parent
Baris 1.685 ⟶ 1.858:
end
end
args.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)
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, "
dates[1].min.day = tonumber(mw.ustring.match(birth.time, "
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, "
dates[2].min.day = tonumber(mw.ustring.match(death.time, "
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
local yo_pl = {}
if langs[1] == wiki.langcode then
end
if not isSet(yo_pl[2]) then
yo_pl = {yo_label, yo_label}
end
yo = mw.language.new(langs[1]):plural(old_max, 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
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],
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,
else
return (label or id) .. label_icon,
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 ''))
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
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, _ =
return addEditIcon(param)
end
function p.formatNum(frame)
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)
end
|