Модуль:Tl
Материал из Указатель частей и соединений РККА 1941-1945
Для документации этого модуля может быть создана страница Модуль:Tl/doc
local p = {} function p.tlf (frame) local args = frame:getParent().args args ['#code'] = args ['#code'] or 'y' args ['#edit'] = args ['#edit'] or 'n' args ['#icon'] = args ['#icon'] or 'n' return p.tlexec (args,frame) end function p.tl (frame) local args = frame:getParent().args args ['#code'] = args ['#code'] or 'n' args ['#edit'] = args ['#edit'] or 'y' args ['#icon'] = args ['#icon'] or 'y' return p.tlexec (args,frame) end function p.lg (frame) local args = frame.args return p.tlexec (args,frame) end function p.tlexec (args,frame) local yesno = require('Module:Yesno') local code = yesno (args['#code'], true) local icon = yesno (args['#icon'], true) local edit = yesno (args['#edit'], false) local talk = yesno (args['#talk'], false) local subst = yesno (args['#subst'], true) local hiddenwiki = yesno (args['#wh'], true) local compact = yesno (args['#compact'], args['#compact']) local outformat = yesno (args['#output'],args['#output']) if outformat == true then outformat = '$t → <samp>$r</samp>' elseif outformat == 'tdtd' then outformat = '<tr><td>$t</td><td><samp>$r</samp></td><tr>' end local target = args[1] or 'tl' local debugs = '' local splitarget = mw.text.split(target,':') local wiki, namesp, pagename, titarget if #splitarget > 1 and splitarget[1] ~= '' and mw.ustring.lower(mw.ustring.sub(splitarget[1],1,1)) ~= mw.ustring.upper(mw.ustring.sub(splitarget[1],1,1)) then -- if mw.site.interwikiMap('')[splitarget[1]] then -- появится лишь в 1.25. Пока проверям, что не изменился регистр if mw.title.makeTitle( '', 'A', '', splitarget[1] )['fullText'] == mw.ustring.lower(splitarget[1]) ..':' .. 'A' then wiki = splitarget[1] .. ':' table.remove(splitarget, 1) else wiki = '' end else wiki = '' end if #splitarget > 1 then if splitarget[1] == '' then namesp = 0 table.remove(splitarget, 1) elseif splitarget[1] == '#invoke' then namesp = 828 table.remove(splitarget, 1) elseif mw.site.namespaces[splitarget[1]] then namesp = mw.site.namespaces[splitarget[1]]['id'] table.remove(splitarget, 1) else namesp = 10 end else namesp = 10 end pagename = table.concat (splitarget, ':') titarget = wiki .. mw.site.namespaces[namesp]['canonicalName'] .. ':' .. pagename local talktarget if mw.site.namespaces[namesp]['isSubject'] then talktarget = wiki .. mw.site.namespaces[namesp]['talk']['canonicalName'] .. ':' .. pagename end if mw.ustring.sub (titarget,1,1) ~= ':' then titarget = ':' .. titarget end -- titarget - ссылка -- wiki - интервики (с двоеточием) или пусто -- namesp - номер пространства -- pagename - имя без интервики и пространства local showname = mw.site.namespaces[namesp]['canonicalName'] .. ':' .. pagename if code then res = '<code>' else res = '' end res = res .. '<span class="wp-templatelink"><span class="wp-templatelink-syntax">' if compact then -- skip elseif namesp == 8 or namesp == 10 or namesp == 206 or namesp == 828 then -- MediaWiki, Template, HTML, Module res = res .. '{{' showname = pagename else res = res .. '[[' end res = res .. '</span>' if subst then res = res .. '[[wp:Help:Substitution|subst]]<span class="wp-templatelink-syntax">:</span>' end if wiki ~= '' and not hiddenwiki and not compact then res = res .. '[[:' .. wiki ..'|' .. wiki .. ']]' end if compact then -- skip elseif namesp == 828 then if icon then res = res .. '<img src="{{filepath:Lua-logo-nolabel.svg}}" style="height:1em" /> ' else res = res .. '#invoke:' end elseif namesp == 8 then if icon then res = res .. '<i class="fa fa-cog" style="color:#006699"></i> ' else res = 'MediaWiki:' end elseif namesp == 206 then if icon then res = res .. '<i class="fa fa-globe" style="color:#006699"></i> ' else res = 'HTML:' end elseif namesp == 14 then if icon then res = res .. '<i class="fa fa-tag fa-flip-horizontal" style="color:#006699"></i> ' else res = 'Category:' end showname = pagename elseif namesp == 4 then if icon then res = res .. '<i class="fa fa-book" style="color:#006699"></i> ' else res = 'Project:' end showname = pagename elseif namesp == 2 then if icon then res = res .. '<i class="fa fa-user" style="color:#006699"></i> ' else res = 'User:' end showname = pagename end if compact then showname = compact end res = res .. '[[' .. titarget .. '|' .. showname .. ']]' local argu = {} for k, v in ipairs (args) do argu[k-1] = v -- argu[0] is defined if k ~= 1 then res = res .. '<span class="wp-templatelink-syntax">|</span>' .. v end end for k, v in pairs (args) do if type (k) == 'string' then if mw.ustring.sub (k,1,1) == '#' then if mw.ustring.sub (k,2,2) ~= '#' then k = 0 else k = mw.ustring.sub (k,2) end end else k = k-1 end if not argu[k] then argu[k] = v res = res .. '<span class="wp-templatelink-syntax">|</span>' .. k .. '<span class="wp-templatelink-syntax">=</span>' .. v end end argu[0]=nil res = res .. '<span class="wp-templatelink-syntax">' if compact then -- skip elseif namesp == 8 or namesp == 10 or namesp == 206 or namesp == 828 then -- MediaWiki, Template, HTML, Module res = res .. '}}' else res = res .. ']]' end res = res .. '</span></span>' if code then res = res .. '</code>' end if edit then res = res .. '<small class=plainlinks> [' .. tostring(mw.uri.fullUrl( titarget, 'action=edit' )) .. ' <i class="fa fa-edit"></i>]</small>' end if talk and talktarget then res = res .. '<small class=plainlinks> [[' .. talktarget .. '|<i class="far fa-comment"></i>]]</small>' end if outformat then res = mw.ustring.gsub (outformat, '%$[tr]', function (match) if match == '$t' then return res elseif match == '$r' then return frame:expandTemplate {title=titarget,args=argu} end end ) end return res end function p.Demo (frame) local yesno = require('Module:Yesno') local args = frame:getParent().args local stro = args[1] -- local outformat = args['#output'] or '$t → <samp>$r</samp>' local outformat = yesno (args['#output'],args['#output']) if outformat == true then outformat = '$t → <samp>$r</samp>' elseif outformat == 'tdtd' then outformat = '<tr><td>$t</td><td><samp>$r</samp></td><tr>' end local res res = frame:preprocess (mw.text.decode(mw.text.unstrip(stro))) if outformat then res = mw.ustring.gsub (outformat, '%$[tr]', function (match) if match == '$t' then return stro elseif match == '$r' then return res end end ) end return res end function p.z () local h = { 'F', '12 часов:время', ':F', 'Template:F', 'Module:F', '#invoke:F', 'Help:F', 'wp:F', 'wp::F', 'wp:Template:F', 'wp:Module:F', 'wp:Help:F', 'F/a', ':F/a', 'Template:F/a', 'Module:F/a', 'Help:F/a', 'wp:F/a', 'wp::F/a', 'wp:Template:F/a', 'wp:Module:F/a', 'wp:Help:F/a',} src = '' res = '' res1 = '' res2p = '' res2 = '' res3p = '' res3 = '' for k, v in ipairs (h) do res = res .. v .. ' -- ' .. p.tlexec ({v, ['#edit']='yes'}) .. '\n' end return res end return p