Модуль:Shortcut: различия между версиями
Undid revision 1212853521 by Jdlrobson (talk) no, that class is exclusive to the module in which it appears |
Admin (обсуждение | вклад) м 1 версия импортирована |
||
| (не показаны 2 промежуточные версии 2 участников) | |||
| Строка 1: | Строка 1: | ||
require( 'strict' ) | |||
local p = {} | local p = {} | ||
local | local getArgs = require( 'Module:Arguments' ).getArgs | ||
local | local templateStylesPage = 'Module:Shortcut/styles.css' | ||
local errorCat = 'Википедия:Страницы с неправильно заполненным шаблоном Shortcut' | |||
local currentTitle = mw.title.getCurrentTitle() | |||
local headerSubpage = '/шапка' | |||
local imageParams = { 'ВП:ВП', 'Короткая ссылка-перенаправление' } | |||
local function isEmpty( val ) | |||
return val == nil or val == '' | |||
end | |||
local function getLink( val, nocat ) | |||
local category = not nocat and '[[Category:' .. errorCat .. ']]' or '' | |||
return string.format( '[[%s]]%s', val, category ) | |||
end | |||
local | local function getShortcut( val, nocat ) | ||
local thisTitle = mw.title.makeTitle( '', val ) | |||
-- No error category on header subpages | |||
if mw.ustring.find( mw.ustring.lower( currentTitle.prefixedText ), headerSubpage ) then | |||
nocat = true | |||
end | end | ||
if not thisTitle then | |||
return getLink( val, nocat ) | |||
end | end | ||
local doesNotEqualCurrent = not mw.title.equals( thisTitle, currentTitle ) | |||
local | if doesNotEqualCurrent and ( not thisTitle.redirectTarget or not mw.title.equals( thisTitle.redirectTarget, currentTitle ) ) then | ||
return getLink( val, nocat ) | |||
if | |||
end | end | ||
return string.format( '%s', val ) | |||
end | end | ||
function | local function parseList( args, element, anchors, nocat ) | ||
local | local list = mw.html.create( 'ul' ) | ||
local listIsEmpty = true | |||
for key, val in ipairs( args ) do | |||
local | local title = mw.ustring.gsub( mw.ustring.gsub( mw.text.trim( val ), "%[%[","" ), "%]%]", "" ) | ||
for | if title ~= '' then | ||
list:tag( 'li' ):wikitext( getShortcut( title, nocat ) ) | |||
if anchors then | |||
anchors:tag( 'span' ):attr( 'id', title ) | |||
end | |||
listIsEmpty = false | |||
end | end | ||
end | end | ||
element:node( list ) | |||
if listIsEmpty and not nocat then | |||
element:wikitext( '[[Category:' .. errorCat .. ']]' ) | |||
end | |||
end | |||
function p.indicator( frame ) | |||
local | local args = getArgs( frame ) | ||
local nocat = args[ 'nocat' ] or false | |||
if not isEmpty( args[ 1 ] ) and isEmpty( args[ '2' ] ) then | |||
args = mw.text.split( args[ 1 ], '/' ) | |||
end | end | ||
local result = mw.html.create( 'div' ) | |||
:addClass( 'ts-shortcut-indicator hlist inline' ) | |||
:wikitext( '[[File:OOjs UI icon articleRedirect-ltr-progressive.svg|20px|link=' .. table.concat( imageParams, '|' ) .. ']]' ) | |||
:wikitext( ' ' ) | |||
parseList( args, result, nil, nocat ) | |||
local content = frame:extensionTag{ | |||
name = 'templatestyles', | |||
args = { src = templateStylesPage }, | |||
} .. tostring( result ) | |||
return frame:extensionTag{ | |||
name = 'indicator', | |||
content = content, | |||
args = { name = '0-shortcut' }, | |||
} | |||
end | |||
function p.shortcut( frame ) | |||
local args = getArgs( frame ) | |||
local style = args[ 'style' ] or nil | |||
local nocat = args[ 'nocat' ] or false | |||
local result = mw.html.create( 'div' ) | |||
:addClass( 'ts-shortcut noprint' ) | |||
:attr( 'role', 'note' ) | |||
:attr( 'style', style ) | |||
local anchors = result:tag( 'div' ) | |||
:addClass( 'ts-shortcut-anchors' ) | |||
result:tag( 'div' ) | |||
:addClass( 'ts-shortcut-image' ) | |||
:wikitext( '[[File:OOjs UI icon articleRedirect-ltr-progressive.svg|20px|link=' .. table.concat( imageParams, '|' ) .. ']]' ) | |||
local shortcuts = result:tag( 'div' ) | |||
:addClass( 'ts-shortcut-list hlist' ) | |||
parseList( args, shortcuts, anchors, nocat ) | |||
return frame:extensionTag{ | |||
name = 'templatestyles', | |||
args = { src = templateStylesPage }, | |||
} .. tostring( result ) | |||
end | end | ||
return p | return p | ||
Текущая версия от 17:04, 22 июня 2026
Для документации этого модуля может быть создана страница Модуль:Shortcut/doc
require( 'strict' )
local p = {}
local getArgs = require( 'Module:Arguments' ).getArgs
local templateStylesPage = 'Module:Shortcut/styles.css'
local errorCat = 'Википедия:Страницы с неправильно заполненным шаблоном Shortcut'
local currentTitle = mw.title.getCurrentTitle()
local headerSubpage = '/шапка'
local imageParams = { 'ВП:ВП', 'Короткая ссылка-перенаправление' }
local function isEmpty( val )
return val == nil or val == ''
end
local function getLink( val, nocat )
local category = not nocat and '[[Category:' .. errorCat .. ']]' or ''
return string.format( '[[%s]]%s', val, category )
end
local function getShortcut( val, nocat )
local thisTitle = mw.title.makeTitle( '', val )
-- No error category on header subpages
if mw.ustring.find( mw.ustring.lower( currentTitle.prefixedText ), headerSubpage ) then
nocat = true
end
if not thisTitle then
return getLink( val, nocat )
end
local doesNotEqualCurrent = not mw.title.equals( thisTitle, currentTitle )
if doesNotEqualCurrent and ( not thisTitle.redirectTarget or not mw.title.equals( thisTitle.redirectTarget, currentTitle ) ) then
return getLink( val, nocat )
end
return string.format( '%s', val )
end
local function parseList( args, element, anchors, nocat )
local list = mw.html.create( 'ul' )
local listIsEmpty = true
for key, val in ipairs( args ) do
local title = mw.ustring.gsub( mw.ustring.gsub( mw.text.trim( val ), "%[%[","" ), "%]%]", "" )
if title ~= '' then
list:tag( 'li' ):wikitext( getShortcut( title, nocat ) )
if anchors then
anchors:tag( 'span' ):attr( 'id', title )
end
listIsEmpty = false
end
end
element:node( list )
if listIsEmpty and not nocat then
element:wikitext( '[[Category:' .. errorCat .. ']]' )
end
end
function p.indicator( frame )
local args = getArgs( frame )
local nocat = args[ 'nocat' ] or false
if not isEmpty( args[ 1 ] ) and isEmpty( args[ '2' ] ) then
args = mw.text.split( args[ 1 ], '/' )
end
local result = mw.html.create( 'div' )
:addClass( 'ts-shortcut-indicator hlist inline' )
:wikitext( '[[File:OOjs UI icon articleRedirect-ltr-progressive.svg|20px|link=' .. table.concat( imageParams, '|' ) .. ']]' )
:wikitext( ' ' )
parseList( args, result, nil, nocat )
local content = frame:extensionTag{
name = 'templatestyles',
args = { src = templateStylesPage },
} .. tostring( result )
return frame:extensionTag{
name = 'indicator',
content = content,
args = { name = '0-shortcut' },
}
end
function p.shortcut( frame )
local args = getArgs( frame )
local style = args[ 'style' ] or nil
local nocat = args[ 'nocat' ] or false
local result = mw.html.create( 'div' )
:addClass( 'ts-shortcut noprint' )
:attr( 'role', 'note' )
:attr( 'style', style )
local anchors = result:tag( 'div' )
:addClass( 'ts-shortcut-anchors' )
result:tag( 'div' )
:addClass( 'ts-shortcut-image' )
:wikitext( '[[File:OOjs UI icon articleRedirect-ltr-progressive.svg|20px|link=' .. table.concat( imageParams, '|' ) .. ']]' )
local shortcuts = result:tag( 'div' )
:addClass( 'ts-shortcut-list hlist' )
parseList( args, shortcuts, anchors, nocat )
return frame:extensionTag{
name = 'templatestyles',
args = { src = templateStylesPage },
} .. tostring( result )
end
return p