Module:ArchivéPar
Utilisation
Ce module est conçu pour une utilisation à travers le modèle Modèle:ArchivéPar. Il fournit une fonction servant à l'affichage du contenu de la propriété P485 de wikidata pour une entité donnée.
Fonctions exportables
main(frame)
– Prend en argument un frame contenant les paramètres :
id
(alias acceptés :entity
,wikidata
) de l'entité wikidata (par défaut la page courante) ;showsource
Booléen indiquant si les références doivent être indiquées ou non ;compact
Booléen indiquant si un affichage compact est désiré ou non ;expand
Booléen indiquant si un affichage étendu est désiré ou non (incompatible aveccompact
).
Et retourne le contenu de la propriété P485 de wikidata mis en forme.
Modules externes et autres éléments dont ce module a besoin pour fonctionner
mw.html.create
– Crée un nouvel objet mw.html, équivalent d'un élément HTML ;
Module:Biblio
– Module implémentant les modèles de documentation {{Ouvrage}}, {{Lien web}}, etc. ;Module:Outils
– Module contenant diverses fonctions courantes, ici utilisé pour extraire les arguments d'un frame ;Module:Wikidata
– Module contenant des fonctions de récupération des données issues de Wikidata ;Module:Yesno
– Module permettant le traitement des chaînes de caractères « oui » et « non » comme des booléens.
Modules lua utilisant ce module
Aucun
Modèles appelant directement ce module
Exemples
Dans Modèle:ArchivéPar, ce module est appelé par le code suivant :
* {{#invoke:ArchivéPar|main}}
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}
local Outils = require 'Module:Outils'
local wikidata = require 'Module:Wikidata'
local reference = require 'Module:Wikidata/Références'
local cite = require 'Module:Biblio'
local title = "'''Archives conservées par'''"
local function getReferences(statement, args)
local refdata = statement.references
local cats = ''
if not refdata then
return nil
end
local expand = args and args.expand and args.expand ~= '-' and #refdata > 1
local refs = {}
local hashes = {}
for i, ref in pairs(refdata) do
local s
local function hasValue(prop) -- checks that the prop is here with valid value
if ref.snaks[prop] and ref.snaks[prop][1].snaktype == 'value' then
return true
end
return false
end
if hasValue('P8091') or hasValue('P854') then -- cas lorsque P8091 (Archival Resource Key) ou P854 (URL de la référence)est utilisé
local arkKey, url, author, publisher, accessdate, publishdate, publishlang, quotation
local description = ''
local title = 'consulter'
if hasValue('P8091') then
arkKey = wikidata.formatSnak(ref.snaks.P8091[1], {text = "-"})
url = 'https://n2t.net/' .. arkKey
if hasValue('P1476') then -- si un titre est présent
title = wikidata.formatSnak(ref.snaks.P1476[1])
end
elseif hasValue('P854') then
url = wikidata.formatSnak(ref.snaks.P854[1], {text = "-"})
if hasValue('P1476') then -- si un titre est présent
title = wikidata.formatSnak(ref.snaks.P1476[1])
end
end
if expand then
if hasValue('P1810') then -- sous le nom
if description ~= '' then description = description .. ', ' end
description = 'sous le nom ' .. wikidata.formatSnak(ref.snaks.P1810[1])
end
if hasValue('P813') then -- date de consultation
accessdate = wikidata.formatSnak(ref.snaks.P813[1])
end
if hasValue('P217') then -- date de consultation
if description ~= '' then description = description .. ', ' end
description = description .. wikidata.formatSnak(ref.snaks.P217[1])
end
if hasValue('P50') then -- author (item type)
author = wikidata.formatSnak(ref.snaks.P50[1])
elseif hasValue('P2093') then -- author (string type)
author = wikidata.formatSnak(ref.snaks.P2093[1])
end
if hasValue('P123') then -- éditeur
publisher = wikidata.formatSnak(ref.snaks.P123[1])
end
if hasValue('P577') then -- date de publication
publishdate = wikidata.formatSnak(ref.snaks.P577[1])
end
if hasValue('P1683') then -- citation
quotation = wikidata.formatSnak(ref.snaks.P1683[1])
end
if hasValue('P407') then -- langue de l'œuvre
local id = wikidata.getId(ref.snaks.P407[1])
publishlang = getLangCode(id)
end
s = cite.lienWeb{titre = title, url = url, auteur = author, editeur = publisher, langue = publishlang, ['en ligne le'] = publishdate, ['consulté le'] = accessdate, ['citation'] = quotation, ['description'] = description}
if title == 'consulter' and description == '' and not accessdate then
cats = cats .. '[[Catégorie:Page ayant une référence sans titre depuis wikidata]]'
end
else
if title == 'consulter' and hasValue('P217') then -- date de consultation
title = wikidata.formatSnak(ref.snaks.P217[1])
end
if hasValue('P1810') then -- sous le nom
description = description .. 'sous le nom ' .. wikidata.formatSnak(ref.snaks.P1810[1])
end
s = '[' .. url .. ' ' .. title .. ']'
if description and description ~= '' then
s = s .. ' ' .. description
end
if title == 'consulter' and description == '' then
-- cats = cats .. '[[Catégorie:Page ayant une référence sans titre depuis wikidata]]'
end
end
table.insert(hashes, ref.hash)
table.insert(refs, s)
--[[
elseif 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 = wikidata.formatSnak(ref.snaks.P304[1])
end
if hasValue('P813') then -- date de consultation
accessdate = wikidata.formatSnak(ref.snaks.P813[1])
end
if hasValue('P1683') then -- citation
quotation = wikidata.formatSnak(ref.snaks.P1683[1])
end
local sourceId = wikidata.getId(source)
s = reference.citeitem(sourceId, {['page'] = page, ['accessdate'] = accessdate, ['citation'] = quotation})
table.insert(refs, s)
table.insert(hashes, ref.hash .. sourceId)
end
end
--]]
elseif ref.snaks.P854 and ref.snaks.P854[1].snaktype == 'value' then
s = wikidata.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, cats
end
return refs, nil, cats
end
end
local function stringTable(args) -- like getClaims, but get a list of string rather than a list of snaks, for easier manipulation
local claims = args.claims
local cats = ''
if not claims then
claims = wikidata.getClaims(args)
end
if not claims or claims == {} then
return {}, {}, cats
end
if args.removedupesdate and (args.removedupesdate ~= '-') then
claims, cats = removeDupesDate(claims, args.removedupesdate)
end
local props = {} -- liste des propriétés associété à chaque string pour catégorisation et linkback
for i, j in pairs(claims) do
claims[i] = wikidata.formatStatement(j, args)
if args.expand and args.expand ~= '-' then
local sources, hashes, cat = getReferences(j, {expand = true}) -- affichage complet si expand
if sources and #sources > 1 then
cats = cats .. cat
local elementsHtml = mw.html.create('ul')
for _, source in pairs(sources) do
elementsHtml:tag('li'):wikitext(source):done():wikitext(' ')
end
claims[i] = claims[i].. tostring(elementsHtml:allDone())
end
end
table.insert(props, j.mainsnak.property)
end
if args.removedupes and (args.removedupes ~= '-') then
claims = wikidata.addNewValues({}, claims) -- devrait aussi supprimer de props celles qui ne sont pas utilisées
end
return claims, props, cats
end
local function formatQualifiers(statement, qualifs, params) -- basé sur wikidata.getFormattedQualifiers dans [[Module:Wikidata]]
local str = ''
if not params then params = {} end
local qualiftable = wikidata.getQualifiers(statement, qualifs)
if not qualiftable then
return nil
end
qualiftable = wikidata.filterClaims(qualiftable, params) or {}
for i, snak in pairs(qualiftable) do
if (snak.datatype == 'time' and snak.property == 'P7104') then -- fin de période couverte
str = str .. '-'
elseif i > 1 then
str = str .. ', '
end
qualiftable[i] = wikidata.formatSnak(snak, params)
if snak.datatype == 'quantity' and tonumber(snak.datavalue.value.amount) > 1 then -- pluriel
qualiftable[i] = qualiftable[i] .. 's'
end
str = str .. qualiftable[i]
end
local sources, hashes, cat = getReferences(statement) -- risque d'appel en double
if (not params.expand or params.expand == '-' or #sources == 1) and (params.showsource and params.showsource ~= '-') then
if sources then
if str ~= '' then
str = str .. ', '
end
str = str .. table.concat(sources, ', ')
end
end
return str .. cat
end
function p.main(frame)
local params = Outils.extractArgs( frame )
local showsource = params.showsource or true
local expand = params.expand or true
local entity = wikidata.getEntity(params.wikidata)
local cats = ''
local data = {
entity = entity,
property = 'P485', conjtype = 'new line',
showqualifiers = {'P217','P7328','P585','P7103','P7104'}, qualifprecision = 'year',
qualifformat = formatQualifiers, qualifargs = {expand = expand, showsource = showsource},
expand = expand
}
local result, props, cat = stringTable(data)
cats = cats .. cat
if #result > 0 then
-- Ajout du label si l'id wikidata a été précisé manuellement
if params.wikidata and entity then --Has "entity" parameter, Wikidata item was found
local label = entity:getLabel()
local link= wikidata.siteLink(entity)
if label then
if link then
title = title .. ' (pour [[' .. link .. '|' .. label .. ']])'
else
title = title .. ' (pour ' .. label .. ')'
end
elseif link then
title = title .. ' (pour [[' .. link .. ']])'
end
end
if params.linkback ~= '-' then
title = wikidata.addLinkBack(title , entity, 'P485')
end
local elementsHtml
if #result > 1 then
elementsHtml = mw.html.create('div')
:wikitext(title .. ' : ')
:tag('ul')
for _, val in pairs(result ) do
elementsHtml:tag('li'):wikitext(val):done():wikitext(' ')
end
elseif #result == 1 then
elementsHtml = mw.html.create('span')
:wikitext(title .. ' : ')
:wikitext(result[1])
end
return tostring(elementsHtml:allDone()) .. cats
end
return cats
end
return p