Module:Infobox/Fonctions : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
m
m
 
(28 révisions intermédiaires par 6 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
 
-- Fonctions communes à diverses infobox
 
-- Fonctions communes à diverses infobox
local wikidata = require 'Module:Interface Wikidata'.fromLua
+
local localdata = require( 'Module:Infobox/Localdata' )
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'
+
local wikidata = require( 'Module:Interface Wikidata' ).fromLua
local lang = mw.language.new('fr')
+
local coordfunctions -- = require 'Module:Infobox/Fonctions/Géolocalisation'
 
local p = {}
 
local p = {}
  
 
function p.title(icon, style, subtitleparam, subtitlequery)
 
function p.title(icon, style, subtitleparam, subtitlequery)
local title = localdata['nom']
 
if not title then
 
title = lang:ucfirst(wikidata.getLabel(item) or mw.title.getCurrentTitle().text)
 
end
 
 
if subtitleparam then
 
subtitle = localdata[subtitleparam]
 
end
 
if (not subtitle) and subtitlequery then
 
subtitle = wikidata.formatStatements(subtitlequery)
 
end
 
 
 
return {
 
return {
type = 'title',
+
type = 'title',
value = function() return title end,
+
value = function()  
subtitle = function() return subtitle end,
+
return localdata['nom']
icon = icon,
+
or wikidata.getLabel(localdata.item) and mw.language.getContentLanguage():ucfirst( wikidata.getLabel(localdata.item) )
style = style,
+
or mw.title.getCurrentTitle().text
 +
end,
 +
subtitle = function() return localdata[subtitleparam] end,
 +
wikidatasubtitle = subtitlequery,
 +
icon = icon,
 +
style = style,
 
}
 
}
 
end
 
end
  
function p.mainimage(cat, defaultimage, size)
+
function p.mainimage(args, defaultimage)
 +
if type( args ) ~= 'table' then
 +
args = { cat = args, defaultimage = defaultimage }
 +
end
 
return {
 
return {
 
type = 'images',
 
type = 'images',
 
imageparameters =  {'image'},
 
imageparameters =  {'image'},
defaultimages = defaultimage,
+
defaultimages = args.defaultimage,
 
defaultimagelink = 'Aide:Insérer une image',
 
defaultimagelink = 'Aide:Insérer une image',
 
sizeparameter = 'taille image',
 
sizeparameter = 'taille image',
defaultsize = size,
+
uprightparameter = 'upright',
maintenancecat =
+
defaultupright = args.upright,
function(localdata, item, params)
+
defaultsize = args.size,
if cat and (cat ~= '-') then
+
maintenancecat = args.cat or 'Article à illustrer',
return cat
 
else
 
return 'Article à illustrer'
 
end
 
end,
 
 
captionparameter = 'légende',
 
captionparameter = 'légende',
defaultcaption = function() return defaultcaption end,
+
altparameter = args.altparameter or 'alternative image',
property = 'P18',
+
defaultalt = args.alt,
 +
defaultimagealt = args.defaultimagealt,
 +
wikidata = args.wikidata or {property = 'P18'},
 
numval = 1,
 
numval = 1,
 
}
 
}
 
end
 
end
  
function p.logo(size)
+
function p.logo(upright)
 
return {
 
return {
 
type = 'images',
 
type = 'images',
Ligne 56 : Ligne 49 :
 
-- defaultimage = {},
 
-- defaultimage = {},
 
-- maintenancecat =
 
-- maintenancecat =
defaultsize =  size or '240px',
 
 
captionparameter = 'légende logo',
 
captionparameter = 'légende logo',
 
property = 'P154',
 
property = 'P154',
-- defaultupright = '0.8',
+
defaultupright = upright or '0.6',
 +
uprightparameter = 'upright logo',
 
sizeparameter = 'taille logo',
 
sizeparameter = 'taille logo',
 +
numval = 1,
 +
}
 +
end
 +
 +
function p.blason(upright)
 +
return {
 +
type = 'images',
 +
imageparameters =  {'blason'},
 +
-- defaultimage = {},
 +
-- maintenancecat =
 +
captionparameter = 'légende blason',
 +
property = 'P94',
 +
defaultupright = upright or '0.3',
 +
uprightparameter = 'upright blason',
 +
sizeparameter = 'taille blason',
 +
numval = 1,
 +
}
 +
end
 +
 +
function p.flag(upright)
 +
return {
 +
type = 'images',
 +
imageparameters =  {'drapeau'},
 +
-- defaultimage = {},
 +
-- maintenancecat =
 +
captionparameter = 'légende drapeau',
 +
property = 'P41',
 +
defaultupright = upright or '0.6',
 +
uprightparameter = 'upright drapeau',
 +
sizeparameter = 'taille drapeau',
 +
numval = 1,
 +
}
 +
end
 +
 +
function p.sign(upright)
 +
return {
 +
type = 'images',
 +
imageparameters =  {'signalisation'},
 +
-- defaultimage = {},
 +
-- maintenancecat =
 +
captionparameter = 'légende signalisation',
 +
property = 'P14',
 +
defaultupright = upright or '0.4',
 +
uprightparameter = 'upright signalisation',
 +
sizeparameter = 'taille signalisation',
 +
numval = 1,
 +
}
 +
end
 +
 +
function p.bathymetricmap(upright)
 +
return {
 +
type = 'images',
 +
imageparameters =  {'carte bathymétrique'},
 +
-- defaultimage = {},
 +
-- maintenancecat =
 +
captionparameter = 'légende carte bathymétrique',
 +
property = 'P207',
 +
defaultupright = upright or '1',
 +
uprightparameter = 'upright carte bathymétrique',
 +
sizeparameter = 'taille carte bathymétrique',
 
numval = 1,
 
numval = 1,
 
}
 
}
Ligne 66 : Ligne 119 :
  
 
-- Liens externes
 
-- Liens externes
function p.website() --texte libre [http://example.org example.org] ou url seule
+
function p.website() -- texte libre [http://example.org example.org] ou url seule
local function getLinks(item)
 
return wikidata.getClaims {property='P856', entity = item}
 
end
 
 
return {  
 
return {  
            type = 'mixed',
+
type = 'mixed',
            label = 'Site web',  
+
label = 'Site web',  
            wikidatalabel = function()
+
plurallabel = 'Sites web',
            local links = getLinks(item)
+
wikidata = {entity = localdata.item, displayformat = 'weblink', conjtype = '<br />', property = 'P856'},
            if links and #links > 1 then
+
value =  
            return 'Sites web'
+
function()
            end
+
local siteurl = localdata['site web'] or localdata['site_web'] or localdata['site officiel']
            return 'Site web'
+
local sitename = localdata['nom site']
            end,
+
return require("Module:Weblink").makelink(siteurl, sitename)
            wikidata = function()
+
end,
            local claims = getLinks(item)
+
}
            return wikidata.formatAndCat{entity = item, claims = claims, displayformat = 'weblink', conjtype = '<br />', property = 'P856'}
 
            end,
 
            value = function(localdata)  
 
            local website = localdata['site web'] or localdata['site_web'] or localdata['site officiel']
 
            if website then
 
            if (string.sub(website, 1, 4) == 'http') and (not string.find(website, ' ')) then -- if website is url
 
            return require("Module:Weblink").makelink(website)
 
            else
 
            return website
 
            end
 
            elseif localdata['url'] then
 
            return require("Module:Weblink").makelink(localdata['url'])
 
            end
 
            end
 
            }
 
 
end
 
end
  
-- Pays
+
-- Fonctions de géolocalisation
 
function p.country(default)
 
function p.country(default)
return coordfunctions.country(default)
+
local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
 +
return coordfunctions.country(default)
 +
end
 +
 
 +
function p.geoloc(params)
 +
local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
 +
return coordfunctions.geoloc(params)
 +
end
 +
 
 +
function p.coordinates(params)
 +
local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
 +
return coordfunctions.coordinates(params)
 +
end
 +
 
 +
function p.locationmap(params)
 +
local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
 +
return coordfunctions.locationmap(params)
 
end
 
end
  
 
return p
 
return p

Version actuelle datée du 31 octobre 2016 à 16:27

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/doc

-- Fonctions communes à diverses infobox
local localdata = require( 'Module:Infobox/Localdata' )
local wikidata = require( 'Module:Interface Wikidata' ).fromLua
local coordfunctions  -- = require 'Module:Infobox/Fonctions/Géolocalisation'
local p = {}

function p.title(icon, style, subtitleparam, subtitlequery)
	return {
		type = 'title',
		value = function() 
			return localdata['nom'] 
				or wikidata.getLabel(localdata.item) and mw.language.getContentLanguage():ucfirst( wikidata.getLabel(localdata.item) )
				or mw.title.getCurrentTitle().text
		end,
		subtitle = function() return localdata[subtitleparam] end,
		wikidatasubtitle = subtitlequery,
		icon = icon,
		style = style,
	}
end

function p.mainimage(args, defaultimage)
	if type( args ) ~= 'table' then
		args = { cat = args, defaultimage = defaultimage }
	end
	return {
		type = 'images',
		imageparameters =  {'image'},
		defaultimages = args.defaultimage,
		defaultimagelink = 'Aide:Insérer une image',
		sizeparameter = 'taille image',
		uprightparameter = 'upright',
		defaultupright = args.upright,
		defaultsize = 	args.size,
		maintenancecat = args.cat or 'Article à illustrer',
		captionparameter = 'légende',
		altparameter = args.altparameter or 'alternative image',
		defaultalt = args.alt,
		defaultimagealt = args.defaultimagealt,
		wikidata = args.wikidata or {property = 'P18'},
		numval = 1,
	}
end

function p.logo(upright)
	return {
		type = 'images',
		imageparameters =  {'logo'},
	--	defaultimage = {},
	--	maintenancecat =
		captionparameter = 'légende logo',
		property = 'P154',
		defaultupright = upright or '0.6',
		uprightparameter = 'upright logo',
		sizeparameter = 'taille logo',
		numval = 1,
	}
end

function p.blason(upright)
	return {
		type = 'images',
		imageparameters =  {'blason'},
	--	defaultimage = {},
	--	maintenancecat =
		captionparameter = 'légende blason',
		property = 'P94',
		defaultupright = upright or '0.3',
		uprightparameter = 'upright blason',
		sizeparameter = 'taille blason',
		numval = 1,
	}
end

function p.flag(upright)
	return {
		type = 'images',
		imageparameters =  {'drapeau'},
	--	defaultimage = {},
	--	maintenancecat =
		captionparameter = 'légende drapeau',
		property = 'P41',
		defaultupright = upright or '0.6',
		uprightparameter = 'upright drapeau',
		sizeparameter = 'taille drapeau',
		numval = 1,
	}
end

function p.sign(upright)
	return {
		type = 'images',
		imageparameters =  {'signalisation'},
	--	defaultimage = {},
	--	maintenancecat =
		captionparameter = 'légende signalisation',
		property = 'P14',
		defaultupright = upright or '0.4',
		uprightparameter = 'upright signalisation',
		sizeparameter = 'taille signalisation',
		numval = 1,
	}
end

function p.bathymetricmap(upright)
	return {
		type = 'images',
		imageparameters =  {'carte bathymétrique'},
	--	defaultimage = {},
	--	maintenancecat =
		captionparameter = 'légende carte bathymétrique',
		property = 'P207',
		defaultupright = upright or '1',
		uprightparameter = 'upright carte bathymétrique',
		sizeparameter = 'taille carte bathymétrique',
		numval = 1,
	}
end

-- Liens externes
function p.website() -- texte libre [http://example.org example.org] ou url seule
	return { 
		type = 'mixed',
		label = 'Site web', 
		plurallabel = 'Sites web',
		wikidata = {entity = localdata.item, displayformat = 'weblink', conjtype = '<br />', property = 'P856'},
		value = 
			function()
				local siteurl = localdata['site web'] or localdata['site_web'] or localdata['site officiel']
				local sitename = localdata['nom site']
				return require("Module:Weblink").makelink(siteurl, sitename)
			end,
	}
end

-- Fonctions de géolocalisation
function p.country(default)
	local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
	return coordfunctions.country(default)	
end

function p.geoloc(params)
	local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
	return coordfunctions.geoloc(params)	
end

function p.coordinates(params)
	local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
	return coordfunctions.coordinates(params)
end

function p.locationmap(params)
	local coordfunctions = coordfunctions or require 'Module:Infobox/Fonctions/Géolocalisation'
	return coordfunctions.locationmap(params)	
end

return p