Дополнительные действия
DarkMuse (обсуждение | вклад) Новая страница: «-- <nowiki> local dependencyList = require( 'Module:DependencyList' ) local hatnote = require( 'Module:Hatnote' )._hatnote local mbox = require( 'Module:Mbox' )._mbox local i18n = require( 'Module:i18n' ):new() local TNT = require( 'Module:Translate' ):new() local lang = mw.getContentLanguage() local p = {} --- Wrapper function for Module:i18n.translate --- --- @param key string The translation key --- @return string If the key was not found, the key is re...» |
DarkMuse (обсуждение | вклад) Нет описания правки |
||
| (не показаны 3 промежуточные версии этого же участника) | |||
| Строка 1: | Строка 1: | ||
-- <nowiki> | -- <nowiki> | ||
local dependencyList = require( 'Module:DependencyList' ) | local dependencyList = require('Module:DependencyList') | ||
local hatnote = require( 'Module:Hatnote' )._hatnote | local hatnote = require('Module:Hatnote')._hatnote | ||
local mbox = require( 'Module:Mbox' )._mbox | local mbox = require('Module:Mbox')._mbox | ||
local i18n = require( 'Module:i18n' ):new() | local i18n = require('Module:i18n'):new() | ||
local TNT = require( 'Module:Translate' ):new() | local TNT = require('Module:Translate'):new() | ||
local lang = mw.getContentLanguage() | local lang = mw.getContentLanguage() | ||
local p = {} | local p = {} | ||
--- Wrapper function for Module:i18n.translate | --- Wrapper function for Module:i18n.translate | ||
| Строка 13: | Строка 12: | ||
--- @param key string The translation key | --- @param key string The translation key | ||
--- @return string If the key was not found, the key is returned | --- @return string If the key was not found, the key is returned | ||
local function t( key ) | local function t(key) | ||
return i18n:translate( key ) | return i18n:translate(key) | ||
end | end | ||
--- FIXME: This should go to somewhere else, like Module:Common | --- FIXME: This should go to somewhere else, like Module:Common | ||
| Строка 23: | Строка 21: | ||
--- @param key string The translation key | --- @param key string The translation key | ||
--- @return string If the key was not found in the .tab page, the key is returned | --- @return string If the key was not found in the .tab page, the key is returned | ||
local function translate( key, ... ) | local function translate(key, ...) | ||
local success, translation = pcall( TNT.format, 'Module:Documentation/i18n.json', key or '', ... ) | local success, translation = pcall(TNT.format, 'Module:Documentation/i18n.json', key or '', ...) | ||
if not success or translation == nil then | if not success or translation == nil then | ||
| Строка 33: | Строка 31: | ||
end | end | ||
function p.doc(frame) | |||
function p.doc( frame ) | |||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local page = args[1] or mw.ustring.gsub( title.fullText, '/[Dd]o[ck]u?$', '' ) | local page = args[1] or mw.ustring.gsub(title.fullText, '/[Dd]o[ck]u?$', '') | ||
local ret, cats, ret1, ret2, ret3 | local ret, cats, ret1, ret2, ret3 | ||
local pageType = title.namespace == 828 and translate( 'module' ) or translate( 'template' ) | local pageType = (title.namespace == 828) and translate('module') or translate('template') | ||
-- subpage header | -- subpage header | ||
if title.subpageText == 'doc' then | if title.subpageText == 'doc' then | ||
ret = mbox( | ret = mbox( | ||
translate( 'message_subpage_title', page ), | translate('message_subpage_title', page), | ||
translate( 'message_subpage_desc', page, pageType ), | translate('message_subpage_desc', page, pageType), | ||
{ icon = 'WikimediaUI-Notice.svg' } | { icon = 'WikimediaUI-Notice.svg' } | ||
) | ) | ||
if title.namespace == 10 then -- Template namespace | if title.namespace == 10 then -- Template namespace | ||
cats = '[[Category:' .. t( 'category_template_documentation' ) .. '|' .. title.baseText .. ']]' | cats = '[[Category:' .. t('category_template_documentation') .. '|' .. title.baseText .. ']]' | ||
ret2 = dependencyList._main() | ret2 = dependencyList._main() | ||
elseif title.namespace == 828 then -- Module namespace | elseif title.namespace == 828 then -- Module namespace | ||
cats = '[[Category:' .. t( 'category_module_documentation' ) .. '|' .. title.baseText .. ']]' | cats = '[[Category:' .. t('category_module_documentation') .. '|' .. title.baseText .. ']]' | ||
ret2 = dependencyList._main() | ret2 = dependencyList._main() .. require('Module:Module toc').main() | ||
else | else | ||
cats = '' | cats = '' | ||
| Строка 61: | Строка 57: | ||
end | end | ||
return tostring( ret ) .. ret2 .. cats | return tostring(ret) .. ret2 .. cats | ||
end | end | ||
-- template header | -- template header | ||
ret1 = '<div class="documentation">' | ret1 = '<div class="documentation">' | ||
ret2 = mw.html.create( nil ) | ret2 = mw.html.create(nil) | ||
:tag( 'div' ) | :tag('div') | ||
:addClass( 'documentation-header' ) | :addClass('documentation-header') | ||
:tag( 'span' ) | :tag('span') | ||
:addClass( 'documentation-title' ) | :addClass('documentation-title') | ||
:wikitext( lang:ucfirst( translate('message_documentation_title', pageType ) ) ) | :wikitext(lang:ucfirst(translate('message_documentation_title', pageType))) | ||
:done() | :done() | ||
:tag( 'span' ) | :tag('span') | ||
:addClass( 'documentation-links plainlinks' ) | :addClass('documentation-links plainlinks') | ||
:wikitext( | :wikitext( | ||
'[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' .. | '[[' .. tostring(mw.uri.fullUrl(page .. '/doc', {action='view'})) .. ' view]] ' .. | ||
'[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' .. | '[[' .. tostring(mw.uri.fullUrl(page .. '/doc', {action='edit'})) .. ' edit]] ' .. | ||
'[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' .. | '[[' .. tostring(mw.uri.fullUrl(page .. '/doc', {action='history'})) .. ' history]] ' .. | ||
'[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = 'purge' } ) ) .. ' purge]</span>]' | '[<span class="jsPurgeLink">[' .. tostring(mw.uri.fullUrl(title.fullText, { action = 'purge' })) .. ' purge]</span>]' | ||
) | ) | ||
:done() | :done() | ||
:done() | :done() | ||
:tag( 'div' ) | :tag('div') | ||
:addClass( 'documentation-subheader' ) | :addClass('documentation-subheader') | ||
:tag( 'span' ) | :tag('span') | ||
:addClass( 'documentation-documentation' ) | :addClass('documentation-documentation') | ||
:wikitext( translate( 'message_transclude_desc', page ) ) | :wikitext(translate('message_transclude_desc', page)) | ||
:done() | :done() | ||
:wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } ) | :wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} }) | ||
:done() | :done() | ||
ret3 = {} | ret3 = {} | ||
if args. | if args.iccupShared then | ||
--- Message box | --- Message box | ||
table.insert( ret3, | table.insert(ret3, | ||
mbox( | mbox( | ||
translate( | translate('message_shared_across', title.fullText, mw.uri.encode(tostring(title.text), 'PATH')), | ||
translate('message_shared_across_subtext', pageType), | |||
translate( | |||
{ icon = 'WikimediaUI-ArticleDisambiguation-ltr.svg' } | { icon = 'WikimediaUI-ArticleDisambiguation-ltr.svg' } | ||
) | ) | ||
) | ) | ||
--- Set category | --- Set category | ||
table.insert( ret3, '[[Category:' .. mw.ustring.format( t( 'category_shared_across' ), lang:ucfirst( pageType ) ) .. ']]' ) | table.insert(ret3, '[[Category:' .. mw.ustring.format(t('category_shared_across'), lang:ucfirst(pageType)) .. ']]') | ||
--- Interlanguage link | --- Interlanguage link | ||
for _, code in pairs{'ru', 'en'} do | |||
for _, code in pairs{ ' | |||
if lang:getCode() ~= code then | if lang:getCode() ~= code then | ||
table.insert( ret3, mw.ustring.format( '[[%s:%s]]', code, title.fullText ) ) | table.insert(ret3, mw.ustring.format('[[%s:%s]]', code, title.fullText)) | ||
end | end | ||
end | end | ||
| Строка 124: | Строка 111: | ||
if args.fromWikipedia then | if args.fromWikipedia then | ||
table.insert( ret3, | table.insert(ret3, | ||
mbox( | mbox( | ||
translate( | translate('message_from_wikipedia', title.fullText, mw.uri.encode(tostring(page), 'WIKI'), page), | ||
translate('message_from_wikipedia_subtext', pageType), | |||
translate( | |||
{ icon = 'WikimediaUI-Logo-Wikipedia.svg' } | { icon = 'WikimediaUI-Logo-Wikipedia.svg' } | ||
) | ) | ||
) | ) | ||
--- Set category | --- Set category | ||
table.insert( ret3, '[[Category:' .. mw.ustring.format( t( 'category_from_wikipedia' ), lang:ucfirst( pageType ) ) .. ']]' ) | table.insert(ret3, '[[Category:' .. mw.ustring.format(t('category_from_wikipedia'), lang:ucfirst(pageType)) .. ']]') | ||
end | end | ||
if title.namespace == 828 then | if title.namespace == 828 then | ||
-- Has config | -- Has config | ||
if mw.title.new( title.fullText .. '/config.json', 'Module' ).exists then | if mw.title.new(title.fullText .. '/config.json', 'Module').exists then | ||
table.insert( ret3, | table.insert(ret3, | ||
mbox( | mbox( | ||
translate( | translate('message_module_configuration', title.fullText, title.fullText), | ||
translate('message_module_configuration_subtext'), | |||
translate( 'message_module_configuration_subtext' ), | |||
{ icon = 'WikimediaUI-Settings.svg' } | { icon = 'WikimediaUI-Settings.svg' } | ||
) | ) | ||
| Строка 160: | Строка 135: | ||
-- Has localization | -- Has localization | ||
if mw.title.new( title.fullText .. '/i18n.json', 'Module' ).exists then | if mw.title.new(title.fullText .. '/i18n.json', 'Module').exists then | ||
table.insert( ret3, | table.insert(ret3, | ||
mbox( | mbox( | ||
translate( | translate('message_module_i18n', title.fullText, title.fullText), | ||
translate('message_module_i18n_subtext'), | |||
translate( 'message_module_i18n_subtext' ), | |||
{ icon = 'WikimediaUI-Language.svg' } | { icon = 'WikimediaUI-Language.svg' } | ||
) | ) | ||
| Строка 176: | Строка 147: | ||
-- Testcase page | -- Testcase page | ||
if title.subpageText == 'testcases' then | if title.subpageText == 'testcases' then | ||
table.insert( ret3, | table.insert(ret3, | ||
hatnote( | hatnote( | ||
translate( 'message_module_tests', title.baseText ), | translate('message_module_tests', title.baseText), | ||
{ icon = 'WikimediaUI-LabFlask.svg' } | { icon = 'WikimediaUI-LabFlask.svg' } | ||
) | ) | ||
| Строка 184: | Строка 155: | ||
end | end | ||
table.insert( ret3, mw.ustring.format( '[[Category:%s]]', t( 'category_module' ) ) ) | table.insert(ret3, mw.ustring.format('[[Category:%s]]', t('category_module'))) | ||
end | end | ||
--- Dependency list | --- Dependency list | ||
table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) ) | table.insert(ret3, dependencyList._main(nil, args.category, args.isUsed)) | ||
-- Has templatestyles | -- Has templatestyles | ||
if mw.title.new( title.fullText .. '/styles.css' ).exists then | if mw.title.new(title.fullText .. '/styles.css').exists then | ||
table.insert( ret3, | table.insert(ret3, | ||
hatnote( | hatnote( | ||
translate( 'message_styles', title.fullText, title.fullText ), | translate('message_styles', title.fullText, title.fullText), | ||
{ icon = 'WikimediaUI-Palette.svg' } | { icon = 'WikimediaUI-Palette.svg' } | ||
) | ) | ||
| Строка 202: | Строка 173: | ||
--- Module stats bar | --- Module stats bar | ||
if title.namespace == 828 then | if title.namespace == 828 then | ||
table.insert( ret3, '<div class="documentation-modulestats">' ) | table.insert(ret3, '<div class="documentation-modulestats">') | ||
-- Function list | -- Function list | ||
table.insert( ret3, require( 'Module:Module toc' ).main() ) | table.insert(ret3, require('Module:Module toc').main()) | ||
-- Unit tests | -- Unit tests | ||
local testcaseTitle = title.baseText .. '/testcases' | local testcaseTitle = title.baseText .. '/testcases' | ||
if mw.title.new( testcaseTitle, 'Module' ).exists then | if mw.title.new(testcaseTitle, 'Module').exists then | ||
-- | -- Execute unit tests from the testcases subpage | ||
table.insert( ret3, frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' ) ) | table.insert(ret3, frame:preprocess('{{#invoke:' .. testcaseTitle .. '|run}}')) | ||
end | end | ||
table.insert( ret3, '</div>' ) | table.insert(ret3, '</div>') | ||
end | end | ||
return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 ) | return ret1 .. tostring(ret2) .. '<div class="documentation-content">' .. table.concat(ret3) | ||
end | end | ||
Текущая версия от 17:56, 2 сентября 2024
message_transclude_desc
message_module_i18n
message_module_i18n_subtext
{{#seo:
| type = website | description = Модуль:Documentation is a template page used on the iCCup Wiki. Templates are pages that are embedded (transcluded) into other pages to allow for the repetition of information. | site_name = iCCup Wiki | locale = ru }} Module:Documentation implements Template:Documentation for templates and modules.
-- <nowiki>
local dependencyList = require('Module:DependencyList')
local hatnote = require('Module:Hatnote')._hatnote
local mbox = require('Module:Mbox')._mbox
local i18n = require('Module:i18n'):new()
local TNT = require('Module:Translate'):new()
local lang = mw.getContentLanguage()
local p = {}
--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t(key)
return i18n:translate(key)
end
--- FIXME: This should go to somewhere else, like Module:Common
--- Calls TNT with the given key
---
--- @param key string The translation key
--- @return string If the key was not found in the .tab page, the key is returned
local function translate(key, ...)
local success, translation = pcall(TNT.format, 'Module:Documentation/i18n.json', key or '', ...)
if not success or translation == nil then
return key
end
return translation
end
function p.doc(frame)
local title = mw.title.getCurrentTitle()
local args = frame:getParent().args
local page = args[1] or mw.ustring.gsub(title.fullText, '/[Dd]o[ck]u?$', '')
local ret, cats, ret1, ret2, ret3
local pageType = (title.namespace == 828) and translate('module') or translate('template')
-- subpage header
if title.subpageText == 'doc' then
ret = mbox(
translate('message_subpage_title', page),
translate('message_subpage_desc', page, pageType),
{ icon = 'WikimediaUI-Notice.svg' }
)
if title.namespace == 10 then -- Template namespace
cats = '[[Category:' .. t('category_template_documentation') .. '|' .. title.baseText .. ']]'
ret2 = dependencyList._main()
elseif title.namespace == 828 then -- Module namespace
cats = '[[Category:' .. t('category_module_documentation') .. '|' .. title.baseText .. ']]'
ret2 = dependencyList._main() .. require('Module:Module toc').main()
else
cats = ''
ret2 = ''
end
return tostring(ret) .. ret2 .. cats
end
-- template header
ret1 = '<div class="documentation">'
ret2 = mw.html.create(nil)
:tag('div')
:addClass('documentation-header')
:tag('span')
:addClass('documentation-title')
:wikitext(lang:ucfirst(translate('message_documentation_title', pageType)))
:done()
:tag('span')
:addClass('documentation-links plainlinks')
:wikitext(
'[[' .. tostring(mw.uri.fullUrl(page .. '/doc', {action='view'})) .. ' view]] ' ..
'[[' .. tostring(mw.uri.fullUrl(page .. '/doc', {action='edit'})) .. ' edit]] ' ..
'[[' .. tostring(mw.uri.fullUrl(page .. '/doc', {action='history'})) .. ' history]] ' ..
'[<span class="jsPurgeLink">[' .. tostring(mw.uri.fullUrl(title.fullText, { action = 'purge' })) .. ' purge]</span>]'
)
:done()
:done()
:tag('div')
:addClass('documentation-subheader')
:tag('span')
:addClass('documentation-documentation')
:wikitext(translate('message_transclude_desc', page))
:done()
:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} })
:done()
ret3 = {}
if args.iccupShared then
--- Message box
table.insert(ret3,
mbox(
translate('message_shared_across', title.fullText, mw.uri.encode(tostring(title.text), 'PATH')),
translate('message_shared_across_subtext', pageType),
{ icon = 'WikimediaUI-ArticleDisambiguation-ltr.svg' }
)
)
--- Set category
table.insert(ret3, '[[Category:' .. mw.ustring.format(t('category_shared_across'), lang:ucfirst(pageType)) .. ']]')
--- Interlanguage link
for _, code in pairs{'ru', 'en'} do
if lang:getCode() ~= code then
table.insert(ret3, mw.ustring.format('[[%s:%s]]', code, title.fullText))
end
end
end
if args.fromWikipedia then
table.insert(ret3,
mbox(
translate('message_from_wikipedia', title.fullText, mw.uri.encode(tostring(page), 'WIKI'), page),
translate('message_from_wikipedia_subtext', pageType),
{ icon = 'WikimediaUI-Logo-Wikipedia.svg' }
)
)
--- Set category
table.insert(ret3, '[[Category:' .. mw.ustring.format(t('category_from_wikipedia'), lang:ucfirst(pageType)) .. ']]')
end
if title.namespace == 828 then
-- Has config
if mw.title.new(title.fullText .. '/config.json', 'Module').exists then
table.insert(ret3,
mbox(
translate('message_module_configuration', title.fullText, title.fullText),
translate('message_module_configuration_subtext'),
{ icon = 'WikimediaUI-Settings.svg' }
)
)
end
-- Has localization
if mw.title.new(title.fullText .. '/i18n.json', 'Module').exists then
table.insert(ret3,
mbox(
translate('message_module_i18n', title.fullText, title.fullText),
translate('message_module_i18n_subtext'),
{ icon = 'WikimediaUI-Language.svg' }
)
)
end
-- Testcase page
if title.subpageText == 'testcases' then
table.insert(ret3,
hatnote(
translate('message_module_tests', title.baseText),
{ icon = 'WikimediaUI-LabFlask.svg' }
)
)
end
table.insert(ret3, mw.ustring.format('[[Category:%s]]', t('category_module')))
end
--- Dependency list
table.insert(ret3, dependencyList._main(nil, args.category, args.isUsed))
-- Has templatestyles
if mw.title.new(title.fullText .. '/styles.css').exists then
table.insert(ret3,
hatnote(
translate('message_styles', title.fullText, title.fullText),
{ icon = 'WikimediaUI-Palette.svg' }
)
)
end
--- Module stats bar
if title.namespace == 828 then
table.insert(ret3, '<div class="documentation-modulestats">')
-- Function list
table.insert(ret3, require('Module:Module toc').main())
-- Unit tests
local testcaseTitle = title.baseText .. '/testcases'
if mw.title.new(testcaseTitle, 'Module').exists then
-- Execute unit tests from the testcases subpage
table.insert(ret3, frame:preprocess('{{#invoke:' .. testcaseTitle .. '|run}}'))
end
table.insert(ret3, '</div>')
end
return ret1 .. tostring(ret2) .. '<div class="documentation-content">' .. table.concat(ret3)
end
return p
-- </nowiki>