local p = require("strict")
-- Wrapper for pcall which returns nil on failure.local function quickPcall(func) local success, result = pcall(func) if success then return result endend
-- Count words by ','local function countpattern(x) local _, count = x:gsub(", ","") return count end
-- Get the rank of statement from tablelocal function getRank(prop) local rank = prop.rank if rank
'normal' then return 0 elseif rank
-- Get the Q-id from the site or arg.local function getId(id) local artikkel if not mw.wikibase then return end if id then artikkel = mw.wikibase.getEntity(id) else artikkel = mw.wikibase.getEntity end if not artikkel then return end return artikkelend
-- Gets all values and add a dot (".") to it.p.file_extension = function(frame) local exts = local artikkel = getId(frame.args[1]) if artikkel
nil then return "" end for i, ext in ipairs(fileExten) do exts[#exts+1] = ("." .. ext.mainsnak.datavalue.value) end return mw.text.nowiki(table.concat(exts, ', '))end
local function formatEntityId(entityId,i) local label local link = mw.wikibase.sitelink(entityId) if i
-- Gets all values and if multip. add multi paradigm: ...p.paradigm = function(frame) local pid = frame.args.pid --Property-ID to find best match local notAllowed = frame.args.notallowed -- Q-value that is not allowed local qId = frame.args.qid -- Q-value that is linked to in .. local collapsedName = frame.args.name -- In collapsed mode name. Like 9 versjoner [vis] or 9 muligheter [vis] local multiName = frame.args.multiname -- The name of qId multiName local paradigms = local artikkel = getId(frame.args[1]) if artikkel
nil then return "" end local count = 0 for i, paradig in ipairs(paradigm) do if paradig.mainsnak.datavalue.value.id ~= notAllowed then --multi-paradigm programming count = count + 1 paradigms[#paradigms+1] = formatEntityId(paradig.mainsnak.datavalue.value.id,count) end end
if paradigms[2] then local values = table.concat(paradigms, ', ') local multi = '' .. multiName .. '' .. ': ' if count >= 5 then return string.format(
%s
%s
, count .. ' ' .. collapsedName,multi .. values) else return multi .. values end elseif paradigms[1] then return paradigms[1] elseif paradigm[1] then return '' .. multiName .. '' endend-- Filter on rank and qqid. Then return with "," between statements.local function findBestProperty(entity, pid, qqid, ppid) local props = local propsAlt =
local prop = quickPcall(function return entity['claims'][pid] end)
if not prop then return end for i, pro in ipairs(prop) do local rank = getRank(pro) if rank
qqid then props[#props+1] = pro.mainsnak.datavalue.value elseif rank
qqid then propsAlt[#propsAlt+1] = pro.mainsnak.datavalue.value end end if props[1] then return quickPcall(function return table.concat(props, ', ') end) elseif propsAlt[1] then return quickPcall(function return table.concat(propsAlt, ', ') end) else return endend
-- Find the version that you are looking for. Adds it to a collapsed class if over 5.p.version = function(frame) local artikkel = getId(frame.args[1]) -- Args[1] is the Q-id (alt) local pid = frame.args.pid -- Property (Pxx) under Q-value (Qxxxx) local qQid = frame.args.qqid -- Secound Q-id local pPid = frame.args.ppid -- Secound P-id (Property) local alle = frame.args.alle -- if 'ja' and if findBestProperty return nil, get all statements local priVersions = quickPcall(function return findBestProperty(artikkel,pid,qQid,pPid) end) if priVersions
'ja' then local temp = artikkel:formatPropertyValues(pid, mw.wikibase.entity.claimRanks) priVersions = temp['value'] end if countpattern(priVersions) > 5 then return string.format(
%s versjoner
%s
, countpattern(priVersions), priVersions) else return mw.text.nowiki(priVersions) endendreturn p