Module:Documentation: Difference between revisions

mNo edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local defaultDocPage = 'doc'
local docPreload = 'Template:Documentation/preload'
local docStyle = 'Module:Documentation/styles.css'


local static = require( 'Module:Static' )
local static = require( 'Module:Static' )


local i18n = {
local i18n = {
-- default settings, change when necessary
defaultDocPage = 'doc', -- documentation page suffix
defaultPreload = 'Template:Documentation/preload', -- page that stores qualified documentation page contents
defaultStyles = 'Module:Documentation/styles.css', -- stylesheet for this module when using TemplateStyles, remove or set to nil if your wiki not use this
-- format strings, should not be translated
-- format strings, should not be translated
commonInternalLink = '[[%s]]',
commonInternalLink = '[[%s]]',
Line 67: Line 68:
pageDocHeaderBottom = 'The above documentation is transcluded from %s.', -- message shown as the bottom line of the documentation header
pageDocHeaderBottom = 'The above documentation is transcluded from %s.', -- message shown as the bottom line of the documentation header
}
}
local function loadStyles( stylesheet )
if not stylesheet or mw.text.trim( stylesheet ) == '' then
return ''
end
return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = stylesheet } }
end


local function getType( namespace, page )
local function getType( namespace, page )
Line 75: Line 83:
elseif namespace == 'Widget' then
elseif namespace == 'Widget' then
pageType = 'widget'
pageType = 'widget'
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.css$' ) then
pageType = 'stylesheet'
pageType = 'stylesheet'
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.js$' ) then
pageType = 'script'
pageType = 'script'
elseif namespace == 'MediaWiki' then
elseif namespace == 'MediaWiki' then
Line 90: Line 98:
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 .. '/' .. defaultDocPage
local docPage = args.page or page.nsText .. ':' .. page.baseText .. '/' .. i18n.defaultDocPage


local out
local out
Line 96: Line 104:
local pageType = mw.ustring.lower( args.type or getType( page.nsText, page ) )
local pageType = mw.ustring.lower( args.type or getType( page.nsText, page ) )
local pageTypeDisplay = i18n[ 'pageType_' .. pageType ] or i18n.pageTypeTemplate
local pageTypeDisplay = i18n[ 'pageType_' .. pageType ] or i18n.pageTypeTemplate
out = f:preprocess( mw.title.new( docPreload ):getContent():gsub( '$1' , pageTypeDisplay ) )
out = f:preprocess( mw.title.new( i18n.defaultPreload ):getContent():gsub( '$1' , pageTypeDisplay ) )
else
else
local templateArgs = {}
local templateArgs = {}
Line 138: Line 146:
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 .. '/' .. 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 164: Line 172:
mw.logObject( body, 'Module:Documentation: body' )
mw.logObject( body, 'Module:Documentation: body' )


return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = docStyle } } .. tostring( body )
return loadStyles( i18n.defaultStyles ) .. tostring( body )
end
end


Line 189: Line 197:
docPage = page
docPage = page
else
else
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/' .. defaultDocPage )
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/' .. i18n.defaultDocPage )
noDoc = args.nodoc or not docPage.exists
noDoc = args.nodoc or not docPage.exists
end
end
Line 245: Line 253:
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.commonSpecialPageSub:format( i18n.specialHistory, docPage.fullText ), i18n.linkTextHistory ) ) )
else
else
table.insert( linkList, i18n.linkFormat:format( i18n.commonExternalLinkWithName:format( docPage:canonicalUrl{ action = 'edit', preload = docPreload, 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.commonSpecialPageSub:format( i18n.specialPurge, docPage.fullText ), i18n.linkTextPurge ) ) )
Line 297: Line 305:
end
end


return mw.getCurrentFrame():extensionTag{ name = "templatestyles", args = { src = docStyle } } .. tostring( body ) .. tostring( anchor )
return loadStyles( i18n.defaultStyles ) .. tostring( body ) .. tostring( anchor )
end
end


return p
return p