Module:NooSFere
De Wikipedia, l'encyclopédie encyclopedia
local p = {}
local wd = require 'Module:Wikidata' local mdate = require 'Module:Date' local urlNoosfere = "https://www.noosfere.org" local defaultSur = "sur le site NooSFere"
local function getId(args, property) local id = args.id or args[1]
if not id and property then local claims = wd.getClaims{entity = args.entity, property = property, numval = 1}
if claims then for i, j in pairs(claims) do if j.mainsnak and j.mainsnak.snaktype == 'value' and j.mainsnak.datavalue then id = j.mainsnak.datavalue.value if mw.title.getCurrentTitle().namespace == 0 then id = id .. '' end end end end end return id end
local function isFromWikidata(args) if args.id or args[1] then return false end return true end
local function getNomTitre(args, fromwikidata) local nom = args.nom or args.titre or args[2]
if not nom and fromwikidata then local entity = args.entity if not entity then
entity = mw.wikibase.getEntityIdForCurrentPage() end
nom = wd.getLabel(entity) end return nom or mw.title.getCurrentTitle().text end
local function formatConsulteLe(consultele) if consultele then if string.sub(consultele, 1, 5) ~= '<time' then consultele = mdate.modeleDate{consultele, nolinks=1} end return ' (consulté le ' .. consultele .. ')' end return end
local function getEditeur(args, fromwikidata) local editeur = args["éditeur"]
if not editeur and fromwikidata then if wd.isInstance("Q3331189", {id=args.entity}, 2) then editeur = wd.formatStatements{entity = args.entity, property = 'P123', linkback = args.linkback == nil or args.linkback == "true"} end elseif editeur == "-" then editeur = nil end return editeur end
local function getDate(args, fromwikidata, instanceOf) local date = args.date or args["année"]
if not date and fromwikidata and instanceOf then
if wd.isInstance(instanceOf, {id=args.entity}, 3) then date = wd.formatStatements{entity = args.entity, property = 'P577', linkback = args.linkback == nil or args.linkback == "true"} end elseif date == "-" then date = nil elseif date and string.sub(date, 1, 5) ~= '<time' then date = mdate.modeleDate{date, nolinks=1} end return date end
local function getAuteur(args, fromwikidata, instanceOf) local auteur = args.auteur or args[3]
if not auteur and fromwikidata and instanceOf then if wd.isInstance(instanceOf, {id=args.entity}, 3) then auteur = wd.formatStatements{entity = args.entity, property = 'P50', sorttype = 'P1545', linkback = args.linkback == nil or args.linkback == "true"} end elseif auteur == "-" then auteur = nil end return auteur end
function p.article( frame ) local url = urlNoosfere .. "/articles/article.asp?numarticle="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args) if not id then return '' end local titre = getNomTitre(args, false) local texte = args.texte local auteur = getAuteur(args, false) local consultele = args['consulté le'] local page = args['page'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id if page then url = url .. '&numpage=' .. page end
if lien then return url elseif titre == '-' or texte == '-' then return '[' .. url .. ']' end
local rendu if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else rendu = '« ' .. '[' .. url .. ' ' .. titre .. ']' .. ' »' end
if auteur then rendu = rendu .. ", article de " .. auteur end
local date = getDate(args, false) if args.publication or args.date then rendu = rendu .. ' (' if args.publication then rendu = rendu .. args.publication end if date then if args.publication then rendu = rendu .. ', ' end rendu = rendu .. date end rendu = rendu .. ')' end
if sur ~= '-' then if auteur then rendu = rendu .. "," end rendu = rendu .. " " .. sur end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.auteur( frame ) local urlAuteur = urlNoosfere .. "/livres/auteur.asp?numauteur=" local urlCritiques = urlNoosfere .. "/livres/critsigndetail.asp?numauteur="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args, 'P5570') if not id then return '' end local isFromWikidata = isFromWikidata(args) local nom = args.texte or getNomTitre(args, isFromWikidata) local consultele = args['consulté le'] local souspage = args['sous-page'] or args['Niveau'] or args['niveau'] local tri = args.tri or args.Tri local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet'] local url
if souspage == 'critiques' then url = urlCritiques .. id nom = 'Critiques par ' .. nom else url = urlAuteur .. id if souspage then url = url .. '&Niveau=' .. souspage end end if tri then url = url .. '&tri=' .. tri end
if lien then return url elseif nom == '-' then return '[' .. url .. ']' end
local rendu = '[' .. url .. ' ' .. nom .. ']'
if sur ~= '-' then rendu = rendu .. " " .. sur end
if (souspage and souspage ~= "critiques") or tri then rendu = rendu .. " (" if souspage then local cases = { livres = "Livres", Nouvelles = "Autres fictions", revues = "Articles/critiques", illus = "Illustrations", bio = "Biographie", critiques = "", } local niveau = cases[souspage] or souspage rendu = rendu .. niveau end if tri then local cases = { alpha = "Titre", chronoVF = "Date VF", chronoVO = "Date VO", editeur = "Éditeur", chrono = "Date", auteur = "Auteur", } local lableTri = cases[tri] or tri if souspage and souspage ~= "critiques" then rendu = rendu .. ', ' end rendu = rendu .. lableTri end rendu = rendu .. ")" end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.collection( frame ) local url = urlNoosfere .. "/livres/collection.asp?numcollection="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args) if not id then return '' end local nom = args.nom or args[2] or mw.title.getCurrentTitle().text local titre = args.titre or args.texte local prefix = args.prefix or "Fiche de la collection" local souspage = args['sous-page'] or args['Niveau'] or args['niveau'] local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if souspage then url = url .. '&Niveau=' .. souspage end
if lien then return url elseif nom == '-' or titre == '-' then return '[' .. url .. ']' end
local rendu if titre then rendu = '[' .. url .. ' ' .. titre .. ']' else rendu = '« ' .. '[' .. url .. ' ' .. nom .. ']' .. ' »' if prefix ~= '-' then rendu = prefix .. ' ' .. rendu end end
local editeur = getEditeur(args, isFromWikidata) if editeur then rendu = rendu .. ' (' .. editeur .. ')' end
if sur ~= '-' then rendu = rendu .. " " .. sur end
if souspage then local cases = { collection = "livres", autres = "livres et rééditions", couv = "couvertures", } local niveau = cases[souspage] if niveau then rendu = rendu .. " (" .. niveau .. ")" end end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.editeur( frame ) local url = urlNoosfere .. "/livres/editeur.asp?numediteur="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args) if not id then return '' end local nom = args.nom or args[2] or mw.title.getCurrentTitle().text local titre = args.titre or args.texte local prefix = args.prefix or "Fiche de l'éditeur" local souspage = args['sous-page'] or args['Niveau'] or args['niveau'] local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if souspage then url = url .. '&Niveau=' .. souspage end
if lien then return url elseif nom == '-' or titre == '-' then return '[' .. url .. ']' end
local rendu if titre then rendu = '[' .. url .. ' ' .. titre .. ']' else rendu = "« " .. '[' .. url .. ' ' .. nom .. ']' .. ' »' if prefix ~= '-' then rendu = prefix .. ' ' .. rendu end end
if sur ~= '-' then rendu = rendu .. " " .. sur end
if souspage then local cases = { collections = "Collections", tout = "Toutes les parutions", } local niveau = cases[souspage] if niveau then rendu = rendu .. " (" .. niveau .. ")" end end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.edition( frame ) local url = urlNoosfere .. "/livres/niourf.asp?numlivre="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args, 'P6901') if not id then return '' end local isFromWikidata = isFromWikidata(args) local titre = getNomTitre(args, isFromWikidata) local texte = args.texte local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if args.ancre then url = url .. "#" .. args.ancre end
if lien then return url elseif titre == '-' or texte == '-' then return '[' .. url .. ']' end
if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else rendu = "« " .. '[' .. url .. ' ' .. titre .. ']' .. ' »' end
local auteur = getAuteur(args, isFromWikidata, "Q3331189") if auteur then rendu = auteur .. ", " .. rendu end
local editeur = getEditeur(args, isFromWikidata) local date = getDate(args, isFromWikidata, "Q3331189") if editeur or date then rendu = rendu .. ' (' if editeur then rendu = rendu .. editeur end if date then if editeur then rendu = rendu .. ', ' end rendu = rendu .. date end rendu = rendu .. ')' end
if sur ~= '-' then rendu = rendu .. " " .. sur end
if args.ancre then local labelAncre if args.ancre == "Résumes" then labelAncre = "Quatrième de couverture" elseif args.ancre == "ListeRef" then labelAncre = "Citations thématiques" elseif args.ancre == "CitationListes" then labelAncre = "Citations" elseif args.ancre == "Adaptations" then labelAncre = "Adaptations" elseif args.ancre == "AutresCritique" then labelAncre = "Critiques" elseif args.ancre == "Critique" then labelAncre = "Critiques" else labelAncre = args.ancre end rendu = rendu .. " (" .. labelAncre .. ")" end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.GPI( frame ) local url = "https://gpi.noosfere.org/"
local parentFrame = frame:getParent() local args = parentFrame.args
local annee = args["année"] or args[1] if annee == then annee = nil end local categorie = args["catégorie"] or args[2] if categorie == then categorie = nil end if not categorie and annee then local a = tonumber(annee) if not a then categorie = annee annee = nil end end if not annee and not categorie then return '' end
local texte = args.texte or args.titre or args.nom local prefix = args.prefix or "GPI —" local sur = args.sur or "sur gpi.noosfere.org" local consultele = args['consulté le'] local lien = args['lien'] or args['sans crochet']
if annee then url = url .. 'gpi-' .. annee .. '/' else url = url .. categorie .. '/' end
if lien then return url elseif texte == '-' then return '[' .. url .. ']' end
local rendu if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else if annee then rendu = '[' .. url .. ' Palmarès ' .. annee .. ']' else local cat if categorie == "roman-francophone" then cat = "Roman francophone" elseif categorie == "roman-etranger" then cat = "Roman étranger" elseif categorie == "nouvelle-francophone" then cat = "Nouvelle francophone" elseif categorie == "nouvelle-etrangere" then cat = "Nouvelle étrangère" elseif categorie == "roman-jeunesse-francophone" then cat = "Roman jeunesse francophone" elseif categorie == "roman-jeunesse-etranger" then cat = "Roman jeunesse étranger" elseif categorie == "traduction" then cat = "Traduction" elseif categorie == "graphisme" then cat = "Graphisme" elseif categorie == "bd" then cat = "BD" elseif categorie == "manga" then cat = "Manga" elseif categorie == "essai" then cat = "Essai" elseif categorie == "prix-special" then cat = "Prix spécial" elseif categorie == "prix-europeen" then cat = "Prix européen" else cat = categorie end rendu = '[' .. url .. ' Palmarès par catégories — ' .. cat.. ']' end end
if prefix ~= '-' then rendu = prefix .. " " .. rendu end
if sur ~= '-' then rendu = rendu .. " " .. sur end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.livre( frame ) local url = urlNoosfere .. "/livres/EditionsLivre.asp?numitem="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args, 'P5571') if not id then return '' end local isFromWikidata = isFromWikidata(args) local titre = getNomTitre(args, isFromWikidata) local texte = args.texte local tri = args.tri or args.Tri local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if tri then url = url .. '&Tri=' .. tri end
if lien then return url elseif titre == '-' or texte == '-' then return '[' .. url .. ']' end
if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else rendu = "« " .. '[' .. url .. ' ' .. titre .. ']' .. ' »' end
local auteur = getAuteur(args, isFromWikidata, "Q47461344") if auteur then rendu = auteur .. ", " .. rendu end
local date = getDate(args, isFromWikidata, "Q47461344") if date then rendu = rendu .. ' (' .. date .. ')' end
if sur ~= '-' then rendu = rendu .. " " .. sur end
if tri then local lableTri if tri == "1" then lableTri = "par nom d'éditeur" elseif tri == "2" then lableTri = "chronologique inversé" elseif tri == "3" then lableTri = "chronologique" else lableTri = tri end if lableTri then rendu = rendu .. " (" .. lableTri .. ")" end end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.oeuvre( frame ) local url = urlNoosfere .. "/livres/EditionsLivre.asp?ID_ItemSommaire="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args, 'P6221') if not id then return '' end local isFromWikidata = isFromWikidata(args) local titre = getNomTitre(args, isFromWikidata) local texte = args.texte local tri = args.tri or args.Tri local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if tri then url = url .. '&Tri=' .. tri end
if lien then return url elseif titre == '-' or texte == '-' then return '[' .. url .. ']' end
if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else rendu = "« " .. '[' .. url .. ' ' .. titre .. ']' .. ' »' end
local auteur = getAuteur(args, isFromWikidata, "Q47461344") if auteur then rendu = auteur .. ", " .. rendu end
local date = getDate(args, isFromWikidata, "Q7725634") if date then rendu = rendu .. ' (' .. date .. ')' end
if sur ~= '-' then rendu = rendu .. " " .. sur end
if tri then local lableTri if tri == "1" then lableTri = "par nom d'éditeur" elseif tri == "2" then lableTri = "chronologique inversé" elseif tri == "3" then lableTri = "chronologique" else lableTri = tri end if lableTri then rendu = rendu .. " (" .. lableTri .. ")" end end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.prix( frame ) local url = urlNoosfere .. "/livres/prix.asp?numprix="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args) if not id then return '' end local nom = getNomTitre(args, false) local texte = args.texte local annee = args['année'] local tri = args.tri or args.Tri local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if tri then url = url .. '&tri=' .. tri end
if annee then url = url .. '#A' .. annee end
if lien then return url elseif nom == '-' or texte == '-' then return '[' .. url .. ']' end
local rendu if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else rendu = "Fiche du prix « " .. '[' .. url .. ' ' .. nom .. ']' .. ' »' end
if tri or annee then rendu = rendu .. " (" if tri then local lableTri if tri == "an" then lableTri = "par année" elseif tri == "cat" then lableTri = "par catégorie" else lableTri = tri end rendu = rendu .. lableTri end if annee then if tri then rendu = rendu .. ', ' end rendu = rendu .. annee end rendu = rendu .. ")" end
if sur ~= '-' then rendu = rendu .. " " .. sur end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
function p.serie( frame ) local url = urlNoosfere .. "/livres/serie.asp?numserie="
local parentFrame = frame:getParent() local args = parentFrame.args
local id = getId(args, 'P5792') if not id then return '' end local isFromWikidata = isFromWikidata(args) local nom = getNomTitre(args, isFromWikidata) local texte = args.texte local souspage = args['sous-page'] or args['Niveau'] or args['niveau'] local consultele = args['consulté le'] local sur = args.sur or defaultSur local lien = args['lien'] or args['sans crochet']
url = url .. id
if souspage then url = url .. '&Niveau=' .. souspage end
if lien then return url elseif nom == '-' or texte == '-' then return '[' .. url .. ']' end
if texte then rendu = '[' .. url .. ' ' .. texte .. ']' else rendu = "« " .. '[' .. url .. ' ' .. nom .. ']' .. ' »' end
local auteur = getAuteur(args, isFromWikidata, "Q17489659") if auteur then rendu = auteur .. ", " .. rendu end
local date = getDate(args, isFromWikidata, "Q17489659") if date then rendu = rendu .. ' (' .. date .. ')' end
if sur ~= '-' then rendu = rendu .. " " .. sur end
if souspage then local cases = { simple = "affichage simple", complet = "affichage complet", } local niveau = cases[souspage] if niveau then rendu = rendu .. " (" .. niveau .. ")" end end
rendu = rendu .. formatConsulteLe(consultele)
return rendu end
return p