Modulo:Babel

Dokumentado Dokumentado


Ŝablona programadoDiskutojLuaTestojSubpaĝoj
ModuloEsperantoEnglish

Modulo:Dokumentado


Se vi havas demandon pri ĉi tiu Lua-modulo, tiam vi povas demandi en la diskutejo pri Lua-moduloj. La Intervikiaj ligiloj estu metataj al Vikidatumoj. (Vidu Helpopaĝon pri tio.)
-- Babel -- 20220530function subtitle(text)-- This function builds subtitles in the boxlocal sub_title = mw.html.create('table')  :css('text-align','center')  :css('width','100%')  :css('margin','0 auto')local row =  sub_title:tag('tr')local sub_title_cell =  row:tag('th')   :css('background-color','#EEFFCC')   :css('border','1px dotted #FFCC99')   :css('padding','0.3em')      :wikitext(text)   :done()return tostring(sub_title)endfunction placeholder(text)-- This function builds placeholders in the boxlocal height = "45px"local t1 = tonumber(text)if t1 thenheight = t1 .. ".px"endlocal t = "&nbsp;"local place = mw.html.create('table')  :css('text-align','center')  :css('width','100%')  :css('margin','0 auto')local row =  place:tag('tr')local place_cell =  row:tag('th')   :css('height',height)   :css('padding','0.3em')      :wikitext(t)   :done()return tostring(place)endfunction line (text)-- This function builds lines in the boxlocal line_div = mw.html.create('div')   :css('float','left')   :css('width','238px')   :css('height','1.5px')   :css('margin','1px')   :css('background-color','#EEEEEE')   :css('border','1px solid #EEEEEE')   :wikitext(text)   :done()return tostring(line_div)endfunction beginonly (text,s,c)-- changes html codes for the tabel's beginning into wiki codes-- removes the end of the table-- htmllocal b1 = '<table class="userboxes"'local b2 = '><tr><th colspan="' .. s .. '" style="background%-color:' .. c .. ';text%-align:center">'local b3 = "</th></tr><tr>"-- wiki codelocal b1w = '{|  class="userboxes"'local b2w = '\n|-\n! colspan="' .. s .. '" style="background-color:' .. c .. ';text-align:center" | 'local b3w = "\n<tr>"local r = textr = mw.ustring.gsub(r,b1,b1w,1) -- <table ... -> {| ...r = mw.ustring.gsub(r,b2,b2w,1) -- <tr><th> ... -> |- !r = mw.ustring.gsub(r,b3,b3w,1) -- </tr><tr> -> <tr>r = mw.ustring.sub(r,1,-9)      -- </table> -> nothingreturn rendlocal p = {}function p._babel_x(babels,args)-- this function builds the box used by the {{Babel-x}} templateargs.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" args.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" args['extra-css'] = 'background-color:#FFFFFF;'return p._babel(babels,args)endfunction p._babel_l(b,args)-- this function builds the box used by the {{BabelLandoj}} and {{BabelDevenLoĝLoko}} templateslocal babels = {}-- copies some named parameters from {{BabelLandoj}} into unnamed for the modullocal i = 1for k, v in pairs(args) dolocal x = args['l' .. i]if type(x) == "string" thenx = mw.text.trim(x)endif x ~= "" thenbabels[i] = xi = i + 1endendif args['common box'] == "yes" or args['komuna kesto'] =="jes" thenargs.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" args.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" args['extra-css'] = 'background-color:#FFFFFF;'--shows it like the {{Babel}} templatereturn p._babel(babels,args)else-- shows it like the old {{BabelLandoj}} and {{BabelDevenLoĝLoko}}local empty = {}empty.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" empty.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" empty['extra-css'] = 'background-color:#FFFFFF;'empty.align = args.align or args.flosolocal align = "float-right" -- for the complete boxlocal align2 = "right"      -- for the internal box if empty.align == "left" thenalign = "float-left"align2 = "left"end-- creates the external tablelocal ret = mw.html.create('table'):css('border','none'):css('width','100px'):addClass(align)local row1 = ret:tag('tr')local bab = row1:tag('td')-- puts the babel information into the first table celllocal bab_cell = p._babel(babels, empty)bab:wikitext(bab_cell):done()local k = args.kat or 'jes'local frame = mw.getCurrentFrame()-- code for the template {{DevenLoĝLoko}}if args.devenlando ~= nil and args.devenlando ~= "" then-- creates the second table cell    local row2 = ret:tag('tr')    local der = row2:tag('td')local dl1 = args.devenlandolocal dl2 = args.devenloko or ""local dl3 = args.devenlokspeco or ""local ll1 = args['loĝlando'] or ""local ll2 = args['loĝloko'] or ""local ll3 = args['loĝlokspeco'] or ""local n = args.nomo or ""der:wikitext( frame:preprocess('{{DevenLoĝLoko|devenlando=' .. dl1 .. '|devenloko=' .. dl2 .. '|devenlokspeco=' .. dl3 .. '|loĝlando='.. ll1 .. '|loĝloko=' .. ll2 .. '|loĝlokspeco=' .. ll3 .. '|nomo=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes|floso=' .. align2 .. '}}') ):done()endreturn tostring(ret)endend -- babel_lfunction p._babel_l2(b,args)-- this function builds the box used by the {{BabelLoko}} templatelocal babels = {}-- copies some named parameters from {{BabelLoko}} into unnamed for the modullocal i = 1for k, v in pairs(args) dolocal x = args['l' .. i]if type(x) == "string" thenx = mw.text.trim(x)endif x ~= "" thenbabels[i] = xi = i + 1endendif args['common box'] == "yes" or args['komuna kesto'] =="jes" thenargs.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" args.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" args['extra-css'] = 'background-color:#FFFFFF;'args['flag'] = 'no'--shows it like the {{Babel}} templatereturn p._babel(babels,args)else-- shows it like the old {{BabelLoko}}local empty = {}empty.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" empty.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" empty['extra-css'] = 'background-color:#FFFFFF;'empty.align = args.align or args.flosolocal align = "float-right"if empty.align == "left" thenalign = "float-left"end-- creates the external tablelocal ret = mw.html.create('table'):css('border','none'):css('width','100px'):addClass(align)local row1 = ret:tag('tr')local bab = row1:tag('td')-- puts the babel information into the first table celllocal bab_cell = p._babel(babels, empty)bab:wikitext(bab_cell):done()local k = args.kat or 'jes'local frame = mw.getCurrentFrame()-- code for the template {{Loko}}if args.lando ~= nil and args.lando ~= "" then-- creates the second table cell    local row2 = ret:tag('tr')    local der = row2:tag('td')local l1 = args.landolocal l2 = args.loko or ""local n = args.Nomo or ""der:wikitext(frame:preprocess('{{Loko|1=' .. l1 .. '|2=' .. l2 .. '|3=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes}}') ):done()endreturn tostring(ret)endend -- babel_l2function p._babel_l3(b,args)-- this function builds the box used by the {{BabelLando}} templatelocal babels = {}-- copies some named parameters from {{BabelLando}} into unnamed for the modullocal i = 1for k, v in pairs(args) dolocal x = args['l' .. i]if type(x) == "string" thenx = mw.text.trim(x)endif x ~= "" thenbabels[i] = xi = i + 1endendif args['common box'] == "yes" or args['komuna kesto'] =="jes" thenargs.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" args.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" args['extra-css'] = 'background-color:#FFFFFF;'--shows it like the {{Babel}} templatereturn p._babel(babels,args)else-- shows it like the old {{BabelLando}}local empty = {}empty.header = args.header or args.kaplinio or "[[Vikipedio:Babel]]" empty.footer = args.footer or args.piedlinio or "'''[[:Kategorio:Vikipediistoj laŭ lingvo]]'''" empty['extra-css'] = 'background-color:#FFFFFF;'empty.align = args.align or args.flosolocal align = "float-right" -- for the complete boxlocal align2 = "right"      -- for the internal box if empty.align == "left" thenalign = "float-left"align2 = "left"end-- creates the external tablelocal ret = mw.html.create('table'):css('border','none'):css('width','100px'):addClass(align)local row1 = ret:tag('tr')local bab = row1:tag('td')-- puts the babel information into the first table celllocal bab_cell = p._babel(babels, empty)bab:wikitext(bab_cell):done()local k = args.kat or 'jes'local frame = mw.getCurrentFrame()-- code for the template {{UzantoLando}}if args.lando ~= nil and args.lando ~= "" then-- creates the second table cell    local row2 = ret:tag('tr')    local der = row2:tag('td')local l1 = args.landolocal l2 = args.loko or ""local l3 = args.lokospeco or ""local n = args.nomo or "{{PAGENAME}}"der:wikitext( frame:preprocess('{{UzantoLando|lando=' .. l1 .. '|loko=' .. l2 .. '|lokospeco=' .. l3 ..  '|nomo=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes|floso=' .. align2 .. '}}') ):done()endreturn tostring(ret)endend -- babel_l3function p._babel(babels, args)  -- This function builds the babel box used by the {{babel}} template.local fl = args.align or args.floso-- variables for the marginslocal l = "1"local r = "0"if fl == "left" thenl = "0"r = "1"endlocal ret = mw.html.create('table'):addClass('userboxes'):css( {float = args.align or args.floso or 'right',['margin-left'] = l .. 'em',['margin-right'] = r .. 'em',['margin-bottom'] = (args.bottom or args['malsupra marĝeno'] or '0') .. 'em',width = (args.width or args['larĝo'] or '248') .. 'px',clear = args.align or args.floso or 'right',color = args.textcolor or args['teksta koloro'] or '#000000',border = (args.bordercolor or args['randkoloro'] or '#99B3FF') .. ' solid ' .. (args.solid or args['linilarĝo'] or 1) ..'px'} ) if (args.shadow and string.lower(args.shadow) == 'yes') or (args.ombro and string.lower(args.ombro) == 'jes')  thenret:css({ ['-webkit-box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)',  ['-moz-box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)',  ['box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' })end-- formats from {{Bordera radiuso}}  and the old {{Babel}}ret:css({ ['-webkit-border-radius'] = '0.6em',  ['-moz-border-radius'] = '0.6em',  ['border-radius'] = '0.6em' })ret:cssText( args['extra-css'] or '' ) local color = args.color or args.fonkoloro or 'inherit'local row1 = ret:tag('tr')local row2 = ret:tag('tr')local row3 = ret:tag('tr') local body_cells = row2:tag('td'):css('vertical-align', 'top !important')local userboxeslocal k = args.kat or 'jes'local frame = mw.getCurrentFrame()-- Special message for when first argument is blank; otherwise treat it as normalif babels[1] and babels[1]:find('%S') thenif mw.ustring.sub(babels[1],1,2) == "[[" thenbody_cells:wikitext(babels[1])elseif mw.ustring.sub(babels[1],1,2) == "{{" and mw.ustring.sub(babels[1],1,3) ~= "{{{" thenbody_cells:wikitext(babels[1])elseif mw.ustring.sub(babels[1],1,1) == "<" thenbody_cells:wikitext(babels[1])elseif mw.ustring.sub(babels[1],1,2) == "##" thenlocal v = mw.ustring.sub(babels[1],3)body_cells:wikitext(subtitle(v))elseif mw.ustring.sub(babels[1],1,2) == "--" thenlocal v = mw.ustring.sub(babels[1],3)body_cells:wikitext(placeholder(v))-- code for {{#Babel, because the parser analyzed this before Lua can workelseif mw.ustring.sub(babels[1],1,3) == "#b#" or mw.ustring.sub(babels[1],1,3) == "#B#"thenlocal v = mw.ustring.sub(babels[1],4) -- removes the internal links v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babela informo pri uzanto%]%]","",1)v = mw.ustring.gsub(v,"%[%[:Kategorio:Vikipediistoj laŭ_lingvo%|Serĉu uzulajn lingvojn%]%]","",1)v = '<div style="width:246px; float:left;">' .. v .. "</div>"body_cells:wikitext(v)elseif mw.ustring.sub(babels[1],1,1) == "~" thenbody_cells:wikitext(line())elseuserboxes = frame:preprocess('{{Uzulo|'..babels[1]..'|kat=' .. k .. '|babel-larĝo=jes|floso=left}}')endelseuserboxes = args.noboxestext or "''Ĉi tiu uzanto scipovas nek legi nek skribi iun ajn lingvon. [[Ŝablono:Babelejo/dokumentado|Helpo]] necesas.''"end body_cells:wikitext(userboxes)-- "remove" args[1] so it isn't looked at in the loop-- table.remove(args,1) doesn't produce desired resultbabels[1] = '' -- Keep track of how many columns are in this tablelocal col_span = 1for _, v in ipairs( babels ) do-- ! indicates a new cell should be createdif v:find('%S') and v ~= '!' thenif mw.ustring.sub(v,1,2) == "[[" thenbody_cells:wikitext(v)elseif mw.ustring.sub(v,1,2) == "{{" and mw.ustring.sub(v,1,3) ~= "{{{" thenbody_cells:wikitext(v)elseif mw.ustring.sub(v,1,1) == "<" thenbody_cells:wikitext(v)-- converts the text with ## at the begining into subtitleelseif mw.ustring.sub(v,1,2) == "##" thenv = mw.ustring.sub(v,3)body_cells:wikitext(subtitle(v))elseif mw.ustring.sub(v,1,2) == "--" thenv = mw.ustring.sub(v,3)body_cells:wikitext(placeholder(v))elseif mw.ustring.sub(v,1,1) == "~" thenbody_cells:wikitext(line())-- code for {{#Babel, because the parser analyzed this before Lua can workelseif mw.ustring.sub(v,1,3) == "#b#" or mw.ustring.sub(v,1,3) == "#B#"thenv = mw.ustring.sub(v,4) -- removes the internal links v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babela informo pri uzanto%]%]","",1)v = mw.ustring.gsub(v,"%[%[:Kategorio:Vikipediistoj laŭ_lingvo%|Serĉu uzulajn lingvojn%]%]","",1)v = '<div style="width:246px; float:left;">' .. v .. "</div>"body_cells:wikitext(v)elsebody_cells:wikitext( frame:preprocess('{{Uzulo|'..v..'|kat=' .. k .. '|babel-larĝo=jes|floso=left}}') )end-- Recycling body_cells for <td>elseif v and v == '!' thencol_span = col_span + 1body_cells:done()body_cells = row2:tag('td')endend if (args.header ~= "whitout") and (args.header ~= "sen") and (args.kaplinio ~= "sen") thenlocal header = args.header or args.kapliniorow1:tag('th'):css({ ['background-color'] = color,['text-align'] = 'center' }):attr('colspan',col_span):wikitext( header or '[[Vikipedio:Babelejo]]' ):done()end if (args.footer ~= "whitout") and (args.footer ~= "sen") and (args.piedlinio ~="sen") and args['begin only'] ~="yes" and args['nur komenco'] ~="jes" then local footer = args.footer or args.piedliniorow3:tag('td'):css({ ['background-color'] = color,['text-align'] = 'center' }):attr('colspan',col_span):wikitext( footer or '[[:Kategorio:Vikipediistoj laŭ lingvo|Uzantoj laŭ lingvo]]' ):done()end-- code for the templates {{UzantoLando}}, {{UzantoLandoFlago}} and {{Lando}}if args.lando ~= nil and args.lando ~= "" thenlocal l1 = args.landolocal l2 = args.loko or ""local l3 = args.lokospeco or ""local n = args.nomo or args.Nomo or ""local flag = args.flag or args.flago-- for title before the information about the user's countrylocal title = args['lando-titolo'] or ""if title ~= "" thenbody_cells:wikitext(subtitle(title))endif flag == "yes" or flag == "jes" or flag == nil or flag == "" then-- little box with flagbody_cells:wikitext( frame:preprocess('{{UzantoLando|lando=' .. l1 .. '|loko=' .. l2 .. '|lokospeco=' .. l3 .. '|nomo=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes|floso=left}}') )elseif flag == "no" or flago == "ne" then-- little box without flagbody_cells:wikitext( frame:preprocess('{{Loko|1=' .. l1 .. '|2=' .. l2 .. '|3=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes}}') )elseif mw.ustring.sub(flag,-4,-1) == ".jpg" or mw.ustring.sub(flag,-4,-1) == ".png"or mw.ustring.sub(flag,-4,-1) == ".svg" or mw.ustring.sub(flag,-5,-1) == ".jpeg" thenlocal f = flag body_cells:wikitext( frame:preprocess('{{UzantoLandoFlago|lando=' .. l1 .. '|loko=' .. l2 .. '|lokospeco=' .. l3 .. '|nomo=' .. n .. '|flagloko=' .. f .. '}}') )elsebody_cells:wikitext( frame:preprocess('{{UzantoLando|lando=' .. l1 .. '|loko=' .. l2 .. '|lokospeco=' .. l3 .. '|nomo=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes|floso=left}}') )endend-- code for the template {{DevenLoĝLoko}}if args.devenlando ~= nil and args.devenlando ~= "" thenlocal dl1 = args.devenlandolocal dl2 = args.devenloko or ""local dl3 = args.devenlokspeco or ""local ll1 = args['loĝlando'] or ""local ll2 = args['loĝloko'] or ""local ll3 = args['loĝlokspeco'] or ""local n = args.nomo or ""-- for title before the information about the user's countrieslocal title = args['devenlando-titolo'] or ""if title ~= "" thenbody_cells:wikitext(subtitle(title))endbody_cells:wikitext( frame:preprocess('{{DevenLoĝLoko|devenlando=' .. dl1 .. '|devenloko=' .. dl2 .. '|devenlokspeco=' .. dl3 .. '|loĝlando='.. ll1 .. '|loĝloko=' .. ll2 .. '|loĝlokspeco=' .. ll3 .. '|nomo=' .. n .. '|kat=' .. k .. '|babel-larĝo=jes|floso=left|marĝeno=0}}') )end-- code for the template {{UTC}}if args.UTC ~= nil and args.UTC ~= "" thenlocal u = args.UTC-- for title before the information about the user's UTClocal title = args['UTC-titolo'] or ""if title ~= "" thenbody_cells:wikitext(subtitle(title))endbody_cells:wikitext( frame:preprocess('{{UTC|' ..u .. '|kat=' .. k .. '|babel-larĝo=jes|floso=left}}') )end-- code for the template {{Uzanto SUL}}if args['sul-projekto'] ~= nil and args['sul-projekto'] ~= "" thenlocal p = args['sul-projekto']local l = args['sul-lingvo'] or ""-- for title before the information about the user's SULlocal title = args['sul-titolo'] or ""if title ~= "" thenbody_cells:wikitext(subtitle(title))endbody_cells:wikitext( frame:preprocess('{{Uzanto SUL|1=' .. l .. '|2=' .. p .. '|nocat=' .. k .. '|babel-larĝo=jes|floso=left}}') )end-- for special boxeslocal maxspec = 15if args['speciala kesto'] then-- for a title before the special boxlocal title = args['specialkesta titolo'] or ""if title ~= "" thenbody_cells:wikitext(subtitle(title))endlocal s = args['speciala kesto']body_cells:wikitext(s)endfor i = 2, maxspec dolocal s = args['speciala kesto' .. i] or ""if s ~="" then-- for a title before the special boxlocal title = args['specialkesta' .. i .. " titolo"] or ""if title ~= "" thenbody_cells:wikitext(subtitle(title))endbody_cells:wikitext(s)endend if args['special-boxes'] or args['specialaj kestoj'] thenlocal sp = args['special-boxes'] or args['specialaj kestoj']body_cells:wikitext(sp)end body_cells:done()local result = tostring(ret)-- change the html coding of the tabel's beginning into wiki code-- remove the end of the html coding of the tableif args['begin only'] =="yes" or args['nur komenco'] =="jes" thenlocal s = col_spanresult = beginonly (result,s,color) end return resultendlocal function processBabelArgs(args)-- This function processes a table of arguments and returns two tables: an array of portal names for processing by ipairs, and a table of-- the named arguments that specify style options, etc. We need to use ipairs because we want to list all the portals in the order-- they were passed to the template, but we also want to be able to deal with positional arguments passed explicitly, for example-- {{portal|2=Politics}}. The behaviour of ipairs is undefined if nil values are present, so we need to make sure they are all removed.args = type(args) == 'table' and args or {}local babels = {}local namedArgs = {}for k, v in pairs(args) doif type(k) == 'number' and type(v) == 'string' then -- Make sure we have no non-string babel names.table.insert(babels, k)elseif type(k) ~= 'number' thennamedArgs[k] = vendendtable.sort(babels)for i, v in ipairs(babels) dobabels[i] = args[v]endreturn babels, namedArgsend local function makeWrapper(funcName)-- Processes external arguments and sends them to the alia functions.return function (frame)-- If called via #invoke, use the args passed into the invoking-- template, or the args passed to #invoke if any exist. Otherwise-- assume args are being passed directly in from the debug console-- or from another Lua modulo.local origArgsif frame == mw.getCurrentFrame() thenorigArgs = frame:getParent().argsfor k, v in pairs(frame.args) doorigArgs = frame.argsbreakendelseorigArgs = frameend-- Trim whitespace and remove blank arguments.local args = {}for k, v in pairs(origArgs) doif type(v) == 'string' thenv = mw.text.trim(v)endif v ~= '' thenargs[k] = vendendreturn p[funcName](processBabelArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.endend local funcNames = {'babel', 'babel_x', 'babel_l', 'babel_l2', 'babel_l3'} for _, funcName in ipairs(funcNames) dop[funcName] = makeWrapper('_' .. funcName)endreturn p