(Fixed) |
(?) |
||
Ligne 70 : | Ligne 70 : | ||
local size = {} |
local size = {} |
||
if args.type and not ( args.width and args.height ) then |
if args.type and not ( args.width and args.height ) then |
||
− | for i, j in pairs( |
+ | for i, j in pairs( require( 'Module:Data' ).imageSize[args.type] ) do |
if dataName == i then |
if dataName == i then |
||
if args.id then |
if args.id then |
Version du 31 octobre 2017 à 10:36
Ce module est lié au projet Modèles. Ne l'utilisez pas sur des pages du wiki non-liées à ce projet tant que celui-ci n'est pas terminé.
|
La documentation ci-haut est transcluse de Module:Image/doc. (modifier | historique)
local p = {}
local rtext = require( 'Module:Text' )
-- "ext: gif, size:12" --> { ext = "gif", size = "12" }
local function splitParams( initialString )
local firstSplit = rtext.trimAll( mw.text.split( initialString, ',%s' ) )
local param = {}
local allParam = {}
for i, j in pairs( firstSplit ) do
param = rtext.trimAll( mw.text.split( j, ':' ) )
allParam[param[1]] = param[2]
end
return allParam
end
-- "( ext: gif, size:12 )(name : Box)" --> { 1 = "ext: gif, size:12", 2 = "name : Box" }
local function splitImages( initialString )
local images = rtext.trimAll( rtext.trimAll( mw.text.split( initialString, '%(' ) ), '%)' )
local params = {}
local i = 2 -- 1st box of 'images' is empty
repeat
params[i-1] = splitParams( images[i] )
i = i + 1
until not images[i]
return params
end
local function merge( userParam, default )
local param = {}
for i, j in pairs( default ) do
param[i] = j
end
for k, l in pairs( userParam ) do
param[k] = l
end
return param
end
function p.main( f )
local args = rtext.trimAll( rtext.getArgs( f ) )
if not args.params then error( 'Missing "params" parameter', 0 ) end
local ret = ''
local userParams = splitImages( args.params )
for i, j in pairs( userParams ) do
ret = ret .. p.data( args['image'..i] and merge( j, splitParams( args['image'..i] ) ) or j )
end
return ret
end
function p.data( f )
local args = rtext.trimAll( rtext.getArgs( f ) )
if not ( args.type or args.width or args.height ) then error( 'Missing file size values. Add a value to "type", "width", or "height"', 0 ) end
local wikiName = rtext.link{ name=args.name, type=args.type, data=true }.wiki
local fileName = ''
if args.fullname then
fileName = args.fullname
else
fileName = fileName .. rtext.link{ name=args.name, type=args.type, data=true }.file
fileName = ( args.pfx and ' ' .. ( args.pfx ):lower() or '' ) .. fileName .. ( args.sfx and ' ' .. ( args.sfx ):lower() or '' )
end
fileName = fileName .. '.' .. ( args.ext or 'png' )
local size = {}
if args.type and not ( args.width and args.height ) then
for i, j in pairs( require( 'Module:Data' ).imageSize[args.type] ) do
if dataName == i then
if args.id then
for k, l in pairs( j ) do
if args.id:lower() == k then
size.width = l[1]
size.height = l[2]
break
end
end
else
size.width = j[1][1]
size.height = j[1][2]
end
break
end
end
end
size.width = args.width or size.width or mw.getCurrentFrame():callParserFunction( '#imgw', fileName )
size.height = args.height or size.height or mw.getCurrentFrame():callParserFunction( '#imgh', fileName )
local scale = args.scale or '1'
local fileSize = math.ceil( size.width * scale ) .. 'x' .. math.ceil( size.height * scale ) .. 'px'
local fileAlign = args.align or 'center'
local fileLink = args.link and rtext.link{ name=args.name, data=true }.wiki .. '|' .. rtext.link{ name=args.name, data=true }.disp or ''
return '[[Image:' .. fileName .. '|' .. fileSize .. '|' .. fileAlign .. '|link=' .. fileLink .. ']]'
end
return p