« Module:Wikidata » : différence entre les versions

Contenu supprimé Contenu ajouté
Elfix (discussion | contributions)
rv temporaire (test)
Elfix (discussion | contributions)
m ok
Ligne 1 :
--script that retrieves basic data stored in Wikidata, for the datamodel, see https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
 
 
local p = {}
local linguistic = require('Module:Linguistique')
local dates = require('Module:Wikidata/Dates')
local langmodule = require('Module:Langue')
lang = 'fr' -- peut-être écrasé par args.lang
 
local i18n = {
["errors"] = {
["property-param-not-provided"] = "Paramètreproperty propriétéparameter non renseigné.missing",
["qualifier-param-not-provided"] = "Paramètre qualifier nonparameter renseigné.missing",
["entity-not-found"] = "Entitéentity nonnot trouvée.found",
["unknown-claim-type"] = "typeunknown d'affirmationclaim inconnu.type",
["unknown-snak-typetypeg"] = "Type deunknown snak inconnu.type",
["unknown-datavalue-type"] = "Typeunknown dedatavalue donnée non reconnutype.",
["unknown-entity-type"] = "Typeunknown d'entitéentity non reconnu.type",
["invalid-id"] = "invalid ID"
["unknown-value-module"] = "You must set both value-module and value-function parameters.",
["value-module-not-found"] = "The module pointed by value-module not found.",
["value-function-not-found"] = "The function pointed by value-function not found.",
["ambigous"] = "Ambigu : plusieurs valeurs possibles",
},
["no-label"] = "pas de libellé",
['no description'] = "pas description",
["novalue"] = "not applicable",
["somevalue"] = "inconnu",
["trackingcat"] = 'Page utilisant des données de Wikidata'
["novalue"] = "pas applicable"
}
 
local function formatError( key )
return error(i18n.errors[key])
end
 
local function getEntityFromIdaddtrackingcat(prop, id cat)
if not prop and not cat then
return mw.wikibase.getEntityObject() --TODO support for getting other entities
return error("no property provided")
end
if not cat then
cat = i18n.trackingcat .. '/' .. string.upper(prop)
end
return '[[Category:' .. cat .. ']]'
end
 
function formatTheUnknown() -- voir si on peut accorder/adapter l'usage de "inconnu"
local function formatError( key )
return i18n.somevalue
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
 
local function samevalue(snak, target)
 
if snak.snaktype == 'value' and p.getRawvalue(snak) == target then
local function withtargetvalue(claims, targetvalue)
return true
targetvalue = string.upper(targetvalue)
local oldclaims = claims
local claims = {}
for i, statement in pairs(oldclaims) do
if p.getRawvalue(statement.mainsnak) == targetvalue then
table.insert(claims, statement)
end
end
return claims
end
 
local function validclaimsgetEntity(claims val )
if type(val) == 'table' then
local oldclaims = claims
return val
local claims = {}
for i, statement in pairs(oldclaims) do
if statement.rank == 'preferred' or statement.rank == 'normal' then
table.insert(claims, statement)
end
end
return mw.wikibase.getEntityObject(val)
return claims
end
 
local function formattable(statements, params) -- transform a table of claims into a table of formatted values
local function withrank(claims, rank)
for i, j in pairs(statements) do
if rank == 'best' then
j = p.formatStatement(j, params)
local preferred = withrank(claims, 'preferred')
end
if #preferred > 0 then
return preferredstatements
end
else
 
return withrank(claims, 'normal')
local function tableToText(values, params) -- takes a list of already formatted values and make them a text
end
if not values then
return nil
end
return linguistic.quickconj( values, params.conjtype)--linguistic.conj( values, params.lang, params.conjtype )
end
 
function p.getDate(statement)
--[[
return a "timedata" object as used by the date modules with the date of an item from the p580, p582 and p585 qualifiers
object format:
* timestamp 28 char string value for the timepoint, or if non the beginning or if none, the end (for easy sorting)
* timepoint: snak
* begin: snak
]]--
local q = statement.qualifiers
if not q or not (q.P585 or q.P580 or q.P582) then
return nil
end
if q.P585 and q.P585[1].snaktype == 'value' then -- P585: punctual date
return dates.dateobject(q.P585[1].datavalue.value)
if rank == 'valid' then
return validclaims(claims)
end
local begin, ending
 
local oldclaims = claims
if q.P582 and q.P582[1].snaktype == 'value' then
local claims = {}
ending = dates.dateobject(q.P582[1].datavalue.value)
for i, statement in pairs(oldclaims) do
if statement.rank == rank then
table.insert(claims, statement)
end
end
if q.P580 and q.P580[1].snaktype == 'value' then
return claims
begin = dates.dateobject(q.P580[1].datavalue.value)
end
return dates.daterange(begin, ending)
end
 
function p.getFormattedDate(statement, params)
local function withqualifier(claims, qualifier, qualifiervalue)
local datetable = p.getDate(statement)
qualifier, qualifiervalue = string.upper(qualifier), string.upper(qualifiervalue or '')
if not datetable then
return nil
local oldclaims = claims
end
return dates.objecttotext(datetable, params)
end
 
local function withtargetvalue(claims, targetvalue)
targetvalue = string.upper(targetvalue)
local oldclaims = claims
local claims = {}
for i, statement in pairs(oldclaims) do
if statement.qualifiers and if samevalue(statement.qualifiers[qualifier]mainsnak, targetvalue) then
table.insert(claims, statement)
if qualifiervalue then
end
for j, qualif in pairs(statement.qualifiers[qualifier]) do
end
if p.getRawvalue(qualif) == qualifiervalue then
return claims
table.insert(claims, statement)
end
end
else
table.insert(claims, statement)
end
end
end
return claims
end
 
local function validclaims(claims)
local oldclaims = claims
local claims = {}
for i, statement in pairs(oldclaims) do
if statement.rank == 'preferred' or statement.rank == 'normal' then
table.insert(claims, statement)
end
end
return claims
end
 
local function withrank(claims, rank)
if rank == 'best' then
local preferred = withrank(claims, 'preferred')
if #preferred > 0 then
return preferred
else
return withrank(claims, 'normal')
end
end
if rank == 'valid' then
return validclaims(claims)
end
local oldclaims = claims
local claims = {}
for i, statement in pairs(oldclaims) do
if statement.rank == rank then
table.insert(claims, statement)
end
end
return claims
end
 
local function withqualifier(claims, qualifier, qualifiervalue)
qualifier, qualifiervalue = string.upper(qualifier), string.upper(qualifiervalue or '')
local oldclaims = claims
local claims = {}
for i, statement in pairs(oldclaims) do
if statement.qualifiers and statement.qualifiers then
if qualifiervalue ~= '' then
for j, qualif in pairs(statement.qualifiers[qualifier]) do
if p.getRawvalue(qualif) == qualifiervalue then
table.insert(claims, statement)
end
end
else
table.insert(claims, statement)
end
end
end
return claims
end
local function withsource(claims, source, sourceproperty)
local oldclaims = claims
local claims = {}
source sourceproperty = string.upper(sourcesourceproperty or 'P248')
sourceproperty local sourcevalue = string.upper(sourcepropertysource or 'P248')
for i, statement in pairs(oldclaims) do
local success
for i, statement in pairs(oldclaims) do
if statement.references then
for j, reference in pairs(statement.references) do
if success then break end -- sp that it does not return twice the same reference when the property is used twice
for prop, content in pairs(reference.snaks) do
for prop, content in pairs(reference.snaks) do
if prop == sourceproperty then
if prop == sourceproperty then
for l, m in pairs(content) do
if p.getRawvalue(m)sourcevalue == source'' then
table.insert(claims, statement)
success = true
end
else
end
for l, m in pairs(content) do
end
if p.getRawvalue(m) == source then
end
table.insert(claims, statement)
success = true
end
end
end
end
end
end
end
end
return claims
end
 
local function isinlanguage(claims, lang) -- ne fonctionne que pour les monolingualtext / étendre aux autres types en utilisant les qualifiers ?
local newclaims = {}
for i, j in pairs(claims) do
if j.mainsnak.snaktype == 'value' and j.mainsnak.datavalue.type == 'monolingualtext' then
if j.mainsnak.datavalue.value.language == lang then
table.insert(newclaims,j)
end
end
end
return claimsnewclaims
end
 
local function excludespecial(claims)
local oldclaims = claims
local claims = {}
for i, statement in pairs(oldclaims) do
if statement.mainsnak.snaktype == 'value' then
table.insert(claims, statement)
end
end
return claims
end
 
local function comparedate(a, b) -- returns true if a is earlier than B or if a has a date but not b
if a and b then
return a.timestamp < b.timestamp
elseif a then
return true
end
return claims
end
 
local function firstvaluechronosort(claims, inverted)
table.sort(claims, function(a,b)
-- return just the first value (useful for images for instance)
local timeA = p.getDate(a)
-- returns in priority claims with rank = 'preferred', else with rank == 'normal' do not return claims with rank == 'deprecated'
local timeB = p.getDate(b)
for i, statement in pairs(claims) do -- choisit en priorité les données "preferred"
if inverted then
if statement.rank == 'preferred' then
return {statement}comparedate(timeB, timeA)
else
return comparedate(timeA, timeB)
end
end
for i, statement in pairs(claims) do
if statement.rank == 'normal' then
return {statement}
end
)
return claims
end
 
function p.sortclaims(claims, sorttype)
if sorttype == 'chronological' then
return chronosort(claims)
elseif sorttype == 'inverted' then
return chronosort(claims, true)
elseif type(sorttype) == 'function' then
table.sort(claims, sorttype)
return claims
end
return claims
end
 
local function numval(claims, numval)
local numval = tonumber(numval) or 0 -- raise a error if numval is not a positive integer ?
local newclaims = {}
for i, j in pairs(claims) do
if #newclaims == numval then
return newclaims
end
table.insert(newclaims,j)
end
return newclaims
end
 
function p.getRawvalue(snak)
return p.getDatavalue(snak, {format = 'raw'})
end
 
function p.getDatavalue(snak, formattingparams)
if snak.snaktypenot ~= 'value'params then
params = {}
return nil
end
local formatting = params.formatting
if snak.snaktype ~= 'value' then
local datatype = snak.datavalue.type
return nil
local value = snak.datavalue.value
end
if datatype == 'wikibase-entityid' then
local datatype = snak.datavalue.type
if formatting == 'raw' then
local value = snak.datavalue.value
return "Q" .. tostring(value['numeric-id'])
local displayformat = params.format
else
if datatype == 'wikibase-entityid' then
return p.formatEntityId("Q" .. tostring(value['numeric-id']), formatting)
if displayformat == 'raw' then
end
return "Q" .. tostring(value['numeric-id'])
else
elseif datatype == 'string' then
return p.formatEntity('Q' .. value['numeric-id'], params)
if formatting == 'weblink' then
end
local link = require ('Module:Weblink')
return link.makelink(value)
elseif datatype == 'string' then
else
if params.displayformat == 'weblink' then
return value
return require('Module:Weblink').makelink(value)
end
end
return value
 
elseif datatype == 'time' then -- format example: +00000001809-02-12T00:00:00Z
local precision = params.precision -- degré de précision à afficher ('day', 'month', 'year'), inférieur ou égal à value.precision
if formatting == 'raw' then
return value.time
else
return dates.objecttotext(dates.dateobject(value))
local wdate = require('Module:Wikidata/Dates')
return wdate.objecttotext(wdate.dateobject(value))
end
 
Ligne 194 ⟶ 319 :
return value -- note : les coordonnées Wikidata peuvent être utilisée depuis Module:Coordinates. Faut-il aussi autoriser à appeler Module:Coordiantes ici ?
end
 
elseif datatype == 'urlquantity' then
if displayformat == 'raw' then
return value.url
return value.amount
 
else
elseif datatype == 'quantity' then
return local str = string.sub(value.amount,2) --
return str
 
end
else
elseif datatype == 'monolingualtext' then
return formatError( 'unknown-datavalue-type' )
return langmodule.langue({value.language, value.text})
end
else
return formatError('unknown-datavalue-type' )
end
end
 
local function getMultipleClaims(args)
local newargs = args
local claims = {}
for i, j in pairs(args.property) do
newargs.property = j
local newclaims = p.getClaims(args)
for k, l in pairs(newclaims) do
table.insert(claims, l)
end
end
return claims
end
function p.getClaims( args ) -- returns a table of the claims matching some conditions given in args
if not args.property then
return formatError( 'property-param-not-provided' )
end
if type(args.property) == 'table' then
return getMultipleClaims(args)
end
--Get entity
localif args.item then args.entity = nilargs.item end -- synonyms
local propertyentity = string.upper(args.property)entity
if args.entity and type( args.entity ) =~= "'table"' then
entity = getEntity( args.entity )
elseend
if (not entity) =or getEntityFromId(not argsentity.entityIdclaims) then )
return nil
end
local property = string.upper(args.property)
local claims = entity.claims[property]
if not claims then return nil end
-- mettre ~= '' pour le cas ou le paramètre est écrit mais laissé blanc ({{#invoke:formatStatements|property=pXX|targetvalue = xx}})
if args.targetvalue and args.targetvalue ~= '' then
claims = withtargetvalue(claims, args.targetvalue)
end
 
if args.qualifier and args.qualifier ~= '' then
if not entity or not entity.claims or not entity.claims[property] then
claims = withqualifier(claims, args.qualifier, args.qualifiervalue)
end
if (args.source and args.source ~= '') or (args.sourceproperty and args.sourceproperty ~= '') then
claims = withsource(claims, args.source, args.sourceproperty)
end
if (args.isinlanguage and args.isinlanguage ~= '') then
claims = isinlanguage(claims, args.inlanguage)
end
if args.excludespecial and args.excludespecial ~= '' then
claims = excludespecial(claims)
end
 
if args.rank ~= 'all' then
if not args.rank or args.rank == '' then
args.rank = 'best'
end
claims = withrank(claims, args.rank)
end
if args.sorttype then
claims = p.sortclaims(claims, args.sorttype)
end
if args.numval and args.numval ~= '' then --keep at the end, after other filters have been implmented
claims = numval(claims, args.numval)
end
if #claims > 0 then
return claims
end
end
 
function p.formatClaimList(claims, args)
if not claims then
return nil
end
claimsfor =i, entity.j in pairs(claims[property]) do
claims[i] = p.formatStatement(j, args)
-- mettre ~= '' pour le cas ou le paramètre est écrit mais laissé blanc ({{#invoke:formatStatements|property=pXX|targetvalue = xx}})
end
return claims
if args.targetvalue and args.targetvalue ~= '' then
end
claims = withtargetvalue(claims, args.targetvalue)
 
function p.stringTable(args) -- like getClaims, but get a list of string rather than a list of snaks, for easier manipulation
local claims = p.getClaims(args)
return p.formatClaimList(claims, args)
end
 
 
local function getQualifiers(statement, qualifs, params)
if not statement.qualifiers then
return nil
end
local vals = {}
for i, j in pairs(qualifs) do
if statement.qualifiers[j] then
for k, l in pairs(statement.qualifiers[j]) do
table.insert(vals, l)
end
end
end
if #vals == 0 then
return nil
end
return vals
end
 
function p.getFormattedQualifiers(statement, qualifs, params)
if args.qualifier and args.qualifier ~= '' then
if not params then params = {} end
claims = withqualifier(claims, args.qualifier, args.qualifiervalue)
local qualiftable = getQualifiers(statement, qualifs)
if not qualiftable then
return nil
end
for i, j in pairs(qualiftable) do
if args.source and args.source ~= '' then
qualiftable[i] = p.formatSnak(j, params)
claims = withsource(claims, args.source, args.sourceproperty)
end
return linguistic.conj(qualiftable, params)
end
if args.excludespecial == 'true' and args.excludespecial ~= '' then
 
claims = excludespecial(claims)
function p.formatStatement( statement, args )
if not statement.type or statement.type ~= 'statement' then
return formatError( 'unknown-claim-type' )
end
local str = p.formatSnak( statement.mainsnak, args )
if args.showqualifiers then
local qualifs = args.showqualifiers
if type(qualifs) == 'string' then
qualifs = mw.text.split(qualifs, ',')
end
local foundvalues = p.getFormattedQualifiers(statement, qualifs, args)
if foundvalues then
str = str .. linguistic.inparentheses(foundvalues, lang)
end
end
if args.showdate then -- when "withdate and chronosort are both set, date retrieval is performed twice
local timedata = p.getDate(statement)
if timedata then
local formatteddate = dates.objecttotext(timedata, args)
formattteddate = linguistic.inparentheses(formatteddate, lang)
str = str .. '<small>' .. formattteddate ..'</small>'
end
end
 
if args.showsource and statement.references then --[[needs abritrary access
if args.rank ~= 'all' then -- à laisser vers la fin, quan les élimination sont faites
local sourcestring = ''
if not args.rank or args.rank == '' then
for i, ref in pairs(statement.references) do
args.rank = 'best'
if ref.snaks.P248 then
for j, source in pairs(ref.snaks.P248) do
if source.snaktype == 'value' then
local page
if ref.snaks.P304 and ref.snaks.P304[1].snaktype == 'value' then
page = ref.snaks.P304[1].datavalue.value
end
local s = require('Module:Cite/sandbox').citeitem('Q' .. source.datavalue.value['numeric-id'], lang, page)
s = mw.getCurrentFrame():extensionTag( 'ref', s )
sourcestring = sourcestring .. s
end
end
elseif ref.snaks.P854 and ref.snaks.P854[1].snaktype == 'value' then
s = mw.getCurrentFrame():extensionTag( 'ref', formatLink(ref.snaks.P854[1].datavalue.value))
sourcestring = sourcestring .. s
end
end
str = str .. sourcestring ]]--
end
return str
end
 
function p.formatSnak( snak, params )
if not args then args = {} end -- pour faciliter l'appel depuis d'autres modules
if snak.snaktype == 'somevalue' then
return formatTheUnknown()
elseif snak.snaktype == 'novalue' then
return i18n['novalue'] --todo
elseif snak.snaktype == 'value' then
return p.getDatavalue( snak, params)
else
return formatError( 'unknown-snak-type' )
end
end
 
function p._getLabel(entity, default, inlanguage)
local label
if not entity then
return nil
end
if inlanguage then -- cherche dans l'élément complet s'il est déjà chargé, ou s'il faut une libellé non-français, inacessible par mw.wikibase.label
entity = getEntity(entity)
end
if type(entity) == 'table' then
if entity and entity.labels and entity.labels[lang] then
label = entity.labels[lang].value
end
else
claims = withrank(claims, args.rank)
label = mw.wikibase.label(entity)
end
if label then
return label
end
if default == 'nolabel' then
if args.first == 'true' and args.first ~= '' then -- retourne une seule valeur
return i18n['no-label']
claims = firstvalue(claims)
end
return entity.id
end
 
function p._getDescription(entity, lang)
if type(entity) ~= 'table' then
entity = getEntity(entity)
end
if not entity.descriptions then
return claims
return i18n['no description']
end
local descriptions = entity.descriptions
if not descriptions then
return nil
end
if descriptions[lang] then
return descriptions[lang].value
end
local fblist = require('Module:Fallback').fblist(lang) -- list of fallback languages in no label in the desired language
for i, j in pairs (mw.language.getFallbacksFor(lang)) do
if descriptions.lang then
return descriptions[lang].value
end
end
if default == 'nolabel' then
return i18n['no-label']
end
return entity.id
end
 
local function p.numOfClaimsformattedLabel(framelabel, entity, args)
if args.link== '-' then
local claims = p.getClaims(frame.args)
return label
if claims then
return #claims
else
return 0
end
local link = mw.wikibase.sitelink( entity )
if not link then
link = 'd:' .. entity
end
return '[[' .. link .. '|' .. label .. ']]'
end
 
 
function p._getQualifier(args)
function p.getmainid(claim)
claims = p.getClaims( args )
if claim and claim.mainsnak.snaktype == 'value' then
if args.qualifier then
return 'Q' .. claim.mainsnak.datavalue.value['numeric-id']
qualifier = args.qualifier
else
return formatError( 'qualifier-param-not-provided' )
end
if not claims or #claims == 0 then
return nil
else
result = {}
for i, j in pairs(claims) do
for k, l in pairs( j.qualifiers[qualifier] ) do
table.insert(result, p.getDatavalue(l, 'standard'))
end
end
end
return mw.text.listToText(result)
end
 
function p.getQualifierformatEntity( frameentity, args )
local label = p._getLabel(entity, lang)
return p._getQualifier(frame.args)
if not label then
label = entity
end
return formattedLabel(label, entity, args)
end
 
 
function p.getLabel(frame) -- simple for simple templates like {{Q|}}}
local args = frame.args
local entity = args.entity
local lang = lang
if args.lang and args.lang ~= '' then
lang = args.lang
end
if string.sub(entity, 1, 10) == 'Property:P' then
entity = string.sub(entity, 10)
elseif (string.sub(entity, 1, 1) ~= 'P' and string.sub(entity, 1, 1) ~= 'Q') or (not tonumber(string.sub(entity, 2))) then
return i18n.errors['invalid-id']
end
if not args.link or args.link == '' then -- by default: no link
args.link = '-'
end
if args.link == '-' then
return p._getLabel(entity, lang) or i18n.errors['invalid-id']
else
lang = lang
return p.formatEntity(entity, args)
end
end
 
function p._formatStatements( args )--Format statement and concat them cleanly
if args.item == '-' then
--If a value is set to '-', ignore the query
if args.value == '-' then
return nil
end
local valuetable = p.stringTable(args)
--If a value is already set, use it
return tableToText(valuetable, args)
if args.value and args.value ~= '' then
end
return args.value
 
function p._formatAndCat(args)
local val = p._formatStatements( args )
if val then
return val .. addtrackingcat(args.property)
end
end
local rawStatements = p.getClaims( args )
 
local formattedStatements = {}
function p.getTheDate(args)
if not rawStatements or #rawStatements == 0 then
local claims = p.getClaims(args)
if args.returntype == 'table' then return {} end
if not claims then
return nil
end
local formattedvalues = {}
for i, statement in pairs( rawStatements ) do
for i, j in pairs(claims) do
table.insert( formattedStatements, formatStatement( statement, args ))
table.insert(formattedvalues, p.getFormattedDate(j))
end
end
if args.returntype == 'table' then -- pour certaines modules, il vaut mieux récupérer les données sous forme de table
return linguistic.conj(formattedvalues)
return formattedStatements
end
---FONCTIONS depuis le FRAME
return mw.text.listToText( formattedStatements, args.separator, args.conjunction )
function p.getaDate(frame)
-- .. '[[Category:Page utilisant des données de Wikidata/' .. string.upper(args.property) .. ']]'
return p.getTheDate(frame.args)
end
 
 
function p.formatStatements( frame )
function p.getQualifier( frame )
local args = {}
local claims = p.getClaims(frame.args)
if frame == mw.getCurrentFrame() then
local str = ''
args = frame:getParent().args -- paramètres du modèle appelant (est-ce vraiment une bonne idée ?)
for local k,qualifs v= inframe.args.qualifiers or pairs(frame.args).qualifier do
if not qualifs then
args[k] = v
return formatError( 'property-param-not-provided' )
end
else
args = frame
end
qualifs = mw.text.split(qualifs, ',')
return p._formatStatements( args )
for i, j in pairs(claims) do
local new = p.getFormattedQualifiers(j, qualifs) or ''
str = str .. new
end
return str
end
 
function p.getDescription(frame) -- simple for simple templates like {{Q|}}}
function formatStatement( statement, args )
local entity = frame.args.entity
if not statement.type or statement.type ~= 'statement' then
if frame.args.lang then
return formatError( 'unknown-claim-type' )
lang = frame.args.lang
end
if (string.sub(entity, 1, 1) ~= 'P' and string.sub(entity, 1, 1) ~= 'Q') or (not tonumber(string.sub(entity, 2))) then
 
return i18n.errors['invalid-id']
mainsnak = p.formatSnak( statement.mainsnak, args )
if args.showqualifiers then -- to be improved
qualifier = args.showqualifiers
if statement.qualifiers and statement.qualifiers[qualifier] then
qualifvalues = {}
for i, j in pairs (statement.qualifiers[qualifier]) do
table.insert(qualifvalues, p.getDatavalue(j))
end
return mainsnak .. ' (' .. mw.text.listToText(qualifvalues) .. ')'
end
end
return p._getDescription(entity, lang) or i18n.errors['invalid-id']
return mainsnak
end
 
function p.formatSnaknumOfClaims( snak, args frame)
local claims = p.getClaims(frame.args)
if not args then args = {} end -- pour faciliter l'appel depuis d'autres modules
if claims then
if snak.snaktype == 'somevalue' then
return i18n['somevalue']#claims
else
elseif snak.snaktype == 'novalue' then
return i18n['novalue']0
elseif snak.snaktype == 'value' then
return p.getDatavalue( snak, args.formatting)
else
return formatError( 'unknown-snak-type' )
end
end
 
function p.formatEntityIdformatStatements( entityId, formattingframe )
local labelargs = mw.wikibase.label( entityId ){}
if frame == if not labelmw.getCurrentFrame() then
args = frame:getParent().args -- paramètres du modèle appelant (est-ce vraiment une bonne idée ?)
label = entityId --TODO what if no links and label + fallback language?
for k, v in pairs(frame.args) do
end
args[k] = v
if formatting == 'nolink' then
end
return label
else
args = frame
local link = mw.wikibase.sitelink( entityId )
if link then
return '[[' .. link .. '|' .. label .. ']]'
else
return '[[wikidata:' .. entityId .. '|' .. label .. ']]'
end
end
return p._formatStatements( args )
end