Module:Blog officiel
Aller à la navigation
Aller à la recherche
La documentation pour ce module peut être créée à Module:Blog officiel/doc
local Lien = { } local Outils = require "Module:Outils" local Verif = require "Module:Correction syntaxique" local function caterreur(param) if mw.title.getCurrentTitle().namespace == 0 then return '[[Catégorie:Page du modèle Blog officiel comportant une erreur|' .. string.upper(param or '?') .. ']]' else return '' end end function Lien.blogOfficiel( frame ) local oldargs = Outils.extractArgs( frame ) local args = {} for i, j in pairs(oldargs) do local trimmed = mw.text.trim(j) if trimmed ~= '' then args[i] = trimmed end end local nocaturl = args.nocaturl local erreurs = '' -- les messages d'erreurs sont ajoutés ici local erreursarguments = Verif.verif(args, {'titre', 'title', 1, 2, 'langue', 'lang', 'url', 'wikidata', 'nocaturl'}, 'Modèle Blog officiel avec un paramètre inconnu') if erreursarguments then erreurs = erreurs .. erreursarguments end local titredefaut = 'Blog officiel' local titre = args['titre'] or args['title'] or titredefaut local langue = args['langue'] or args['lang'] local url = args['url'] or args[2] or args[1] if (not langue) and (args[2]) then langue = args[1] end -- si pas d'URL, essayer Wikidata, et si ça marche, sortir de ce module if not url and (args.wikidata ~= '-') then local Wikidata = require "Module:Wikidata" local links = Wikidata.getClaims{entity = args.wikidata, property = 'P1581', excludespecial = true} if links and (#links > 1) then if titre == titredefaut then titre = nil end return "Blogs officiels : " .. Wikidata.formatAndCat{claims = links, property = 'P1581', displayformat = 'weblink', showlang = true, excludespecial = true} .. erreurs elseif links then return Wikidata.formatAndCat{claims = links, property = 'P1581', displayformat = 'weblink', showlang = true, text = titre} .. erreurs end end -- si toujours pas, ajouter les catégories d'erreur et sortir if not url then if not nocaturl then erreurs = erreurs .. caterreur('url') end return erreurs end -- nettoyage de l'URL url = url:gsub( '%[', '%%5B' ):gsub( '%]', '%%5D' ) if not ( url:match( '^http' ) or url:match( '^//' ) ) then url = 'http://' .. url end -- formatage de la langue local indicLangue = '' -- langue telle qu'affichée dans le rendu final if langue then if langue ~= 'fr' then local Langue = require "Module:Langue" indicLangue = Langue.indicationMultilingue{ langue } .. ' ' if indicLangue:find('langue non reconnue') then erreurs = erreurs .. caterreur('langue') end end end return indicLangue .. '[' .. url .. ' ' .. titre .. ']' .. erreurs end return Lien