« Module:Site officiel » : différence entre les versions
Contenu supprimé Contenu ajouté
corrections |
intégration vérification des paramètres. En revanche, le module ne marche pas lorsqu'on a seulement un argument non nommé, problème dans Module:Outils ? |
||
Ligne 4 : | Ligne 4 : | ||
local Wikidata = require "Module:Wikidata" |
local Wikidata = require "Module:Wikidata" |
||
local Langue = require "Module:Langue" |
local Langue = require "Module:Langue" |
||
local Verif = require "Module:Correction syntaxique" |
|||
local function caterreur(param) |
local function caterreur(param) |
||
Ligne 19 : | Ligne 20 : | ||
if j ~= '' then args[i] = j end |
if j ~= '' then args[i] = j end |
||
end |
end |
||
⚫ | |||
local erreursarguments = Verif.verif(args, {'titre', 'title', '1', '2', 1, 2, 'langue', 'lang', 'url', 'wikidata'}, 'Modèle Site officiel avec un paramètre inconnu') |
|||
erreurs = erreursarguments or '' |
|||
local titredefaut = 'Site officiel' |
local titredefaut = 'Site officiel' |
||
Ligne 24 : | Ligne 29 : | ||
local langue = args['langue'] or args['lang'] |
local langue = args['langue'] or args['lang'] |
||
local url = args['url'] or args[2] or args[1] |
local url = args['url'] or args[2] or args[1] |
||
⚫ | |||
if (not langue) and (args[2]) then |
if (not langue) and (args[2]) then |
||
Ligne 32 : | Ligne 37 : | ||
-- si pas d'URL, essayer Wikidata, et si ça marche, sortir de ce module |
-- si pas d'URL, essayer Wikidata, et si ça marche, sortir de ce module |
||
if not url and (args.wikidata ~= '-') then |
if not url and (args.wikidata ~= '-') then |
||
local links = Wikidata.getClaims{entity = args |
local links = Wikidata.getClaims{entity = args.wikidata, property = 'P856', excludespecial = true} |
||
if links and (#links > 1) then |
if links and (#links > 1) then |
||
if titre == titredefaut then |
if titre == titredefaut then |
Version du 9 septembre 2017 à 17:33
[voir] [modifier] [historique] [purger]
Ce module est utilisé par le modèle {{Site officiel}}.
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 Lien = { }
local Outils = require "Module:Outils"
local Wikidata = require "Module:Wikidata"
local Langue = require "Module:Langue"
local Verif = require "Module:Correction syntaxique"
local function caterreur(param)
if mw.title.getCurrentTitle().namespace == 0 then
return '[[Catégorie:Page du modèle Site officiel comportant une erreur|' .. string.upper(param or '?') .. ']]'
else
return ''
end
end
function Lien.siteOfficiel( frame )
local oldargs = Outils.extractArgs( frame )
local args = {}
for i, j in pairs(oldargs) do
if j ~= '' then args[i] = j end
end
local erreurs -- les messages d'erreurs sont ajoutés ici
local erreursarguments = Verif.verif(args, {'titre', 'title', '1', '2', 1, 2, 'langue', 'lang', 'url', 'wikidata'}, 'Modèle Site officiel avec un paramètre inconnu')
erreurs = erreursarguments or ''
local titredefaut = 'Site 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 links = Wikidata.getClaims{entity = args.wikidata, property = 'P856', excludespecial = true}
if links and (#links > 1) then
if titre == titredefaut then
titre = nil
end
return "Sites officiels : " .. Wikidata.formatAndCat{claims = links, property = 'P856', displayformat = 'weblink', showlang = true, excludespecial = true}
elseif links then
return Wikidata.formatAndCat{claims = links, property = 'P856', displayformat = 'weblink', showlang = true, text = titre}
end
end
-- si toujours pas, ajouter les catégories d'erreur et sortir
if not url then
erreurs = erreurs .. caterreur('url')
return erreurs
end
-- nettoyage de l'URL
url = string.gsub ( string.gsub ( url, '%[', '%%5B' ), '%]', '%%5D' )
if not ( string.match( url, '^http' ) or string.match( url, '^//' ) ) then
url = 'http://' .. url
end
-- formatage de la langue
local indicLangue = '' -- langue telle qu'affichée dans le rendu final
if langue then
indicLangue = Langue.indicationMultilingue{ langue } .. ' '
end
return indicLangue .. '[' .. url .. ' ' .. titre .. ']' .. erreurs
end
return Lien