Module:Documentation: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local defaultDocPage = 'doc'
local defaultDocPage = 'doc'
local static = require('Module:Static')
local static = require( 'Module:Static' )


local i18n = {
local i18n = {
Line 7: Line 7:
createSplitDocPagePrompt = '\n<!-- Put categories/interwikis on the documentation page -->',
createSplitDocPagePrompt = '\n<!-- Put categories/interwikis on the documentation page -->',
createNoSubstCategory = 'Category:Pages with templates requiring substitution',
createNoSubstCategory = 'Category:Pages with templates requiring substitution',
docPagePrompt = 'This is the documentation page. It %s be transcluded into the main %s page. See [[Template:Documentation]] for more information.',
docPagePromptWill = 'will',
docPagePromptShould = 'should',
docPageBadDocPrompt = "<br>'''This %s's documentation needs improving or additional information.'''",
docPageCategory = 'Category:Documentation pages',
}
}


Line 35: Line 40:
local out
local out
if not args.content and tostring( page ) == docPage then
if not args.content and tostring( page ) == docPage then
-- local pageType = mw.ustring.lower( args.type or getType( page.nsText, page ) )
-- local pageTypeDisplay = i18n[ 'pageType_' .. pageType ] or i18n.pageTypeTemplate
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
-- out = out:gsub( '$1' , pageTypeDisplay )
else
else
local templateArgs = {}
local templateArgs = {}
Line 64: Line 72:
local args = require( 'Module:ProcessArgs' ).merge( true )
local args = require( 'Module:ProcessArgs' ).merge( true )
local badDoc = args.baddoc
local badDoc = args.baddoc
mw.logObject(badDoc, "Module:Documentation: badDoc")
 
mw.logObject( badDoc, 'Module:Documentation: badDoc' )
if badDoc then
if badDoc then
static.badDoc = '1'
static.badDoc = '1'
end
end
 
local page = mw.title.getCurrentTitle()
local page = mw.title.getCurrentTitle()
local subpage = page.subpageText
local subpage = page.subpageText
if subpage == 'sandbox' or subpage == 'testcases' then
if subpage == 'sandbox' or subpage == 'testcases' then
page = page.basePageTitle
page = page.basePageTitle
end
end
 
local docPage = mw.title.new( args.page or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage )
local docPage = mw.title.new( args.page or page.nsText .. ':' .. page.baseText .. '/' .. 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' )
if docPage ~= page then return end
if docPage ~= page then return end
 
local namespace = page.nsText
local namespace = page.nsText
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
-- local pageTypeDisplay = i18n[ 'pageType_' .. pageType ] or i18n.pageTypeTemplate
 
local body = mw.html.create( 'div' ):addClass( 'documentation' )
local body = mw.html.create( 'div' ):addClass( 'documentation' )
body
body
Line 88: Line 99:
:tag( 'div' )
:tag( 'div' )
:attr( 'id', 'documentation-header-tools' )
:attr( 'id', 'documentation-header-tools' )
:wikitext( '[[', page:fullUrl( 'action=purge' ), ' ' .. f:callParserFunction( 'int:smw_purge' ):lower() .. ']]' )
:wikitext( mw.text.nowiki( '[' ) .. '[[Special:Purge/', page.fullText, '|', f:callParserFunction( 'int:smw_purge' ):lower(), ']]' .. mw.text.nowiki( ']' ) )
:done()
:done()
:wikitext(
:wikitext( i18n.docPagePrompt:format( pageType == 'module' and i18n.docPagePromptWill or i18n.docPagePromptShould, pageType ) )
'This is the documentation page. It ',
pageType == 'module' and 'will' or 'should',
' be transcluded into the main ', pageType, ' page. ',
'See [[Template:Documentation]] for more information'
)
if badDoc then
if badDoc then
body:wikitext( "<br>'''This ", pageType, "'s documentation needs improving or additional information.'''" )
body:wikitext( i18n.docPageBadDocPrompt:format( pageType ) )
end
end
if not ( args.nocat or namespace == 'User' ) then
if not ( args.nocat or namespace == 'User' ) then
body:wikitext( '[[Category:Documentation pages]]' )
body:wikitext( '[[' .. i18n.docPageCategory .. ']]' )
end
end
 
mw.logObject(body, "Module:Documentation: body")
mw.logObject( body, 'Module:Documentation: body')
return mw.getCurrentFrame():extensionTag('templatestyles', '', {src='Module:Documentation/styles.css'}) .. tostring(body)
 
return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = 'Documentation/styles.css' } } .. tostring( body )
end
end