Modifications

Sauter à la navigation Sauter à la recherche
3 420 octets ajoutés ,  13 mai 2020 à 16:23
aucun résumé de modification
if type(entity) == 'string' then
return entity
elseif type(entity) == 'table' then
return entity.id
end
return entity.id
end
-- of the item that is linked to the calling page
function wd.isPageOfQId(qid)
local entity_on_its_page = false local self_entity self_id = mw.wikibase.getEntitygetEntityIdForCurrentPage() if self_entity return self_id ~= nil and qid == wd.entityId(self_entity) then entity_on_its_page = true end return entity_on_its_pageself_id
end
end
function wd.splitStr(val) -- transforme en table les chaînes venant du Wikitexte qui utilisent des virgules de séparatinséparation
if type(val) == 'string' then
val = mw.text.split(val, ",")
}
local entityid = entity = wd.getEntity(entity) if not id or entity then return nil end
local projectdata = projects[project:lower()]
linkcode = lang .. linkcode
end
local link = entity:mw.wikibase.getSitelink(entityid, linkcode)
if not link then
return nil
local function notSpecial(claim)
local snack type if claim.mainsnak ~= nil then type = claim.mainsnak or snack.snaktype return snackelse -- condition respectée quand showonlyqualifier est un paramètre renseigné -- dans ce cas, claim n'est pas une déclaration entière, mais UNE snak qualifiée du main snak type = claim.snaktype end return type == 'value'
end
end
local function hasSourcewd.hasQualifierNumber(claim, targetsourceacceptedqualifs, acceptedvals, sourcepropertyexcludequalifiervalues) sourceproperty local claimqualifs = sourceproperty or 'P248' if targetsource == "-" then return true end if (not claim.references) then return falsequalifiers end local candidates = claim.references[1].snaks[sourceproperty] -- les snaks utilisant la propriété demandée if (not candidatesclaimqualifs) then
return false
end
  acceptedqualifs = wd.splitStr(acceptedqualifs) acceptedvals = wd.splitStr( acceptedvals)   local function ok(qualif) -- vérification pour un qualificatif individuel if not claimqualifs[qualif] then return false end if not (targetsource == "any"acceptedvals) then -- si aucune valeur spécifique n'importe quelle valeur est acceptée tant qu'elle utilise en ref la propriété demandée, OK return true end for i, wanted in pairs(acceptedvals) do for j, actual in pairs(claimqualifs[qualif]) do if mw.wikibase.renderSnak(actual) == wanted then return true end end end
end
targetsource = wd.splitStr(targetsource) for _i, source qualif in pairs(candidatesacceptedqualifs) do local s = wd.getIdif ok(sourcequalif) for i, target in pairs(targetsource) dothen if s == target then return true end
end
end
end
local function excludeQualifierhasSource(claim, qualifiertargetsource, qualifiervaluessourceproperty) sourceproperty = sourceproperty or 'P248' if targetsource == "-" then return not wd.hasQualifier(claim, qualifier, qualifiervalues)true end local function hasDate if (not claim.references)then return false end local claimqualifs candidates = claimsclaim.qualifiersreferences[1].snaks[sourceproperty] -- les snaks utilisant la propriété demandée if (not claimqualifs candidates) then
return false
end
if (targetsource == "any") then -- si n'importe quelle valeur est acceptée tant qu'elle utilise en ref la propriété demandée return true end targetsource = wd.splitStr(targetsource) for _, qualif source in pairs(claimqualifscandidates) do local s = wd.getId(source) for i, target in pairs(targetsource) do if claimsqualifs[qualif] and claimsqualifs[qualif][1].snaktype s == 'value' target then return trueend
end
end
end
local function excludeQualifier(claim, qualifier, qualifiervalues) return not wd.hasQualifier(claim, qualifier, qualifiervalues)end function wd.hasDate(claim) if not claim then return false --error() ? end if wd.getDateFromQualif(claim, 'P585') or wd.getDateFromQualif(claim, 'P580') or wd.getDateFromQualif(claim, 'P582') then return true end return falseend local function hasLink(claim, site, lang) if (claim.mainsnak.snaktype ~= 'value') then -- ne pas supprimer les valeurs spéciales, il y a une fonction dédiée pour ça
return true
end
while (#claims > numval) do
table.remove(claims)
end
return claims
end
 
local function lastVals(claims, numval2) -- retourn les valeurs de la table claims à partir de numval2
local numval2 = tonumber(numval2) or 0 -- raise a error if numval is not a positive integer ?
if not claims then
return nil
end
for i=1,numval2 do
table.remove(claims, 1)
end
return claims
end
local function atDate(claim, mydate, precision)
if mydate == "today" then
mydate = os.date("!%Y-%m-%dT%TZ")
end -- with point in time local newclaims d = timeFromQualifs(claim, {'P585'})  if d then return modules.formatDate.equal(mydate, d, precision) end -- with start or end date
local mindate = timeFromQualifs(claim, {'P580'})
local maxdate = timeFromQualifs(claim, {'P582'})
return true
end
return false
end
table.sort(claims, sorttype)
return claims
elseif type(sorttype) == 'string' and sorttype:sub(1, 1) == 'P' then
return wd.numericPropertySort(claims, sorttype)
end
return claims
filter('atdate', atDate, {'atdate'} )
filter('qualifier', wd.hasQualifier, {'qualifier', 'qualifiervalue'} )
filter('qualifiernumber', wd.hasQualifierNumber, {'qualifiernumber', 'qualifiernumbervalue'} )
filter('excludequalifier', excludeQualifier, {'excludequalifier', 'excludequalifiervalue'} )
filter('withsource', hasSource, {'withsource', 'sourceproperty'} )
filter('withdate', wd.hasDate, {} )
filter('excludevalues', excludeValues, {'excludevalues'})
filter('withlink', hasLink, {'withlink', 'linklang'} )
if #claims == 0 then
return nil
end
if args.numval2 then
claims = lastVals(claims, args.numval2)
end
if args.numval then
function wd.getLabel(entity, lang, labelformat)
if (not entity) then
return nil -- ou option de gestion des erreurs ?
return labelformat(entity)
end
entity = entity.id or ( type(entity) == "string" and entity)
if (type(entity) == 'string') and (lang == defaultlang) then -- le plus économique
return str
end
end
 
if type(entity) == 'string' then
entity = mw.wikibase.getEntity(entity)
end
if entity and entityreturn mw.labels and entitywikibase.labels[lang] then return getLabelByLang(entity.labels[, lang].value, true end)
end
local link, label
local str = '' -- l'intégralité du text à retourner
label = wd.getLabel(entity, lang, labelformat)
end
link = wd.siteLink(id, 'wikidata')
return str .. '[[' .. link .. '|' .. id .. ']]' .. addCat(modules.i18n['to translate'])
-- si pas de libellé, on met un lien vers Wikidata pour qu'on comprenne à quoi ça fait référence
end
if (linktype == '-') or rendering_entity_on_its_page then
return str .. label
end
if link then
return str .. '[[' .. link .. '|' .. label .. ']]'
end
end
local val = '[[' .. sidelink .. '|' .. '<span class = "' .. (class or '').. '" title = "' .. (title or '') .. '">' .. icon .. '</span>]]'
return str .. label .. '<small>&nbsp;(' .. val .. ')</small>'
end
return str .. label
end
end
local function wd.getDateFromQualif(statement, qualif)
if (not statement) or (not statement.qualifiers) or not (statement.qualifiers[qualif]) then
return nil
function wd.getDate(statement)
local period = wd.getDateFromQualif(statement, 'P585') -- retourne un dateobject
if period then
return period
end
local begin, ending = wd.getDateFromQualif(statement, 'P580'), wd.getDateFromQualif(statement, 'P582')
if begin or ending then
return rangeObject(begin, ending) -- retourne un rangeobject fait de deux dateobject
end
return nil
end
-- puis limite intérieur / supérieur
if not str then
local start, ending = wd.getDateFromQualif(statement, 'P1319'), wd.getDateFromQualif(statement, 'P1326')
str = modules.formatDate.between(start, ending, params)
end
-- sinon, le mainsnak, pour les données de type time
if (not str) and (statement.mainsnak.datatype == 'time') then
local mainsnak = statement.mainsnak
end
-- Fonction qui trie des Claims de type value selon l'ordre de la propriété fournit
-- Une clé de tri nomée « dateSortKey » est ajouté à chaque claim.
-- Si des clés de tri de ce nom existent déjà, elles sont utilisées sans modification.
function wd.numericPropertySort( claims, propertySort )
for _, claim in ipairs( claims ) do
if not claim.dateSortKey then
local val
local claimqualifs = claim.qualifiers
if claimqualifs then
local vals = claimqualifs[propertySort]
if vals and vals[1].snaktype == 'value' then
val = vals[1].datavalue.value
end
end
claim.dateSortKey = tonumber(val or 0)
end
end
table.sort(
claims,
function ( c1, c2 )
return c1.dateSortKey < c2.dateSortKey
end
)
return claims
end
-- ===================
local refs = {}
local hashes = {}
for i, ref in pairs(refdata) do
local s
end
if ref.snaks.P248 then-- cas lorsque P248 (affirmé dans) est utilisé
for j, source in pairs(ref.snaks.P248) do
if source.snaktype == 'value' then
local page, accessdate, quotation if hasValue('P304') then-- page
page = wd.formatSnak(ref.snaks.P304[1])
end
if hasValue('P813') then-- date de consultation
accessdate = wd.formatSnak(ref.snaks.P813[1])
end
s if hasValue('P1683') then -- citation quotation = moduleswd.formatSnak(ref.referencesnaks.citeitem(P1683[1]) end local sourceId = wd.getId(source) s = modules.reference.citeitem(sourceId, {['page'] = page, ['accessdate'] = accessdate, ['citation'] = quotation})
table.insert(refs, s)
table.insert(hashes, ref.hash .. sourceId)
end
end
elseif hasValue('P854') then -- cas lorsque P854: reference url(URL de la référence) est utilisé local url, title, author, publisher, accessdate, publishdate, publishlang, quotation
url = wd.formatSnak(ref.snaks.P854[1], {text = "-"})
--todo : handle multiple values for author, etc.
if hasValue('P813') then-- date de consultation
accessdate = wd.formatSnak(ref.snaks.P813[1])
end
author = wd.formatSnak(ref.snaks.P2093[1])
end
if hasValue('P123') then-- éditeur
publisher = wd.formatSnak(ref.snaks.P123[1])
end
if hasValue('P1683') then -- citation quotation = wd.formatSnak(ref.snaks.P1683[1]) end if hasValue('P577') then -- date de publication publishdate avec = wd.formatSnak(ref.snaks.P577 ? (ne semble pas vraiment correspondre[1]) end if hasValue('P407') then-- langue de l'œuvre
local id = wd.getId(ref.snaks.P407[1])
publishlang = getLangCode(id)
end
s = modules.cite.lienWeb{titre = title, url = url, auteur = author, editeur = publisher, langue = publishlang, ['en ligne le'] = publishdate, ['consulté le'] = accessdate, ['citation'] = quotation} table.insert(hashes, ref.hash)
table.insert(refs, s)
elseif ref.snaks.P854 and ref.snaks.P854[1].snaktype == 'value' then
s = wd.formatSnak(ref.snaks.P854[1], {text = "-"})
table.insert(hashes, ref.snaks.P854[1].hash)
table.insert(refs, s)
end
end
if #refs > 0 then
if #hashes == #refs then
return refs, hashes
end
return refs
end
end
function wd.sourceStr(sources, hashes)
if not sources or (#sources == 0) then
return nil
end
local useHashes = hashes and #hashes == #sources for i, j in pairsipairs(sources) do local refArgs = {name = 'ref', content = j} if useHashes and hashes[i] ~= '-' then refArgs.args = {name = 'wikidata-' .. hashes[i]} end sources[i] = mw.getCurrentFrame():extensionTag( "ref", jrefArgs)
end
return table.concat(sources, '<sup class="reference cite_virgule">,</sup>')
end
if datatype == 'quantity' then -- todo : gérer les paramètre paramètres précision
local amount, unit = value.amount, value.unit
end
if not claims or claims == {} then
return nil{}, {}
end
local props = {} -- liste des propriétés associété à chaque string pour catégorisation et linkback
qualifargs.labelformat = args.qualiflabelformat or args.labelformat
qualifargs.link = args.qualiflink or args.link
qualifargs.linktopic = args.qualiflinktopic or args.linktopic
qualifargs.conjtype = args.qualifconjtype
qualifargs.defaultlink = args.qualifdefaultlink or args.defaultlink
local formattedqualifs = wd.getFormattedQualifiers(statement, qualifs, qualifargs)
if formattedqualifs and str formattedqualifs ~= "" then str = str .. modules" (" .linguistic.inparentheses(formattedqualifs, defaultlang.. ")"
end
return str
str = wd.addStandardQualifs(str, statement)
end
end
if args.showdate then -- when "showdate and chronosort are both set, date retrieval is performed twice
local period = wd.getFormattedDate(statement, args, "-") -- 3 arguments indicate the we should not use additional qualifiers, alrady added by wd.formatStatement if period then str = str .. " <small>(" .. period ..")</small>" end
end
if args.showsource then
local sources , hashes = wd.getReferences(statement)
if sources then
local source = wd.sourceStr(sources, hashes) if source then str = str .. (source or "") end
end
end
function wd.addLinkBack(str, id, property)
if not id then
id = wd.getEntitygetEntityIdForCurrentPage()
end
if not id then
if type(property) == 'table' then
property = property[1]
end
if type(id) == 'table' then
id = id.id
end
id = wd.entityId(id)
 
local class = ''
if property then
:tag('span')
:addClass('noprint wikidata-linkback')
:css('padding-left', '0.5em')
:wikitext(icon:format(title, url))
:allDone()
end
local qualifstr = modules.linguistic.conj(qualifs, "qualif-separator")
if not qualifstr and qualifstr ~= "" then return str= str .. " (" .. qualifstr .. ")"
end
return str .. " " .. modules.linguistic.inparentheses(qualifstr)
end
},
end
local datestr = modules.linguistic.conj(dates)
if not datestr and datestr ~= "" then return str= str .. " <small>(" .. datestr .. ")</small>"
end
return str .. "<small>" .. modules.linguistic.inparentheses(datestr) .. "</small>"
end
},
-- si deux affirmations ont la même source, on ne l'affiche qu'une fois
local sources = {}
local hashes = {}
local function dupeRef(old, new)
end
for i, claim in pairs(claims) do
local refs , refHashes = wd.getReferences(claim)
if refs then
for i, j in pairs(refs) do
if not dupeRef(sources, j) then
table.insert(sources, j)
local hash = (refHashes and refHashes[i]) or '-'
table.insert(hashes, hash)
end
end end end return str .. (wd.sourceStr(sources, hashes) or "") end } }  for i, group in pairs(groupedClaims) do -- bricolage pour utiliser les arguments de formatStatements local str = wd.formatEntity(group.id, args) for i, fun in pairs(funs) do if args[fun.param] then str = fun.fun(str, group.claims, args) end end table.insert(stringTable, str) end args.valuetable = stringTable return wd.formatStatements(args)end  function wd.formatStatements( args )--Format statement and concat them cleanly if args.value == '-' then return nil end
for i-- If a value is already set: use it, group in pairsexcept if it's the special value {{WD}} (groupedClaimsuse wikidata) do -- bricolage pour utiliser les arguments de formatStatements if args.value and args.value ~= '' then local str valueexpl = wd.formatEntitytranslate(group.id, args"activate-query") for i, fun in pairs(funs) do if args[fun.param] value ~= valueexpl then str = fun return args.fun(str, group.claims, args) endvalue
end
table.insert(stringTable, str) end args.valuetable = stringTable return wd.formatStatements(args)end  function wd.formatStatements( args )--Format statement and concat them cleanly if args.value == '-' then return nil end local valueexpl = wd.translate("activate-query") --If a There is no value is already set, use it if args.value and (args.value ~= '') and (args.value ~= valueexpl) then return args.value end -- if args.expl: return something only one if explicitly required in Wikitextdisables wikidata on empty values if elseif args.expl and (args.value ~= valueexpl) then
return nil
end
args.entity = wd.getEntity(args.entity)
if args.grouped and args.grouped ~= '' then
local str = modules.linguistic.conj(valuetable, args.conjtype)
if not str then
return nilargs.default
end
if not props then
end
elseif type(event) ~= 'string' then
return formatError('invalid-datatype', type(event), 'string')
elseif string.sub(event, 1, 1) == 'Q' then -- on demande un élément utilisé dans P:P793 (événement clé)
params.property = 'P793'

Menu de navigation