Mòdul:Gallery

Icona de documentació de mòdul Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]

Mòdul Gallery (codi · ús · discussió · proves · tests · casos prova | subpàgines · enllaços)

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Implementa {{galeria}}

Seguiment de categories

modifica

-- This module implements {{gallery}}local p = {}local templatestyles = 'Module:Gallery/styles.css'local yesno = require('Module:Yesno')local function trim(s)return mw.ustring.gsub(mw.ustring.gsub(s, '%s', ' '), '^%s*(.-)%s*$', '%1')endlocal tracking, previewlocal function checkarg(k,v)if k and type(k) == 'string' thenif k == 'align' or k == 'state' or k == 'style' or k == 'title' or k == 'títol' ork == 'width' or k == 'amplada' or k == 'alçada' or k == 'height' or k == 'lines' or k == 'línies' or k == 'whitebg' ork == 'mode' or k == 'footer' or k == 'peu' or k == 'perrow' or k == 'noborder' ork:match('^alt%d+$') or k:match('^%d+$') then-- validelseif k == 'captionstyle' thenif not v:match('^text%-align%s*:%s*center[;%s]*$') thentable.insert(tracking, '[[Categoria:Pàgines que utilitzen la galeria amb el paràmetre captionstyle]]')endelse-- invalidlocal vlen = mw.ustring.len(k)k = mw.ustring.sub(k, 1, (vlen < 25) and vlen or 25) k = mw.ustring.gsub(k, '[^%w\-_ ]', '?')table.insert(tracking, '[[Categoria:Pàgines que utilitzen la galeria amb paràmetres desconeguts|' .. k .. ']]')table.insert(preview, '"' .. k .. '"')endendendfunction p.gallery(frame)-- If called via #invoke, use the args passed into the invoking template.-- Otherwise, for testing purposes, assume args are being passed directly in.local origArgs = (type(frame.getParent) == 'function') and frame:getParent().args or frame        -- ParserFunctions considers the empty string to be false, so to preserve the previous     -- behavior of {{gallery}}, change any empty arguments to nil, so Lua will consider    -- them false too.    local args = {}    tracking, preview = {}, {}    for k, v in pairs(origArgs) do    if v ~= '' then    args[k] = v    checkarg(k,v)    endendif (args.mode or '') == 'packed' and (args.align or '') == '' thenargs.align = 'center'endlocal tbl = mw.html.create('div')tbl:addClass('mod-gallery')    if args.state thentbl:addClass('mod-gallery-collapsible'):addClass('collapsible'):addClass(args.state)endif args.style thentbl:cssText(args.style)elsetbl:addClass('mod-gallery-default')endif args.align thentbl:addClass('mod-gallery-' .. args.align:lower())endlocal tit = args.title or args['títol']if tit thentbl:tag('div'):addClass('title'):tag('div'):wikitext(tit)endlocal gargs = {}gargs['class'] = 'nochecker' .. (args.noborder and '' or ' bordered-images')gargs['widths'] = tonumber(args.width) or tonumber(args.amplada) or 180gargs['heights'] = tonumber(args.height) or tonumber(args['alçada']) or 180gargs['style'] = args.captionstylegargs['perrow'] = args.perrowgargs['mode'] = args.modeif yesno(args.whitebg or 'yes') thengargs['class'] = gargs['class'] .. ' whitebg'endlocal gallery = {}local imageCount = math.ceil(#args / 2)    for i = 1, imageCount dolocal img = trim(args[i*2 - 1] or '')local caption = trim(args[i*2] or '')local alt = trim(args['alt' .. i] or '')if img ~= '' thentable.insert(gallery, img .. (alt ~= '' and ('|alt=' .. alt) or '') .. '|' .. caption )endendtbl:tag('div'):addClass('main'):tag('div'):wikitext(frame:extensionTag{ name = 'gallery', content = '\n' .. table.concat(gallery,'\n'), args = gargs})        local foot = args.footer or args.peuif foot thentbl:tag('div'):addClass('footer'):tag('div'):wikitext(foot)endlocal trackstr = (#tracking > 0) and table.concat(tracking, '') or ''if #preview > 0 thentrackstr = require('Module:If preview')._warning({'Paràmetres desconeguts ' .. table.concat(preview, '; ') .. '.'}) .. trackstrendreturn frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(tbl) .. trackstrendreturn p