Модуль:Tl: различия между версиями
Перейти к навигации
Перейти к поиску
StasR (обсуждение | вклад) м (1 версия импортирована) |
WikiSysop (обсуждение | вклад) Нет описания правки |
||
(не показана 1 промежуточная версия 1 участника) | |||
Строка 28: | Строка 28: | ||
local edit = yesno (args['#edit'], false) | local edit = yesno (args['#edit'], false) | ||
local talk = yesno (args['#talk'], false) | local talk = yesno (args['#talk'], false) | ||
local history = yesno (args['#history'], true) | |||
local subst = yesno (args['#subst'], true) | local subst = yesno (args['#subst'], true) | ||
local hiddenwiki = yesno (args['#wh'], true) | local hiddenwiki = yesno (args['#wh'], true) | ||
local compact = yesno (args['#compact'], args['#compact']) | local compact = yesno (args['#compact'], args['#compact']) | ||
local outformat = yesno (args['#output'],args['#output']) | local outformat = yesno (args['#output'],args['#output']) | ||
if outformat == true then | if outformat == true then | ||
Строка 91: | Строка 92: | ||
res = res .. '<span class="wp-templatelink"><span class="wp-templatelink-syntax">' | res = res .. '<span class="wp-templatelink"><span class="wp-templatelink-syntax">' | ||
if compact then | if compact then | ||
-- skip | -- skip | ||
elseif namesp == 8 or namesp == 10 or namesp == 206 or namesp == 828 then -- MediaWiki, Template, HTML, Module | elseif namesp == 8 or namesp == 10 or namesp == 206 or namesp == 828 then -- MediaWiki, Template, HTML, Module | ||
res = res .. '{{' | res = res .. '{{' | ||
Строка 106: | Строка 107: | ||
end | end | ||
if compact then | if compact then | ||
-- skip | -- skip | ||
elseif namesp == 828 then | elseif namesp == 828 then | ||
if icon then | if icon then | ||
-- res = res .. '<img src="{{filepath:Lua-logo-nolabel.svg}}" style="height:1em" /> ' | |||
res = res .. '[[file:Lua-logo-nolabel.svg|class=height1em|link=]] ' | |||
else | else | ||
res = res .. '#invoke:' | res = res .. '#invoke:' | ||
Строка 130: | Строка 132: | ||
end | end | ||
res = res .. '[[' .. titarget .. '|' .. showname .. ']]' | res = res .. '[[' .. titarget .. '|' .. showname .. ']]' | ||
local argu = {} | local argu = {} | ||
for k, v in ipairs (args) do | for k, v in ipairs (args) do | ||
Строка 141: | Строка 143: | ||
if type (k) == 'string' then | if type (k) == 'string' then | ||
if mw.ustring.sub (k,1,1) == '#' then | if mw.ustring.sub (k,1,1) == '#' then | ||
if mw.ustring.sub (k,2,2) ~= '#' then | if mw.ustring.sub (k,2,2) ~= '#' then | ||
k = 0 | k = 0 | ||
else | else | ||
Строка 152: | Строка 154: | ||
if not argu[k] then | if not argu[k] then | ||
argu[k] = v | argu[k] = v | ||
res = res .. '<span class="wp-templatelink-syntax">|</span>' .. k .. '<span class="wp-templatelink-syntax">=</span>' .. v | res = res .. '<span class="wp-templatelink-syntax">|</span>' .. k .. '<span class="wp-templatelink-syntax">=</span>' .. v | ||
end | end | ||
end | end | ||
Строка 158: | Строка 160: | ||
res = res .. '<span class="wp-templatelink-syntax">' | res = res .. '<span class="wp-templatelink-syntax">' | ||
if compact then | if compact then | ||
-- skip | -- skip | ||
elseif namesp == 8 or namesp == 10 or namesp == 206 or namesp == 828 then -- MediaWiki, Template, HTML, Module | elseif namesp == 8 or namesp == 10 or namesp == 206 or namesp == 828 then -- MediaWiki, Template, HTML, Module | ||
res = res .. '}}' | res = res .. '}}' | ||
Строка 169: | Строка 171: | ||
end | end | ||
if edit then | if edit then | ||
res = res .. '<small class=plainlinks> [' .. tostring(mw.uri.fullUrl( titarget, 'action=edit' )) .. | res = res .. '<small class=plainlinks> [' .. tostring(mw.uri.fullUrl( titarget, 'action=edit' )) .. | ||
' <i class="fa fa-edit"></i>]</small>' | ' <i class="fa fa-edit"></i>]</small>' | ||
end | |||
if history then | |||
res = res .. '<small class=plainlinks> [' .. tostring(mw.uri.fullUrl( titarget, 'action=history' )) .. | |||
' <i class="fa fa-history"></i>]</small>' | |||
end | end | ||
if talk and talktarget then | if talk and talktarget then | ||
res = res .. '<small class=plainlinks> [[' .. talktarget .. | res = res .. '<small class=plainlinks> [[' .. talktarget .. | ||
'|<i class="fa fa-comment-o"></i>]]</small>' | '|<i class="fa fa-comment-o"></i>]]</small>' | ||
end | end | ||
if outformat then | if outformat then | ||
res = mw.ustring.gsub (outformat, '%$[tr]', | res = mw.ustring.gsub (outformat, '%$[tr]', | ||
function (match) | function (match) | ||
if match == '$t' then | if match == '$t' then | ||
Строка 188: | Строка 194: | ||
end | end | ||
) | ) | ||
end | end | ||
return res | return res | ||
Строка 210: | Строка 216: | ||
res = frame:preprocess (mw.text.decode(mw.text.unstrip(stro))) | res = frame:preprocess (mw.text.decode(mw.text.unstrip(stro))) | ||
if outformat then | if outformat then | ||
res = mw.ustring.gsub (outformat, '%$[tr]', | res = mw.ustring.gsub (outformat, '%$[tr]', | ||
function (match) | function (match) | ||
if match == '$t' then | if match == '$t' then | ||
Строка 219: | Строка 225: | ||
end | end | ||
) | ) | ||
end | end | ||
return res | return res | ||
end | end | ||
function p.z () | 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', | 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',} | '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 = '' | src = '' | ||
Строка 238: | Строка 244: | ||
end | end | ||
return res | return res | ||
end | end | ||
return p | return p |
Текущая версия от 20:35, 21 октября 2023
Для документации этого модуля может быть создана страница Модуль: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 history = yesno (args['#history'], true)
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" /> '
res = res .. '[[file:Lua-logo-nolabel.svg|class=height1em|link=]] '
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
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 history then
res = res .. '<small class=plainlinks> [' .. tostring(mw.uri.fullUrl( titarget, 'action=history' )) ..
' <i class="fa fa-history"></i>]</small>'
end
if talk and talktarget then
res = res .. '<small class=plainlinks> [[' .. talktarget ..
'|<i class="fa fa-comment-o"></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