More actions
Content deleted Content added
Interwiki>ExE Boss Correctly handle `content` parameter on `doc` subpages |
ChaoticDevs (talk | contribs) m 1 revision imported: Runescape dependency list |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
-- <nowiki> |
|||
require("strict"); |
|||
local dependencyList = require( 'Module:DependencyList' ) |
local dependencyList = require( 'Module:DependencyList' ) |
||
local |
local hatnote = require( 'Module:Hatnote' )._hatnote |
||
local mbox = require( 'Module:Mbox' )._mbox |
|||
local dt, hc; |
|||
local i18n = require( 'Module:i18n' ):new() |
|||
do |
|||
local TNT = require( 'Module:Translate' ):new() |
|||
local lang = mw.getContentLanguage() |
|||
dt = _module_paramtest.default_to; |
|||
hc = _module_paramtest.has_content; |
|||
end |
|||
local p = {} |
local p = {} |
||
local function processArgs(frame, isLegacyOrHeader) |
|||
local title = mw.title.getCurrentTitle() |
|||
local args = frame:getParent().args |
|||
--- Wrapper function for Module:i18n.translate |
|||
local page, docPage; |
|||
--- |
|||
do |
|||
--- @param key string The translation key |
|||
local argName_page = isLegacyOrHeader and 1 or nil; |
|||
--- @return string If the key was not found, the key is returned |
|||
local argName_docPage = isLegacyOrHeader and "docPage" or 1; |
|||
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 |
|||
page = argName_page ~= nil and args[argName_page] |
|||
return key |
|||
or mw.ustring.gsub(title.fullText, "/doc$", ""); |
|||
docPage = dt(args[argName_docPage], page .. "/doc"); |
|||
end |
end |
||
return translation |
|||
local opts = frame.args; |
|||
return title, args, opts, page, docPage; |
|||
end |
end |
||
function p.doc( frame ) |
function p.doc( frame ) |
||
local title = mw.title.getCurrentTitle() |
|||
local isLegacy = true; |
|||
local args = frame:getParent().args |
|||
local page = args[1] or mw.ustring.gsub( title.fullText, '/[Dd]o[ck]u?$', '' ) |
|||
if hc(header) then |
|||
local ret, cats, ret1, ret2, ret3 |
|||
return header; |
|||
local pageType = title.namespace == 828 and translate( 'module' ) or translate( 'template' ) |
|||
end |
|||
return p.main(frame, isLegacy); |
|||
end |
|||
function p.header(frame, isLegacy) |
|||
local title = mw.title.getCurrentTitle(); |
|||
-- subpage header |
-- subpage header |
||
if title.subpageText == 'doc' then |
|||
ret = mbox( |
|||
if (isDoc or not isLegacy) then |
|||
translate( 'message_subpage_title', page ), |
|||
local _, args, opts, page = processArgs(frame, true); |
|||
translate( 'message_subpage_desc', page, pageType ), |
|||
local onModule = title.namespace == 828 |
|||
{ icon = 'WikimediaUI-Notice.svg' } |
|||
) |
|||
if title.namespace == 10 then -- Template namespace |
|||
cats = '[[Category:' .. t( 'category_template_documentation' ) .. '|' .. title.baseText .. ']]' |
|||
:addClass( 'messagebox' ) |
|||
ret2 = dependencyList._main() |
|||
elseif title.namespace == 828 then -- Module namespace |
|||
cats = '[[Category:' .. t( 'category_module_documentation' ) .. '|' .. title.baseText .. ']]' |
|||
ret2 = dependencyList._main() |
|||
ret2 = ret2 .. require('Module:Module toc').main() |
|||
else |
|||
cats = '' |
|||
ret2 = '' |
|||
end |
|||
:wikitext( 'This is a documentation subpage for [[' .. page .. ']].' ) |
|||
:done() |
|||
:tag( 'div' ) |
|||
:css({ ['font-size'] = '0.85em', ['line-height'] = '1.4em' }) |
|||
:wikitext( |
|||
string.format( |
|||
'It contains usage information, categories, and other content that is not part of the original %s page.', |
|||
onModule and 'module' or 'template' |
|||
) |
|||
) |
|||
:done() |
|||
:done() |
|||
:done() |
|||
:done() |
|||
return tostring( ret ) .. ret2 .. cats |
|||
local ret2, cats = p._dependencyListAndToc(title, args, opts, { |
|||
-- Namespaces with dependency lists: |
|||
[10] = true, -- Template namespace |
|||
[116] = true, -- Calculator namespace |
|||
[828] = true, -- Module namespace |
|||
}); |
|||
if isDoc then |
|||
if (isLegacy and hc(args.content)) then |
|||
ret2 = ret2 .. "\n" .. args.content; |
|||
end |
|||
return tostring(ret) .. ret2 .. (cats or "") |
|||
end |
|||
return ret2 |
|||
end |
end |
||
return ""; |
|||
end |
|||
function p.main(frame, isLegacy) |
|||
local title, args, opts, _, docPage = processArgs(frame, isLegacy); |
|||
local ret, cats, ret1, ret2, ret3 |
|||
local onModule = title.namespace == 828 |
|||
-- template header |
-- template header |
||
Line 104: | Line 72: | ||
:addClass( 'documentation-header' ) |
:addClass( 'documentation-header' ) |
||
:tag( 'span' ) |
: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() |
:done() |
||
:tag( 'div' ) |
:tag( 'div' ) |
||
:addClass( 'documentation-subheader' ) |
:addClass( 'documentation-subheader' ) |
||
:tag( 'span' ) |
:tag( 'span' ) |
||
:addClass( 'documentation-documentation' ) |
|||
:wikitext( translate( 'message_transclude_desc', page ) ) |
|||
:wikitext( 'This documentation is transcluded from [[' .. docPage .. ']]. ' ) |
|||
:done() |
|||
:wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } ) |
|||
:tag( 'span' ) |
|||
:addClass( 'documentation-links plainlinks' ) |
|||
:wikitext( |
|||
'[[' .. tostring( mw.uri.fullUrl(docPage, {action='edit'} ) ) .. ' edit]] ' .. |
|||
'[[' .. tostring( mw.uri.fullUrl(docPage, {action='history'} ) ) .. ' history]] ' .. |
|||
'[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]' |
|||
) |
|||
:done() |
|||
:done() |
:done() |
||
ret3 = {} |
|||
ret3 = isLegacy and (p._dependencyListAndToc(title, args, opts)) or "" |
|||
if yn(args.isData, false) and title.namespace == 828 then |
|||
ret3 = ret3 .. '[[Category:Data modules]]' |
|||
end |
|||
if args.scwShared then |
|||
local mboxes = ""; |
|||
--- Message box |
|||
if hc(args.mboxes) then |
|||
table.insert( ret3, |
|||
mboxes = args.mboxes; |
|||
mbox( |
|||
end |
|||
translate( |
|||
'message_shared_across', |
|||
title.fullText, |
|||
mw.uri.encode( 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 |
|||
--- TODO: Make this into a for loop when there are more wikis |
|||
for _, code in pairs{ 'de', '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, |
|||
ret3 = ret3 .. "\n" |
|||
mbox( |
|||
.. args.content |
|||
translate( |
|||
.. "\n</div></div>"; |
|||
'message_from_wikipedia', |
|||
elseif (not isLegacy) then |
|||
title.fullText, |
|||
local docContent = "{{:" .. docPage .. "}}"; |
|||
mw.uri.encode( page, 'WIKI' ), |
|||
ret3 = ret3 .. "\n" |
|||
page |
|||
.. frame:preprocess(docContent) |
|||
), |
|||
.. "\n</div></div>"; |
|||
translate( |
|||
end |
|||
'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 |
|||
return ret1 |
|||
-- Has config |
|||
.. tostring( ret2 ) |
|||
if mw.title.new( title.fullText .. '/config.json', 'Module' ).exists then |
|||
.. '<div class="documentation-content">' |
|||
. |
table.insert( ret3, |
||
mbox( |
|||
end |
|||
translate( |
|||
'message_module_configuration', |
|||
title.fullText, |
|||
title.fullText |
|||
), |
|||
translate( 'message_module_configuration_subtext' ), |
|||
{ icon = 'WikimediaUI-Settings.svg' } |
|||
) |
|||
) |
|||
end |
|||
-- Has localization |
|||
function p._dependencyListAndToc(title, args, opts, depListCatNums) |
|||
if mw.title.new( title.fullText .. '/i18n.json', 'Module' ).exists then |
|||
local addDependencyList = yn(args.DependencyList, true); |
|||
table.insert( ret3, |
|||
if (addDependencyList == nil) then addDependencyList = true; end |
|||
mbox( |
|||
translate( |
|||
'message_module_i18n', |
|||
title.fullText, |
|||
title.fullText |
|||
), |
|||
translate( 'message_module_i18n_subtext' ), |
|||
{ icon = 'WikimediaUI-Language.svg' } |
|||
) |
|||
) |
|||
end |
|||
-- Testcase page |
|||
local addModuleToc = yn(args.ModuleToc, true); |
|||
if title.subpageText == 'testcases' then |
|||
if (addModuleToc == nil) then addModuleToc = true; end |
|||
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' ) ) ) |
|||
local cats; |
|||
end |
|||
local toc = {}; |
|||
--- Dependency list |
|||
if ( |
|||
table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) ) |
|||
addDependencyList |
|||
and (not depListCatNums or depListCatNums[title.namespace]) |
|||
-- Has templatestyles |
|||
) then |
|||
if mw.title.new( title.fullText .. '/styles.css' ).exists then |
|||
table.insert(toc, dependencyList._main(nil, args.category, args.isUsed)); |
|||
table.insert( ret3, |
|||
hatnote( |
|||
translate( 'message_styles', title.fullText, title.fullText ), |
|||
{ icon = 'WikimediaUI-Palette.svg' } |
|||
) |
|||
) |
|||
end |
end |
||
--- Module stats bar |
|||
if title.namespace == 10 then -- Template namespace |
|||
if title.namespace == 828 then |
|||
cats = '[[Category:Template documentation|' .. title.baseText .. ']]' |
|||
table.insert( ret3, '<div class="documentation-modulestats">' ) |
|||
elseif title.namespace == 828 then -- Module namespace |
|||
cats = '[[Category:Module documentation|' .. title.baseText .. ']]' |
|||
-- Function list |
|||
table.insert(toc, addModuleToc and require('Module:Module toc').main() or nil); |
|||
table.insert( ret3, require( 'Module:Module toc' ).main() ) |
|||
if yn(args.isData, false) then |
|||
table.insert(toc, '<div class="seealso"><code>mw.loadData</code> compatible</div>') |
|||
end |
|||
end |
|||
-- Unit tests |
|||
if hc(opts.preamble) then |
|||
local testcaseTitle = title.baseText .. '/testcases' |
|||
table.insert(toc, 1, opts.preamble); |
|||
if mw.title.new( testcaseTitle, 'Module' ).exists then |
|||
end |
|||
-- There is probably a better way :P |
|||
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 |
end |
||
return p |
return p |
||
-- </nowiki> |
Revision as of 23:22, 20 June 2024
Lua error in Module:DependencyList at line 575: attempt to index field 'smw' (a nil value). 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()
ret2 = ret2 .. require('Module:Module toc').main()
else
cats = ''
ret2 = ''
end
return tostring( ret ) .. ret2 .. cats
end
-- template header
-- don't use mw.html as we aren't closing the main div tag
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.scwShared then
--- Message box
table.insert( ret3,
mbox(
translate(
'message_shared_across',
title.fullText,
mw.uri.encode( 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
--- TODO: Make this into a for loop when there are more wikis
for _, code in pairs{ 'de', '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( 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
-- There is probably a better way :P
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>