Module:Documentation: Difference between revisions

mNo edit summary
No edit summary
Line 16: Line 16:
commonExternalLink = '[%s]',
commonExternalLink = '[%s]',
commonExternalLinkWithName = '[%s %s]',
commonExternalLinkWithName = '[%s %s]',
commonNamespacedPage = '%s:%s',
commonNamespacedPageWithSub = '%s:%s/%s',


-- format strings, translate if your language prefers localized namespace name, although remain it untouched most likely not affect anything
-- namespace names, translate if your language prefers localized namespace name, although remain it untouched most likely not affect anything
commonCategoryPage = 'Category:%s',
namespaceCategory = 'Category',
commonSpecialPageSub = 'Special:%s/%s',
namespaceSpecial = 'Special',
commonUser = 'User',
namespaceUser = 'User',


-- names of special pages, translate if your language prefers localized namespace name, although remain it untouched will still correctly linked to target page
-- names of special pages, translate if your language prefers localized namespace name, although remain it untouched will still correctly linked to target page
Line 100: Line 102:
local args = require( 'Module:ProcessArgs' ).norm()
local args = require( 'Module:ProcessArgs' ).norm()
local page = mw.title.getCurrentTitle()
local page = mw.title.getCurrentTitle()
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. i18n.defaultDocPage
local docPage = args.page or i18n.commonNamespacedPageWithSub:format( page.nsText, page.baseText, i18n.defaultDocPage )


local out
local out
Line 124: Line 126:
out = f:preprocess( out )
out = f:preprocess( out )
if not args.nocat then
if not args.nocat then
out = out .. i18n.commonInternalLink:format( i18n.commonCategoryPage:format( i18n.createNoSubstCategory ) )
out = out .. i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, i18n.createNoSubstCategory ) )
end
end
end
end
Line 148: Line 150:
end
end


local docPage = mw.title.new( args.page or page.nsText .. ':' .. page.baseText .. '/' .. i18n.defaultDocPage )
local docPage = mw.title.new( args.page or i18n.commonNamespacedPageWithSub:format( page.nsText, page.baseText, i18n.defaultDocPage ) )
mw.logObject( docPage, 'Module:Documentation: docPage' )
mw.logObject( docPage, 'Module:Documentation: docPage' )
mw.logObject( page, 'Module:Documentation: page' )
mw.logObject( page, 'Module:Documentation: page' )
Line 162: Line 164:
:tag( 'div' )
:tag( 'div' )
:attr( 'id', 'documentation-header-tools' )
:attr( 'id', 'documentation-header-tools' )
:wikitext( i18n.linkBar:format( i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonSpecialPageSub:format( i18n.specialPurge, page.fullText ), i18n.linkTextPurge ) ) ) )
:wikitext( i18n.linkBar:format( i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialPurge, page.fullText ), i18n.linkTextPurge ) ) ) )
:done()
:done()
:wikitext( i18n.docPagePrompt:format( pageType == 'module' and i18n.docPagePromptWill or i18n.docPagePromptShould, i18n.commonInternalLink:format( namespace .. ':' .. page.baseText ) ) )
:wikitext( i18n.docPagePrompt:format( pageType == 'module' and i18n.docPagePromptWill or i18n.docPagePromptShould, i18n.commonInternalLink:format( i18n.commonNamespacedPage( namespace, page.baseText ) ) ) )
if badDoc then
if badDoc then
body:wikitext( i18n.docPageBadDocPrompt:format( pageTypeDisplay ) )
body:wikitext( i18n.docPageBadDocPrompt:format( pageTypeDisplay ) )
end
end
if not ( args.nocat or namespace == i18n.commonUser ) then
if not ( args.nocat or namespace == i18n.namespaceUser ) then
body:wikitext( i18n.commonInternalLink:format( i18n.commonCategoryPage:format( i18n.docPageCategory ) ) )
body:wikitext( i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, i18n.docPageCategory ) ) )
end
end


Line 199: Line 201:
docPage = page
docPage = page
else
else
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/' .. i18n.defaultDocPage )
docPage = mw.title.new( args.page or i18n.commonNamespacedPageWithSub:format( namespace, page.text, i18n.defaultDocPage ) )
noDoc = args.nodoc or not docPage.exists
noDoc = args.nodoc or not docPage.exists
end
end
Line 228: Line 230:
docClass = 'documentation-noDoc'
docClass = 'documentation-noDoc'
message = i18n.pageNoDocPrompt:format( pageTypeDisplay, pageTypeDisplay )
message = i18n.pageNoDocPrompt:format( pageTypeDisplay, pageTypeDisplay )
if not ( args.nocat or namespace == i18n.commonUser ) then
if not ( args.nocat or namespace == i18n.namespaceUser ) then
category = i18n.pageNoDocCategory:format( pageTypeDisplay )
category = i18n.pageNoDocCategory:format( pageTypeDisplay )
if not mw.title.new( i18n.commonCategoryPage:format( category ) ).exists then
if not mw.title.new( i18n.commonNamespacedPage:format( i18n.namespaceCategory, category ) ).exists then
category = i18n.pageNoDocCategoryDefault
category = i18n.pageNoDocCategoryDefault
end
end
Line 237: Line 239:
docClass = 'documentation-badDoc'
docClass = 'documentation-badDoc'
message = i18n.pageBadDocPrompt:format( pageTypeDisplay )
message = i18n.pageBadDocPrompt:format( pageTypeDisplay )
if not ( args.nocat or namespace == i18n.commonUser ) then
if not ( args.nocat or namespace == i18n.namespaceUser ) then
category = i18n.pageBadDocCategory:format( pageTypeDisplay )
category = i18n.pageBadDocCategory:format( pageTypeDisplay )
if not mw.title.new( i18n.commonCategoryPage:format( category ) ).exists then
if not mw.title.new( i18n.commonNamespacedPage:format( i18n.namespaceCategory, category ) ).exists then
category = i18n.pageBadDocCategoryDefault
category = i18n.pageBadDocCategoryDefault
end
end
Line 252: Line 254:
if not noDoc and page ~= docPage then
if not noDoc and page ~= docPage then
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( docPage.fullText, i18n.linkTextView ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( docPage.fullText, i18n.linkTextView ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonSpecialPageSub:format( i18n.specialEdit, docPage.fullText ), i18n.linkTextEdit ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialEdit, docPage.fullText ), i18n.linkTextEdit ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonSpecialPageSub:format( i18n.specialHistory, docPage.fullText ), i18n.linkTextHistory ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialHistory, docPage.fullText ), i18n.linkTextHistory ) ) )
else
else
table.insert( linkList, i18n.linkFormat:format( i18n.commonExternalLinkWithName:format( docPage:canonicalUrl{ action = 'edit', preload = i18n.defaultPreload, preloadparams = pageTypeDisplay }, i18n.linkTextCreate ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonExternalLinkWithName:format( docPage:canonicalUrl{ action = 'edit', preload = i18n.defaultPreload, preloadparams = pageTypeDisplay }, i18n.linkTextCreate ) ) )
end
end
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonSpecialPageSub:format( i18n.specialPurge, docPage.fullText ), i18n.linkTextPurge ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialPurge, docPage.fullText ), i18n.linkTextPurge ) ) )
links:wikitext( i18n.linkBar:format( table.concat( linkList, i18n.linkSeparator ) ) )
links:wikitext( i18n.linkBar:format( table.concat( linkList, i18n.linkSeparator ) ) )