Modul:Wikidata/bakpasir: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Hidayatsrf (bicara | kontrib) +pageId |
Hidayatsrf (bicara | kontrib) -- version 20200701 from master @cawiki |
||
Baris 1:
-- version
local p = {}
Baris 31:
[10] = "F Y", -- precision: month
[11] = "F j, Y", -- precision: day
["hms"] = {["hours"] = "h", ["minutes"] = "m", ["seconds"] = "s"}, -- duration: xh xm xs
},
Baris 39 ⟶ 41:
},
["cite"] = { --
["
["
["
["
["
-- cite web parameters
["
["
["
["
["archive-date"]
["
["quote"] = "quote",
-- cite journal parameters
["work"] = "work",
["issue"] = "issue",
["issn"] = "issn",
["doi"] = "doi"
},
Baris 69 ⟶ 77:
}
local untranslated -- used in infobox modules: nil or true
local _ -- variable for unused returned values, avoiding globals
-- Module local functions --------------------------------------------
Baris 75 ⟶ 84:
-- Credit to http://stackoverflow.com/a/1283608/2644759, cc-by-sa 3.0
local function tableMerge(t1, t2)
for k, v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
Baris 90 ⟶ 99:
local function loadI18n(lang)
local
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
cases = res.cases
end
if lang ~= wiki.langcode then
exist, res = pcall(require, wiki.module_title .. "/i18n/" .. lang)
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
tableMerge(cases, res.cases)
end
end
end
Baris 130 ⟶ 144:
-- Argument is 'set' when it exists (not nil) or when it is not an empty string.
local function isSet(var)
return not (not var
end
Baris 144 ⟶ 158:
return label
end
-- get safely a serialized snak
local function getSnak(statement, snaks)
local ret = statement
for i, v in ipairs(snaks) do
if not ret then return end
ret = ret[v]
end
return ret
end
Baris 152 ⟶ 176:
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 163 ⟶ 187:
end
return label, lang
end
-- getBestStatements if bestrank=true, else getAllStatements with no deprecated
local function getStatements(entityId, property, bestrank)
local claims = {}
if not (entityId and mw.ustring.match(property, "^P%d+$")) then return claims end
if bestrank then
claims = mw.wikibase.getBestStatements(entityId, property)
else
local allclaims = mw.wikibase.getAllStatements(entityId, property)
for _, c in ipairs(allclaims) do
if c.rank ~= "deprecated" then
table.insert(claims, c)
end
end
end
return claims
end
Baris 168 ⟶ 209:
local function feminineGender(id)
local claims = mw.wikibase.getBestStatements(id or mw.wikibase.getEntityIdForCurrentPage(),'P21')
if getSnak(claims, {1, "mainsnak", "datavalue"}) == nil then -- no claim, novalue or somevalue
return false
else
Baris 183 ⟶ 222:
-- Fetch female form of label
local function feminineForm(id, lang)
local feminine_claims =
for _, feminine_claim in ipairs(feminine_claims) do
if getSnak(feminine_claim
return feminine_claim.mainsnak.datavalue.value.text
end
end
end
Baris 212 ⟶ 241:
.. mw.message.new('Translate-taction-translate'):inLanguage(uselang):plain()
.. "|link=https://www.wikidata.org/wiki/Special:EntityPage/" .. label_id .. "?uselang=" .. uselang .. "]]"
end
if isSet(i18n.categorylabels) and lang ~= uselang and uselang == wiki.langcode then
Baris 219 ⟶ 248:
end
return ret_lang .. ret_icon
end
-- editicon values: true/false (no=false), right, void defaults to i18n.addpencil
local function setEditIcon(param)
if not isSet(param) then return i18n.addpencil end
if param == "false" or param == "no" then return false end
return param
end
Baris 224 ⟶ 260:
local function addEditIcon(parameters)
local ret = ''
if
local icon_style = parameters.editicon == "right" and ' style="float: right;"' or ''
ret = ' <span class="penicon" data-bridge-edit-flow="single-best-value"' .. icon_style .. '>'
.. "[[File:Arbcom ru editing.svg|10px|baseline|"
.. string.gsub(mw.message.new('
.. "|link=https://www.wikidata.org/wiki/" .. parameters.id .. "?uselang=" .. parameters.lang[1] .. "#" .. parameters.property .. "]]"
.. "</span>"
Baris 235 ⟶ 272:
-- add edit icon to the last element of a table
local function addEditIconTable(thetable, parameters)
if #thetable == 0 or
return thetable
end
Baris 306 ⟶ 343:
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
-- 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
Baris 317 ⟶ 355:
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)
Baris 340 ⟶ 378:
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
local data_number = string.match(data, "^%d+")
if data_number then -- sort key by initial number and remaining string
local sortkey = string.format("%019d", data_number * 1000)
return data, sortkey .. string.sub(data, #data_number + 1)
end
return data
Baris 360 ⟶ 403:
return '[' .. data .. ' ' .. label .. ']'
end
return
end
-- format data type external-id
local function printDatatypeExternal(data, parameters)
if parameters.formatting == 'externalid' then
local p_stat = mw.wikibase.getBestStatements(parameters.property, 'P1630') -- formatter URL
local p_link_pattern = getSnak(p_stat, {1, "mainsnak", "datavalue", "value"})
if p_link_pattern then
local p_link = mw.ustring.gsub(p_link_pattern, '$1', {['$1'] = data})
return '[' .. p_link .. ' ' .. data .. ']'
end
end
return printDatatypeString(data, parameters)
end
Baris 369 ⟶ 425:
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',
Baris 426 ⟶ 482:
if unit_symbol == '' then
-- fetch it
local claims =
if #claims > 0 then
local langclaims = {}
table.insert(lang, 'mul') -- multilingual as last try
Baris 470 ⟶ 526:
end
local function
-- rounds out_num with significant figures of in_num (default precision)
local out_num = in_num * factor
if factor/60 == math.floor(factor/60) then -- sexagesimal integer
return out_num
end
-- first, count digits after decimal mark, handling cases like '12.345e6'
local exponent, prec
Baris 496 ⟶ 556:
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" or string.sub(parameters.formatting or '', 1, 8) == "duration" or parameters.convert then
local unit_id = data.unit
unit_id = mw.ustring.sub(unit_id, mw.ustring.find(unit_id, "Q"), -1)
Baris 515 ⟶ 574:
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
end
if convert_to and convert_to ~= unit_id then
Baris 528 ⟶ 589:
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
Baris 550 ⟶ 611:
local lang_obj = mw.language.new(parameters.lang[1])
local sortkey = string.format("%019d", tonumber(amount) * 1000)
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:s' then
local intervals = {"hours", "minutes", "seconds"}
local sec2table = lang_obj:getDurationIntervals(sec, intervals)
sec2table["seconds"] = (sec2table["seconds"] or 0) + tonumber("." .. (tostring(sec):match("%.(%d+)") or "0")) -- add decimals
local duration = ''
for i, v in ipairs(intervals) do
if parameters.formatting == 'durationh:m:s' then
if i == 1 and sec2table[v] then
duration = duration .. sec2table[v] .. ":"
elseif i == 2 then
duration = duration .. string.format("%02d", sec2table[v] or 0) .. ":"
elseif i == 3 then
local sec_str = tostring(lang_obj:formatNum(sec2table[v] or 0))
duration = duration .. (sec2table[v] < 10 and "0" or "") .. sec_str
end
elseif sec2table[v] then
duration = duration .. lang_obj:formatNum(sec2table[v]) .. i18n.datetime.hms[v] .. (i < 3 and " " or "")
end
end
return duration
else
return lang_obj:formatDuration(sec)
end
end
if parameters.case then
amount = case(parameters.case, amount, parameters.lang[1])
Baris 567 ⟶ 654:
end
-- format data
local function
-- Dates and times are stored in ISO 8601 format
local timestamp = data.time
Baris 657 ⟶ 744:
end
-- format data value
local function
local entity_id = data['id']
if parameters.formatting == 'raw' then
return entity_id, entity_id
end
Baris 675 ⟶ 759:
end
if parameters.case ~= 'gender' then
labelcase = case(parameters.case, labelcase, lang, parameters.lang[1], entity_id, parameters.id)
end
local ret1, ret2
Baris 704 ⟶ 788:
ret1 = '[[' .. sitelink .. '|' .. labelcase .. ']]'
ret2 = labelcase
elseif label and string.match(parameter
ret1 = '[[' .. label .. '|' .. labelcase .. ']]'
ret2 = labelcase
Baris 716 ⟶ 800:
end
-- format data
local function
-- data fields: language [string], text [string]
Baris 735 ⟶ 819:
end
return result
end
local function getSnakValue(snak, parameters)
if snak.snaktype == 'value' then
-- see Special:ListDatatypes
if snak.datatype ==
return printDatatypeString(snak.datavalue.value, parameters)
-- other data value string, tabular-data not implemented
elseif snak.datatype == "commonsMedia" then
return printDatatypeMedia(snak.datavalue.value, parameters)
elseif snak.datatype == "url" then
return printDatatypeUrl(snak.datavalue.value, parameters)
elseif snak.datatype == "external-id" then
return printDatatypeExternal(snak.datavalue.value, parameters)
elseif snak.datatype == 'math' then
return printDatatypeMath(snak.datavalue.value)
elseif snak.datatype == 'musical-notation' then
return printDatatypeMusical(snak.datavalue.value, parameters.formatting)
-- other data types
elseif snak.datatype == 'wikibase-item' or snak.datatype == 'wikibase-property' then
return printDatatypeEntity(snak.datavalue.value, parameters)
elseif snak.datatype == 'monolingualtext' then
elseif snak.datatype == "globe-coordinate" then
elseif snak.datatype == "quantity" then
elseif snak.datatype == "time" then
end
elseif snak.snaktype == 'novalue' then
if parameters.formatting == 'raw' or parameters.shownovalue == false then return end
return mw.message.new('Wikibase-snakview-snaktypeselector-novalue'):inLanguage(parameters.lang[1]):plain()
elseif snak.snaktype == 'somevalue' then
Baris 804 ⟶ 857:
end
return mw.wikibase.renderSnak(snak)
end
local function printError(key)
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
Baris 836 ⟶ 893:
end
local function getValueOfClaim(claim, qualifierId, parameters)
local snak, error = getQualifierSnak(claim, qualifierId, parameters)
if not snak then
return nil, nil, error
elseif snak[1] then -- a multi qualifier
local result, sortkey = {}, {}
local
for idx in pairs(snak) do
result[#result + 1], sortkey[#sortkey + 1] = getSnakValue(snak[idx], parameters)
if maxvals and maxvals == #result then break end
end
return mw.text.listToText(result, parameters.qseparator, parameters.qconjunction), sortkey[1]
Baris 854 ⟶ 912:
local function getValueOfParentClaim(claim, qualifierId, parameters)
local qids = mw.text.split(qualifierId, '/', true)
local
local parent_raw, value_text
if qids[1] == parameters.property then
else
end
if string.sub(
local parent_qids = mw.text.split(parent_raw, '/', true)
for idx, p_qid in ipairs(parent_qids) do
local parent_claims = mw.wikibase.getBestStatements(p_qid, qids[2])
if parent_claims[1] then
-- raw parent value needed for while/black lists, lang for avoiding an error on types other than entity
valueraw[idx], _, _ = getValueOfClaim(parent_claims[1], nil, {["formatting"]="raw", ["lang"]=parameters.lang})
end
end
end
value_text = mw.text.listToText(value, parameters.qseparator, parameters.qconjunction)
end
return value_text, sortkey[1], valueraw[1]
end
-- see d:Help:Sources
local function getReferences(claim, lang)
local notproperref = {
["P143"] = true, -- imported from
Baris 884 ⟶ 950:
local refs = {}
local validref = true
local ref_name
-- traverse through all parts of the current reference
for snakkey, snakval in pairs(claim.references[ref].snaks or {}) do
Baris 895 ⟶ 962:
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
if snakkey == "P248" then -- stated in
ref_name = snakval[1].datavalue.value.id
end
end
end
-- fill missing values with parent item
if ref_name then
local function refParent(qid, pid, formatting)
local snak = getSnak(mw.wikibase.getBestStatements(qid, pid), {1, "mainsnak"})
return snak and getSnakValue(snak, {formatting=formatting, lang=lang})
end
refs['P50'] = refs['P50'] or refParent(ref_name, 'P50', 'label') -- author
refs['P407'] = refs['P407'] or refParent(ref_name, 'P407', 'label') -- language of work
refs['P123'] = refs['P123'] or refParent(ref_name, 'P123', 'label') -- publisher
refs['P577'] = refs['P577'] or refParent(ref_name, 'P577') -- date
refs['P1433'] = refs['P1433'] or refParent(ref_name, 'P1433', 'label') -- published in
refs['P304'] = refs['P304'] or refParent(ref_name, 'P304') -- page(s)
refs['P433'] = refs['P433'] or refParent(ref_name, 'P433') -- issue
refs['P236'] = refs['P236'] or refParent(ref_name, 'P236') -- ISSN
refs['P356'] = refs['P356'] or refParent(ref_name, 'P356') -- DOI
end
-- get title of local templates for citing references
local template_web = mw.wikibase.getSitelink('Q5637226') or ""
template_web = mw.text.split(template_web, ":")[2] -- split off namespace from front
local template_journal = mw.wikibase.getSitelink('Q5624899') or ""
template_journal = mw.text.split(template_journal, ":")[2]
local citeParams = {}
if refs['P854'] and (refs['P1476'] or refs['P248']) and template_web then
-- if both "reference URL" and "title" (or "stated in") are present, then use cite web template
citeParams[i18n['cite']['url']] = refs['P854']
citeParams[i18n['cite']['title']] = refs['P248']:match("^%[%[.-|(.-)%]%]")
else
citeParams[i18n['cite']['title']] = refs['P1476']
citeParams[i18n['cite']['website']] = refs['P248']
end
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['
citeParams[i18n['cite']['publisher']] = refs['P123']
citeParams[i18n['cite']['date']] = refs['P577']
Baris 921 ⟶ 1.015:
citeParams[i18n['cite']['archive-date']] = refs['P2960']
citeParams[i18n['cite']['quote']] = refs['P1683']
refparts = mw.getCurrentFrame():expandTemplate{title=
elseif refs['P1433'] and (refs['P1476'] or refs['P248']) and template_journal then
-- if both "published in" and "title" (or "stated in") are present, then use cite journal template
citeParams[i18n['cite']['work']] = refs['P1433']
citeParams[i18n['cite']['title']] = refs['P1476'] or refs['P248']
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['date']] = refs['P577']
citeParams[i18n['cite']['issue']] = refs['P433']
citeParams[i18n['cite']['pages']] = refs['P304']
citeParams[i18n['cite']['language']] = refs['P407']
citeParams[i18n['cite']['issn']] = refs['P236']
citeParams[i18n['cite']['doi']] = refs['P356']
refparts = mw.getCurrentFrame():expandTemplate{title=template_journal, args=citeParams}
elseif validref then
-- raw ouput
local snaksorder = claim.references[ref]["snaks-order"]
local function indexed(a)
for _, b in ipairs(snaksorder) do
if b == a then return true end
end
return false
end
for k, _ in pairs(refs or {}) do
if not indexed(k) then
table.insert(snaksorder, k)
end
end
local italics = "''"
for
if refs[k
refparts = refparts and refparts .. " " or ""
refparts = refparts .. mw.ustring.gsub(
refparts = refparts .. italics ..
italics = ""
end
end
end
if refparts then result =
end
return result
Baris 940 ⟶ 1.058:
-- Set whitelist or blacklist values
local function setWhiteOrBlackList(
local lists = {['whitelist']={}, ['blacklist']={}, ['ignorevalue']={}, ['selectvalue']={}}
for i = 0, num_qual do
for k, _ in pairs(lists) do
if isSet(args[k .. i]) then
lists[k][tostring(i)][resolveEntityId(q)] = true
end
end
end
end
return lists['whitelist'], lists['blacklist'], lists['ignorevalue'], lists['selectvalue']
end
Baris 983 ⟶ 1.083:
end
local function getEntityId(
local id = args.item or args.from or (unnamed and mw.text.trim(args[1] or '') or nil)
if not isSet(id)
id = pargs.item or pargs.from or (unnamed and mw.text.trim(pargs[1] or '') or nil)
end
Baris 1.003 ⟶ 1.102:
-- on debug console use: =p.claim{item="Q...", property="P...", ...}
function p.claim(frame)
local args = frame.args or frame -- via invoke or require
local is_sandbox = isSet(pargs.sandbox)
if not required and is_sandbox then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).claim(frame)
end
--If a value is already set, use it
if isSet(args.value) then
Baris 1.018 ⟶ 1.118:
-- arguments
local id = getEntityId(
if id == nil then return end
local property = string.upper(args.property or "")
Baris 1.028 ⟶ 1.128:
i = i + 1
end
local formatting = isSet(args.formatting
local convert = isSet(args.convert
local case = args.case
local list = args.list or true; if (list == "false" or list == "no") then list = false end
if list == 'firstrank' then list = 'bestrank' end -- alias
local shownovalue = args.shownovalue or true; if (shownovalue == "false" or shownovalue == "no") then shownovalue = false end
local sorting_col = args.tablesort
local sorting_up = (args.sorting or "") ~= "-1"
Baris 1.041 ⟶ 1.143:
local default = args.default
if default then showerrors = nil end
local parameters = {["id"] = id, ["property"] = property, ["formatting"] = formatting, ["convert"] = convert,
["list"] = list, ["case"] = case, ["
["separator"] = separator, ["conjunction"] = conjunction, ["qseparator"] = separator, ["qconjunction"] = conjunction}
parameters.lang = findLang(args.lang)
parameters.editicon = formatting ~= "raw" and setEditIcon(args.editicon or pargs.editicon) or false -- needs loadI18n by findLand
-- fetch property
local claims = {}
local bestrank = (parameters.list == false or parameters.list == 'bestrank') and parameters.list ~= 'lang'
for p in string.gmatch(parameters.property, 'P%d+') do
claims = getStatements(id, p, bestrank)
if #claims > 0 then
parameters.property = p
break
end
end
if #claims == 0 then
if showerrors then return printError("property-not-found") else return default end
end
-- defaults for table
local preformat, postformat = "", ""
local whitelisted
local whitelist, blacklist, ignorevalue, selectvalue = {}, {}, {}, {}
if parameters.formatting == "table" then
parameters.separator = parameters.separator or "<br />"
Baris 1.079 ⟶ 1.195:
-- set whitelist and blacklist values
whitelist,
local next = next
if next(whitelist) ~= nil then whitelisted = true end
end
-- set feminine case if gender is requested
local itemgender = args
local idgender
if itemgender then
Baris 1.155 ⟶ 1.259:
local sortkeys = {}
local refs = {}
local rowlist = {} -- rows to list with whitelist or blacklist
for idx in pairs(claims) do
Baris 1.161 ⟶ 1.264:
local reference = {}
if not whitelisted then rowlist[idx] = true end
if parameters.formatting == "table" then
local params = tableParameters(args, parameters, "0")
Baris 1.183 ⟶ 1.283:
params = tableParameters(args, parameters, j)
local valueq, sortkeyq, valueraw
if qual == parameters.property then -- hack for getting the property with another formatting, i.e. colformat1=raw
valueq, sortkeyq, _ = getValueOfClaim(claim, nil, params)
else
Baris 1.190 ⟶ 1.290:
valueq, sortkeyq, valueraw = getValueOfParentClaim(claim, q, params)
elseif string.find(q, "^/.+") then
local claim2 =
if #claim2 > 0 then
valueq, sortkeyq, _ = getValueOfClaim(claim2[1], nil, params)
end
Baris 1.202 ⟶ 1.302:
values[#values]["col" .. j] = valueq
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})
if whitelist[j] and whitelist[j][valueq or ""] then
Baris 1.208 ⟶ 1.308:
elseif blacklist[j] and blacklist[j][valueq or ""] then
rowlist[#values] = false
elseif ignorevalue[j] and ignorevalue[j][valueq or ""] then
values[#values]["col" .. j] = nil
elseif selectvalue[j] and not selectvalue[j][valueq or ""] then
values[#values]["col" .. j] = nil
end
end
Baris 1.232 ⟶ 1.336:
end
if sorting_col then
local sorting_table = mw.text.split(sorting_col, '
local comparator = function(a, b)
local valuea, valueb
Baris 1.249 ⟶ 1.353:
table.sort(sortindices, comparator)
end
local maxvals = tonumber(parameters.list)
result = {}
for idx in pairs(values) do
local valuerow = values[sortindices[idx]]
local reference = getReferences({["references"] = refs[sortindices[idx]]["col0"]}, parameters.lang)
value = valuerow["col0"]
Baris 1.264 ⟶ 1.369:
for i, _ in ipairs(qualifierId) do
local valueq = valuerow["col" .. i]
if args["rowsubformat" .. i] and isSet(valueq) then
-- add fake end character $
-- gsub $i not followed by a number so $1 doesn't match $10, $11...
Baris 1.285 ⟶ 1.390:
if isSet(value) then
result[#result + 1] = value
if not parameters.list or (maxvals and maxvals == #result) then
break
end
Baris 1.291 ⟶ 1.396:
end
-- in a table, add edit icon on last element
if parameters.formatting == 'table'
result = addEditIconTable(result, parameters)
end
Baris 1.299 ⟶ 1.404:
local claim = claims[sortindices[1]]
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result and references then result = result .. getReferences(claim, parameters.lang) end
end
if isSet(result) then
if not (parameters.formatting == 'table' or (result2 and result2 == 'no-icon')) then
-- add edit icon, except table added previously and except explicit no-icon internal flag
result = result .. addEditIcon(parameters)
end
else
if showerrors then
end
return result, (required and not is_sandbox) and untranslated or ''
end
Baris 1.350 ⟶ 1.426:
local function getPropertyValue(id, property, parameter, langs, editicon, case)
local snaks = mw.wikibase.getBestStatements(id, property)
local mysnak = getSnak(snaks, {1, "mainsnak"})
if
return
end
Baris 1.365 ⟶ 1.439:
return entity_id, result
end
local function getParentObjects(id,
prop_format,
label_format,
languages,
propertySupString,
Baris 1.391 ⟶ 1.456:
include_self)
if
local upto_link_ids = {}
for q in mw.text. upto_link_ids[resolveEntityId(q)] = true
end
local propertySups = mw.text.split(propertySupString, '[^P%d]')
local lastlabel = uc_first(upto or '')
local maxloop = tonumber(upto) or ((lastlabel .. upto_linkId) == '' and 10 or 50)
local labelFilter = {}
if labelShow then
for
labelFilter[uc_first(v)] = true
end
Baris 1.406 ⟶ 1.474:
local label_self
_, label_self = getPropertyValue(id, propertyLabel,
local result = {}
for iter = 1, maxloop do
local link, label,
for _, propertySup in pairs(propertySups) do
_id, _link = getPropertyValue(id, propertySup,
if _id and _link then id = _id; link = _link break end
end
Baris 1.428 ⟶ 1.494:
end
_, label = getPropertyValue(id, propertyLabel,
if labelShow == nil or labelFilter[label] then
Baris 1.438 ⟶ 1.504:
end
if
break
end
Baris 1.484 ⟶ 1.546:
-- Returns pairs of instance label and property value fetching a recursive tree
function p.getParentValues(frame)
local pargs = frame.args and frame:getParent().args or {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).getParentValues(frame)
end
local
if id == nil then return end
local languages = findLang(args.lang)
Baris 1.494 ⟶ 1.557:
local propertyLabel = args.label; if not isSet(propertyLabel) then propertyLabel = "P31" end --instance
local propertyLink = args.valuetext; if propertyLink == "" then propertyLink = nil end --internallink
local property_format = args.formatting; if property_format == "" then property_format = nil end
local label_format = args.labelformat; if not isSet(label_format) then label_format = "label" end
local upto = args.upto; if upto == "" then upto = nil end
local last_only = (args.last_only == "true" or args.last_only == "yes")
local labelShow = args.labelshow; if labelShow == "" then labelShow = nil end
local editicon =
local include_self = (args.include_self == "true" or args.include_self == "yes")
local case = args.case; if case == "" then case = nil end
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
Baris 1.516 ⟶ 1.581:
local result = getParentObjects(id,
property_format,
label_format,
languages,
propertySup,
Baris 1.524 ⟶ 1.590:
editicon,
upto,
args.uptovalueid or args.uptolinkid,
last_only,
case,
Baris 1.545 ⟶ 1.611:
-- Link with a parent label --------------------
function p.linkWithParentLabel(frame)
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).linkWithParentLabel(frame)
end
Baris 1.562 ⟶ 1.629:
-- 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
local items_table = mw.text.split(items_list, "/·/", true)
Baris 1.572 ⟶ 1.639:
-- get internal link of property/qualifier
largs.formatting = "internallink"
local link_list, _ = p.claim(largs)
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
Baris 1.588 ⟶ 1.655:
for i, v in ipairs(items_table) do
largs.item = v
local link_label, _ = p.claim(largs)
if isSet(link_label) then
link_table[i] = mw.ustring.gsub(link_table[i] or '', "%[%[(.*)%|.+%]%]", "[[%1|" .. link_label .. "]]")
end
end
args.editicon =
args.id = getEntityId(
args.lang = findLang(args.lang)
return mw.text.listToText(link_table) .. addEditIcon(args)
Baris 1.601 ⟶ 1.668:
-- Calculate number of years old ----------------------------
function p.yearsOld(frame)
if not required and frame.args and isSet(frame:getParent().args.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).yearsOld(frame)
end
local args = frame.args or frame -- via invoke or require
local
local id = getEntityId(args, pargs)
local lang = mw.language.new('en')
Baris 1.685 ⟶ 1.753:
end
if not isSet(yo_pl) then
yo_pl, _ = getLabelByLangs('Q24564698', langs)
yo_sg = yo_pl
end
Baris 1.708 ⟶ 1.776:
-- Gets a label in a given language (content language by default) or its fallbacks, optionnally linked.
function p.getLabel(frame)
local args = frame.args or frame -- via invoke or require
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).getLabel(frame)
end
local
if id == nil then return end
local languages = findLang(args.lang)
local editicon = mw.wikibase.isValidEntityId(id) and setEditIcon(args.editicon or pargs.editicon) or false
local label_icon = ''
Baris 1.722 ⟶ 1.791:
label = args.label
else
-- exceptions or labels fixed
local exist, labels = pcall(require, wiki.module_title .. "/labels" .. (languages[1] == wiki.langcode and '' or '/' .. languages[1]))
Baris 1.730 ⟶ 1.798:
if label == nil then
if
if args.itemgender and feminineGender(args.itemgender) then
end
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
end
label_icon = addLabelIcon(id, lang, languages[1], editicon)
end
end
Baris 1.746 ⟶ 1.811:
local linked = args.linked
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 untranslated
else
return (label or id) .. label_icon, not required and '' or untranslated
end
end
Baris 1.758 ⟶ 1.823:
-- Copied from Module:Wikibase
function p.getSiteLink(frame)
local
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs, 1)
if id == nil then
return
Baris 1.773 ⟶ 1.840:
-- Number of statements
function p.numStatements(frame)
local
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs)
if id == nil then return 0 end
local prop = mw.text.trim(args[1])
local num =
if args[2] then -- qualifier
local qual = mw.text.trim(args[2])
local values = p.claim{item=id, property=prop, qualifier=qual, formatting='raw', separator='/·/'}
if values then
num = mw.text.split(values, '/·/')
end
else
num = mw.wikibase.getBestStatements(id, prop)
end
return #num
end
Baris 1.785 ⟶ 1.860:
-- Returns true if property datavalue is found excluding novalue/somevalue
function p.validProperty(frame)
local
local
local item = getEntityId(args, pargs)
if item == nil then return end
local
local prop_data = getSnak(mw.wikibase.getBestStatements(item, property), {1, "mainsnak", "datavalue"})
return
end
function p.editAtWikidata(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local value = isSet(args[1])
if value then return end
local param = {}
param.id = getEntityId(args, pargs)
param.property = args.property
param.lang = findLang(args.lang)
param.editicon = setEditIcon(args.editicon)
return addEditIcon(param)
end
|