Модуль:Надстрочное предупреждение: различия между версиями
Перейти к навигации
Перейти к поиску
(вывод забыл) |
(вроде теперь должно в базовом виде работать) |
||
Строка 21: | Строка 21: | ||
-- Форматирование ссылок как в шаблоне | -- Форматирование ссылок как в шаблоне | ||
− | local function getLink( link, | + | local function getLink( link, text, comment ) |
− | |||
− | |||
if comment then | if comment then | ||
local delink = require( 'Module:Delink' )._delink; | local delink = require( 'Module:Delink' )._delink; | ||
Строка 29: | Строка 27: | ||
:attr( 'style', 'border-bottom:1px dotted;' ) | :attr( 'style', 'border-bottom:1px dotted;' ) | ||
:attr( 'title', delink( comment ) ) | :attr( 'title', delink( comment ) ) | ||
− | :wikitext( | + | :wikitext( text ) |
text = tostring( tag ) | text = tostring( tag ) | ||
Строка 91: | Строка 89: | ||
-- Вывод надстрочного предупреждения | -- Вывод надстрочного предупреждения | ||
− | local tag = mw.html.create( ' | + | local tag = mw.html.create( 'sup' ) |
:addClass( 'noprint' ) | :addClass( 'noprint' ) | ||
:attr( 'style', 'white-space:nowrap' ) | :attr( 'style', 'white-space:nowrap' ) | ||
tag | tag | ||
:wikitext( '[' ) -- [ | :wikitext( '[' ) -- [ | ||
− | :wikitext( getLink( args.link, args. | + | :wikitext( getLink( args.link, args.text, comment ) ) |
:wikitext( getTalkLink( args.talk ) ) | :wikitext( getTalkLink( args.talk ) ) | ||
:wikitext( ']' ) -- ] | :wikitext( ']' ) -- ] |
Версия от 00:03, 15 декабря 2022
Для документации этого модуля может быть создана страница Модуль:Надстрочное предупреждение/doc
require( 'strict' );
local p = {}
-- Форматирование выделяемого шаблоном текста
local function getSpanText( text, style )
style = style or 'background:#ffeaea; color:#444444;';
local tag = mw.html.create( 'span' )
:attr( 'style', style )
:wikitext( text )
return tostring( tag )
end
-- Форматирование даты как в шаблоне
local function getDate( day, month, year )
local timestamp = year .. '-' .. month .. '-' .. day
return mw.getContentLanguage():formatDate( 'j xg Y', timestamp )
end
-- Форматирование ссылок как в шаблоне
local function getLink( link, text, comment )
if comment then
local delink = require( 'Module:Delink' )._delink;
local tag = mw.html.create( 'span' )
:attr( 'style', 'border-bottom:1px dotted;' )
:attr( 'title', delink( comment ) )
:wikitext( text )
text = tostring( tag )
end
if link then
return string.format( '[[%s|%s]]', link, text )
end
return text
end
-- Форматирование ссылки на обсуждение как в шаблоне
local function getTalkLink( page )
if not page then return '' end
-- Страница обсуждения для текущей статьи в случае отсутствия якоря
if not mw.ustring.find( page, '#' ) then
page = mw.title.getCurrentTitle().talkPageTitle .. '#' .. page
end
return string.format( ' ([[%s|обс.]]', page )
end
-- TODO: Поддержка подстановки без Unsubst
function p.subst( frame )
local mTemplateInvocation = require( 'Module:Template invocation' )
local name = mTemplateInvocation.name( frame:getParent():getTitle() )
return mTemplateInvocation.invocation( name )
end
--
-- Модуль на замену шаблону «Надстрочное предупреждение»
--
function p.main( frame )
local getArgs = require( 'Module:Arguments' ).getArgs;
local args = getArgs( frame );
local result = '';
-- Поддержка подстановки
if mw.isSubsting() then
return p.subst( frame )
end
-- Вывод ошибки
if not args.text then
return '<strong class="error noprint">[[Модуль:Надстрочное предупреждение#Использование|Ошибка]]: не задан параметр <code>text</code></strong>'
end
-- Поддержка параметра {{{span-text|}}}
if args[ 'span-text' ] then
result = result .. getSpanText( args[ 'span-text' ], args[ 'span-style' ] )
end
-- Поддержка параметра {{{comment|}}}
local comment = args.comment or args[ 'comment-default' ]
if args.day or args.month or args.year then
comment = comment .. ' (' .. getDate( args.day, args.month, args.year ) .. ')'
end
-- Вывод надстрочного предупреждения
local tag = mw.html.create( 'sup' )
:addClass( 'noprint' )
:attr( 'style', 'white-space:nowrap' )
tag
:wikitext( '[' ) -- [
:wikitext( getLink( args.link, args.text, comment ) )
:wikitext( getTalkLink( args.talk ) )
:wikitext( ']' ) -- ]
result = result .. tostring( tag )
-- TODO: проверка для [[Категория:Википедия:Надстрочные предупреждения с некорректно заданной датой]]
-- Поддержка параметра {{{anchor|}}}
if args.anchor then
local anchor = require( 'Module:Якорь' ).main;
result = anchor{ visible = true, text = result, args.anchor }
end
-- TODO: Установка категорий
if args.nocat or mw.title.getCurrentTitle().namespace ~= 0 then
return result
end
return result
end
return p