Dans le monde d'aujourd'hui, Module:Wikidata/Références/Bac à sable est devenu un sujet de la plus haute importance et pertinence pour différents domaines et secteurs. Son impact a été notable dans la société, l'économie, la politique, la culture et dans la vie quotidienne des gens. Depuis son émergence, Module:Wikidata/Références/Bac à sable a généré d'innombrables débats, discussions et analyses qui nous ont permis de comprendre sa portée et son impact dans le monde d'aujourd'hui. Dans cet article, nous explorerons en détail les différents bords et aspects liés à Module:Wikidata/Références/Bac à sable, en analysant son évolution au fil du temps, ses implications et défis actuels, ainsi que ses possibles développements futurs. Il examinera comment Module:Wikidata/Références/Bac à sable a transformé notre façon de penser, d'agir et d'interagir, ainsi que les opportunités et les défis qu'il représente pour l'avenir.
Ce module est utilisé par {{Bibliographie}}.
Fonctions exportables :
citeitem(id, page, dateconsult)
– formate au format Wikitexte, en utilisant les modèles de citation standard si possible, la référence.Test :
{{Bibliographie|Q21470144}}
{{Bibliographie|Q4791}}
{{Bibliographie|Q15228}}
{{Bibliographie|Q331651}}
{{Bibliographie|Q502633}}
{{Bibliographie|Q11927173|page= 122}}
{{Bibliographie|Q21192407}}
{{Bibliographie|Q58623966}}
{{Bibliographie|Q19170030}}
{{Bibliographie|Q98579483}}
{{Bibliographie|Q56389430}}
{{Bibliographie|Q113621581}}
{{Bibliographie|Q21035513}}
(en) Alessandro Ghedini, « The Road to QUIC », The Cloudflare Blog, (lire en ligne).
Sandbox:
{{Bibliographie|Q15397819}}
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 (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local reference = {}
local wd = require 'Module:Wikidata'
local refType = mw.loadData 'Module:Wikidata/Références/Types'
local linguistic = require 'Module:Linguistique'
local cite = require 'Module:Biblio'
local langcodes = mw.loadData 'Module:Dictionnaire Wikidata/Codes langue'
local function concatTables(t1,t2)
local results = {}
for _,e in pairs(t1) do
table.insert(results, e)
end
for _,e in pairs(t2) do
table.insert(results, e)
end
return results
end
local function getStringStatementValues(entity, propertyId)
local statements = mw.wikibase.getBestStatements(entity, propertyId)
for i, statement in pairs(statements) do
statements = statement.mainsnak.datavalue.value
end
return statements
end
local function getStringStatementValue(entity, propertyId)
local statements = getStringStatementValues(entity, propertyId)
if #statements > 0 then
return statements
else
return nil
end
end
local function getDirectItemLang(workentity, property)
local itemlangs = wd.getClaims{entity = workentity, property = property}
if itemlangs ~= nil then
local codes = {}
for i = 1, #itemlangs do
codes = langcodes.mainsnak)]
end
return table.concat(codes, ", ")
end
end
local function hasRole(statement, roleId)
return statement.qualifiers and (
statement.qualifiers and wd.getId(statement.qualifiers) == roleId
or statement.qualifiers and wd.getId(statement.qualifiers) == roleId
)
end
local currentPageTitle = mw.title.getCurrentTitle().prefixedText
local function buildAuthorLink(statement)
local author_label = nil
local author_link = nil
-- getting the label directly from its value to support "author name string" (P2093)
if statement.mainsnak.snaktype == 'value' and statement.mainsnak.datatype == 'string' then
author_label = statement.mainsnak.datavalue.value
elseif statement.qualifiers and statement.qualifiers and statement.qualifiers.snaktype == 'value' then
-- we use "stated in" (P1932) to retrieve the proper author label
author_label = statement.qualifiers.datavalue.value
end
-- we extract the link and the label of the author if it is an entity
if statement.mainsnak.snaktype == 'value' and statement.mainsnak.datatype == 'wikibase-item' then
local author_id = statement.mainsnak.datavalue.value.id
if author_label == nil then
-- fallback on author's item label, if it exists
author_label = mw.wikibase.getLabel(author_id)
end
author_link = mw.wikibase.getSitelink(author_id)
end
if author_link ~= nil and author_link ~= currentPageTitle then
return ']'
else
return author_label
end
end
local function remove_same_isbn(isbns)
-- input a table of isbns
-- return a table of ibns without duplicate
-- asked in https://fr.wikipedia.orghttps://scientiafr.com/Discussion_mod%C3%A8le:Bibliographie#ISBN-10_et_ISBN-13
local References = require( 'Module:Biblio/Références' )
local result = {}
for _, isbn1 in ipairs(isbns) do
local same = false
for index_isbn2, isbn2 in ipairs(result) do
if References.same_isbn(isbn1, isbn2) then
if isbn2:gsub( '', '' ):len() == 13 then
table.remove(result, index_isbn2)
table.insert(result, isbn1)
end
same = true
break
end
end
if not same then
table.insert(result, isbn1)
end
end
return result
end
local function labelformatP1813(e)
-- input: an entity
-- returns a formatted string using the "short name" (P1813) if one is declared
return wd.formatStatements{entity = e, property = 'P1813', defaultlink= '-', numval=1} or wd.getLabel(e)
end
function reference.citeitem(entityId, options)
if not entityId then
return nil
end
local entity = entityId
if not mw.wikibase.getEntityUrl(entityId) then -- test de la validité de l'identifiant, nil si invalide
return 'invalid entity id'
end
if type( options ) ~= 'table' then
options = {}
end
--work entity if it exists
local workEntity = nil
local workClaims = wd.getClaims{entity = entity, property = 'P629'} -- P629 : édition de
if workClaims ~= nil then
workEntity = wd.getMainId(workClaims)
end
local journalEntity = nil
local journalClaims = wd.getClaims{entity = entity, property = 'P1433'}
if journalClaims ~= nil then
journalEntity = wd.getMainId(journalClaims)
end
local translator = wd.formatStatements{entity = entity, property = 'P655', defaultlink = '-'}
local illustrator = wd.formatStatements{entity = entity, property = 'P110', defaultlink = '-'}
local preface = wd.formatStatements{entity = entity, property = 'P2679', defaultlink = '-'}
local postface = wd.formatStatements{entity = entity, property = 'P2680', defaultlink = '-'}
local photographe = ''
local authors = {}
local authors_id = {}
local are_director = {}
local responsability = {}
local author_statements = concatTables(mw.wikibase.getBestStatements(entity, 'P50'), mw.wikibase.getBestStatements(entity, 'P2093'))
if next(author_statements) == nil and workEntity ~= nil then --Fallback to work
author_statements = concatTables(
mw.wikibase.getBestStatements(workEntity, 'P50'),
mw.wikibase.getBestStatements(workEntity, 'P2093')
)
end
for _, statement in pairs(author_statements) do
local position = #authors + 1
if statement.qualifiers and statement.qualifiers then
position = tonumber(statement.qualifiers.datavalue.value)
end
if statement.mainsnak.snaktype == 'value' and statement.mainsnak.datatype == 'wikibase-item' then
authors_id = statement.mainsnak.datavalue.value.id
end
authors = buildAuthorLink(statement)
are_director = ''
--qualifier pour la responsabilité
if statement.qualifiers and statement.qualifiers then
responsability = wd.formatSnak(statement.qualifiers, {defaultlink = '-'})
else
responsability = ''
end
end
for _, statement in pairs(mw.wikibase.getBestStatements(entity, 'P98')) do
local isduplicate = false
for id_key, id in pairs(authors_id) do
if statement.mainsnak.snaktype == 'value' and statement.mainsnak.datatype == 'wikibase-item' and id == statement.mainsnak.datavalue.value.id then
are_director = 'y'
isduplicate = true
break
end
end
if not isduplicate then
table.insert(authors, buildAuthorLink(statement))
table.insert(are_director, 'y')
table.insert(responsability, '')
end
end
for _, statement in pairs(mw.wikibase.getBestStatements(entity, 'P767')) do
if hasRole(statement, 'Q670787') or hasRole(statement, 'Q19839393') then --préface/préfacier
preface = buildAuthorLink(statement)
elseif hasRole(statement, 'Q7234272') then --postface
postface = buildAuthorLink(statement)
elseif hasRole(statement, 'Q33231') or hasRole(statement, 'Q125191') then --photographe/photographie
photographe = buildAuthorLink(statement)
end
end
local isbns = getStringStatementValues(entity, 'P212')
for _, isbn in pairs(getStringStatementValues(entity, 'P957')) do
table.insert(isbns, isbn)
end
if journalEntity then
for _, isbnpublishedin in pairs(getStringStatementValues(journalEntity, 'P212')) do
table.insert(isbns, isbnpublishedin)
end
for _, isbnpublishedin in pairs(getStringStatementValues(journalEntity, 'P957')) do
table.insert(isbns, isbnpublishedin)
end
end
local issns = {}
if journalEntity then
issns = getStringStatementValues(journalEntity, 'P236')
end
if #issns == 0 then
issns = getStringStatementValues(entity, 'P236')
end
local oclc = getStringStatementValue(entity, 'P243')
local bnf = getStringStatementValue(entity, 'P268')
local gallica = getStringStatementValue(entity, 'P4258')
local lccn = getStringStatementValue(entity, 'P1144')
local dnb = getStringStatementValue(entity, 'P1292')
local doi = getStringStatementValue(entity, 'P356')
local pmid = getStringStatementValue(entity, 'P698')
local jstor = getStringStatementValue(entity, 'P888')
local bibcode = getStringStatementValue(entity, 'P1300')
local arxiv = getStringStatementValue(entity, 'P818')
local pmcid = getStringStatementValue(entity, 'P932')
local ednumber = wd.formatStatements{entity = entity, property = 'P393'}
local publisher = wd.formatStatements{entity = entity, property = 'P123', defaultlink = '-', labelformat = labelformatP1813 }
local journal = wd.formatStatements{entity = entity , property = 'P1433', defaultlink = '-'}
local numero = ''
if journalClaims and wd.hasQualifier(journalClaims, 'P433') then
numero = wd.getFormattedQualifiers(journalClaims, 'P433')
else
numero = getStringStatementValue(entity, 'P433')
end
local volume = ''
if journalClaims and wd.hasQualifier(journalClaims, 'P478') then
volume = wd.getFormattedQualifiers(journalClaims, 'P478')
else
volume = getStringStatementValue(entity, 'P478')
end
local chapter = ''
if journalClaims and wd.hasQualifier(journalClaims, 'P792') then
chapter = wd.getFormattedQualifiers(journalClaims, 'P792')
else
chapter = getStringStatementValue(entity, 'P792')
end
local page = ''
if journalClaims and wd.hasQualifier(journalClaims, 'P304') then
page = wd.getFormattedQualifiers(journalClaims, 'P304')
else
page = getStringStatementValue(entity, 'P304')
end
local publishdate = wd.formatStatements{entity = entity, property = 'P577', linktopic = '-'}
local publishplace = wd.formatStatements{entity = entity, property = 'P291', defaultlink = '-'}
--if no publisher, publication date or place, oclc or bnf: look for them in the item stored in P1433, misnamed here as "journalEntity"
if (not publisher) and journalEntity then
publisher = wd.formatStatements{entity = journalEntity, property = "P123", defaultlink = "P577", labelformat = labelformatP1813}
end
if (not publishdate) and journalEntity then
publishdate = wd.formatStatements{entity = journalEntity, property = "P577", linktopic = "P577"}
end
if (not publishplace) and journalEntity then
publishplace = wd.formatStatements{entity = journalEntity, property = "P291", defaultlink = "P577"}
end
if (not oclc) and journalEntity then
oclc = wd.formatStatements{entity = journalEntity, property = "P243", defaultlink = "P577"}
end
if (not bnf) and journalEntity then
bnf = wd.formatStatements{entity = journalEntity, property = "P268", defaultlink = "P577"}
end
local pagenum = wd.formatStatements{entity = entity, property = 'P1104'}
local title
local titlestatement = wd.getClaims{entity = entity, property = 'P1476', numval = 1}
if titlestatement then
title = wd.getFormattedQualifiers(titlestatement, 'P6833') -- htmltitle
end
title = title or wd.formatStatements{entity = entity, property = 'P1476', numval = 1 } or wd.getLabel(entity)
local titlelink = wd.siteLink(entity)
local subtitle = titlestatement and wd.getFormattedQualifiers(titlestatement, 'P1680') or wd.formatStatements{entity = entity, property = 'P1680'}
local url = getStringStatementValue(entity, 'P2699') or getStringStatementValue(entity, 'P854') or getStringStatementValue(entity, 'P953') or (gallica and "https://gallica.bnf.fr/ark:/12148/" .. gallica)
local wikisource = mw.wikibase.getSitelink(entity, 'frwikisource')
if wikisource ~= nil and url ~= nil and url:find('%.wikisource%.org') then
url = nil -- we make sure to not have two links to Wikisource
end
local language = getDirectItemLang(entity, 'P407')
if not language and journalEntity then
language = getDirectItemLang(journalEntity, 'P407')
end
local originalLanguage = getDirectItemLang(entity, 'P364') --TODO: be clever? or getDirectItemLang(workEntity, 'P407') or getDirectItemLang(workEntity, 'P364')
if not language or language == originalLanguage then
originalLanguage = nil -- We are actually not sure if it has been translated from this language
end
local originalTitle = nil
if workEntity and originalLanguage then
originalTitle = wd.formatStatements{entity = workEntity, property = 'P1476', numval = 1 }
if not originalTitle then
originalTitle = mw.wikibase.getLabelByLang(workEntity, originalLanguage)
originalTitle = "<span lang='" .. originalLanguage .. "'>'"..originalTitle.."</span>"
end
end
local citation = wd.formatStatements{entity = entity, property = 'P1683'}
-- choose relevant cite type
local entitytype = wd.formatStatements{property = 'P31', entity = entity, numval = 1, displayformat = 'raw'}
local funtype
-- calcul du rendu du titre de l'ouvrage, éventuellement avec un lien vers l'article de l'ouvrage
-- pas de lien à générer si on est sur la page de l'ouvrage ou si l'élément cité est une édition de cet ouvrage
if not ( wd.isPageOfQId(entityId) or
workEntity and wd.isPageOfQId(wd.entityId(workEntity)) )
then
if not titlelink and workEntity then
-- si pas de lien, on peut essayer de voir si c'est l'édition de quelque chose d'autre
titlelink = wd.siteLink(workEntity)
end
if title and titlelink then
title = ']'
end
end
-- calcul du modèle à utiliser pour rendre l'élémént
if (entitytype == 'Q3331189') then --book edition
funtype = cite.ouvrage
-- TODO : gérer l'édition et l'élément de l'oeuvre.
elseif refType.isOuvrage then -- ouvrage sans édition connue ?
-- TODO : gérer le cas ou un ouvrage est cité mais que Wikidata en connait des éditions.
-- TODO : refuser ce genre d'items ?
funtype = cite.ouvrage
elseif refType.isArticle then -- article
funtype = cite.article
elseif refType.isChapitre then -- chapitre
funtype = cite.chapitre
else -- default: output a very simple display
local parameters = authors
if title then
table.insert(parameters, '<i>' .. title .. '</i>')
end
if entitytype and wd.getLabel(entitytype) then
table.insert(parameters, ' (' .. wd.getLabel(entitytype) .. ')')
end
if publisher then
table.insert(parameters, publisher)
end
if publishplace then
table.insert(parameters, publishplace)
end
if publishdate then
table.insert(parameters, publishdate)
end
if url then
table.insert (parameters, mw.getCurrentFrame():expandTemplate{title="lire en ligne",args={url=url}})
end
if options then
table.insert(parameters, 'p.' .. options)
end
if options then
table.insert(parameters, 'consulté le ' .. options)
end
parameters = wd.addLinkBack(parameters, entity, "P31")
return linguistic.conj(parameters, 'comma')
end
local parameters = {
= translator,
= illustrator,
= preface,
= postface,
= photographe,
= title,
= subtitle,
= publishdate,
= publishplace,
= journal,
= ednumber,
= publisher,
= pagenum,
= url,
= wikisource,
= oclc,
= bnf,
= lccn,
= dnb,
= doi,
= pmid,
= jstor,
= bibcode,
= arxiv,
= pmcid,
= language,
= originalLanguage,
= originalTitle,
= page,
= numero,
= volume,
= citation,
= options
}
if refType.isChapitre and journalClaims then -- chapitre
parameters = journal
parameters = '' -- TODO
parameters = '' -- TODO
parameters = '' --TODO
parameters = chapter
parameters = title
parameters = subtitle
parameters = '' -- TODO
end
isbns = remove_same_isbn(isbns)
for i, isbn in pairs(isbns) do
parameters = isbn
end
for i, issn in pairs(issns) do
parameters = issn
end
-- try to find if there is an author set in options
local setAuthors = true
for i=1, 15 do
if options or options or options then
setAuthors = false
end
end
if setAuthors then
for i, author in pairs(authors) do
parameters = author
parameters = are_director
parameters = responsability
end
end
for parameter, value in pairs(options) do
if value == '-' then
parameters = ''
else
parameters = value
end
end
local val = funtype(parameters)
if val then
return wd.addRefAnchor(wd.addLinkBack(val, entity), wd.entityId(entity))
end
return wd.formatError()
end
-- pour tester
function reference.citeItem(frame)
local args = frame:getParent().args
return reference.citeitem(args, args)
end
--used to test the duplicate isbn functions, use in the console like this
-- p.test()
reference.test = function()
test_same_isbn()
test_remove_same_isbn()
end
return reference