Module:Documentation: Difference between revisions

mNo edit summary
m 1 revision imported
Tags: Mobile edit Mobile web edit
 
(12 intermediate revisions by 6 users not shown)
Line 32: Line 32:


-- translate following types if your language displays differ
-- translate following types if your language displays differ
pageType_page = 'page',
pageType_template = 'template',
pageType_template = 'template',
pageType_module = 'module',
pageType_module = 'module',
pageType_widget = 'widget',
pageType_stylesheet = 'stylesheet',
pageType_stylesheet = 'stylesheet',
pageType_script = 'script',
pageType_script = 'script',
pageType_json = 'JSON',
pageType_message = 'message',
pageType_message = 'message',


Line 45: Line 46:


-- name of different type of links, change them if necessary
-- name of different type of links, change them if necessary
linkTextPurge = mw.getCurrentFrame():callParserFunction( 'int:smw_purge' ):lower(),
linkTextPurge = mw.message.new( 'smw_purge' ):plain():lower(),
linkTextView = mw.getCurrentFrame():callParserFunction( 'int:view' ):lower(),
linkTextView = mw.message.new( 'view' ):plain():lower(),
linkTextEdit = mw.getCurrentFrame():callParserFunction( 'int:edit' ):lower(),
linkTextEdit = mw.message.new( 'edit' ):plain():lower(),
linkTextHistory = mw.getCurrentFrame():callParserFunction( 'int:history_short' ):lower(),
linkTextHistory = mw.message.new( 'history_short' ):plain():lower(),
linkTextCreate = mw.getCurrentFrame():callParserFunction( 'int:create' ):lower(),
linkTextCreate = mw.message.new( 'create' ):plain():lower(),


-- strings used in p.create(): contents shown when using {{docc}} or {{subst:docc}}
-- strings used in p.create(): contents shown when using {{docc}} or {{subst:docc}}
createOutputFormat = '%s%s', -- overall format
createOutputFormat = '%s%s', -- overall format
createSplitDocPagePrompt = '\n<!-- Put categories/interwikis on the documentation page -->', -- this string will shown when a separate documentation page will be created
createSplitDocPagePrompt = '\n<!-- Put categories/interwikis on the documentation page -->', -- this string is shown when a separate documentation page is created
createNoSubstCategory = 'Pages with templates requiring substitution', -- tracking category for using {{docc}} without substitution
createNoSubstCategory = 'Pages with templates requiring substitution', -- tracking category for using {{docc}} without substitution


-- strings used in p.docPage(): contents shown in documentation page
-- strings used in p.docPage(): contents shown in documentation page
docPagePrompt = 'This is the documentation page. It %s be transcluded into %s. See [[Template:Documentation]] for more information.', -- message shown as documentation header in documentation pages. Params: word used when page is a module or not; code page's type
docPagePrompt = 'This is the documentation page. It %s transcluded into %s. See [[Template:Documentation]] for more information.', -- message shown as documentation header in documentation pages. Params: word used when page is a module or not; code page's type
docPagePromptWill = 'will', -- word used when code page is a module page
docPagePromptWill = 'is', -- word used when code page is a module page
docPagePromptShould = 'should', -- word used when code is not a module page
docPagePromptShould = 'should be', -- word used when code is not a module page
docPageBadDocPrompt = "<br>'''This %s's documentation needs improving or additional information.'''", -- additional message if a documentation page marked as baddoc
docPageBadDocPrompt = "<br>'''This %s's documentation needs improving or additional information.'''", -- additional message if a documentation page marked as baddoc
docPageCategory = 'Documentation pages', -- tracking category for documentation pages
docPageCategory = 'Documentation pages', -- tracking category for documentation pages
Line 77: Line 78:
-- Customizable functions
-- Customizable functions
local function pageCategoryHandler( category )
local function pageCategoryHandler( category )
return f:expandTemplate{ title = 'translation category', args = { category, project = '0' } }
return mw.getCurrentFrame():expandTemplate{ title = 'translation category', args = { category, project = '0' } }
end
end


-- Load modules
-- Load modules
local loadStyles = require( 'Module:TSLoader' ).call
local static = require( 'Module:Static' )
local static = require( 'Module:Static' )
if not static.Documentation then
static.Documentation = {}
end


-- Internal functions
-- Internal functions
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 )
local pageType = 'template'
local pageType = 'page'
if namespace == 'Module' then
if namespace == 'Template' then
pageType = 'template'
elseif namespace == 'Module' then
pageType = 'module'
pageType = 'module'
elseif namespace == 'Widget' then
pageType = 'widget'
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.css$' ) then
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.css$' ) then
pageType = 'stylesheet'
pageType = 'stylesheet'
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.js$' ) then
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.js$' ) then
pageType = 'script'
pageType = 'script'
elseif page.fullText:gsub( '/' .. i18n.defaultDocPage .. '$', '' ):find( '%.json$' ) then
pageType = 'json'
elseif namespace == 'MediaWiki' then
elseif namespace == 'MediaWiki' then
pageType = 'message'
pageType = 'message'
Line 108: Line 109:


local function getDisplayType( pageType )
local function getDisplayType( pageType )
return i18n[ 'pageType_' .. pageType ] or i18n.pageType_template
return i18n[ 'pageType_' .. pageType ] or i18n.pageType_page
end
end


Line 150: Line 151:
local badDoc = args.baddoc
local badDoc = args.baddoc


mw.logObject( badDoc, 'Module:Documentation: badDoc' )
if badDoc then
if badDoc then
static.badDoc = '1'
static.Documentation.badDoc = '1'
end
end


Line 163: Line 163:


local docPage = mw.title.new( args.page or i18n.commonNamespacedPageWithSub:format( 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( page, 'Module:Documentation: page' )
if docPage ~= page then return end
if docPage ~= page then return end


Line 174: Line 172:
body
body
:addClass( badDoc and 'documentation-badDoc' or '' )
:addClass( badDoc and 'documentation-badDoc' or '' )
:tag( 'div' )
:tag( 'div' ):addClass( 'documentation-header-tools' )
:attr( 'id', 'documentation-header-tools' )
:wikitext( i18n.linkBar:format( i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, 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()
Line 185: Line 182:
body:wikitext( i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, i18n.docPageCategory ) ) )
body:wikitext( i18n.commonInternalLink:format( i18n.commonNamespacedPage:format( i18n.namespaceCategory, i18n.docPageCategory ) ) )
end
end
mw.logObject( body, 'Module:Documentation: body' )


return loadStyles( i18n.defaultStyles ) .. tostring( body )
return loadStyles( i18n.defaultStyles ) .. tostring( body )
Line 221: Line 216:
if not docText and not noDoc then
if not docText and not noDoc then
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
if static.badDoc and static.badDoc == '1' then
if static.Documentation.badDoc and static.Documentation.badDoc == '1' then
mw.logObject( static, 'static' )
badDoc = 1
badDoc = 1
end
end
Line 259: Line 253:


-- Generates the link bar
-- Generates the link bar
local links = mw.html.create( 'span' )
local links = mw.html.create( 'span' ):addClass( 'documentation-header-tools' )
:attr( 'id', 'documentation-header-tools' )


local linkList = {}
local linkList = {}
if not noDoc and page ~= docPage then
if not noDoc then
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( docPage.fullText, i18n.linkTextView ) ) )
if page ~= docPage then
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( docPage.fullText, i18n.linkTextView ) ) )
end
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.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, i18n.specialEdit, docPage.fullText ), i18n.linkTextEdit ) ) )
table.insert( linkList, i18n.linkFormat:format( i18n.commonInternalLinkPipe:format( i18n.commonNamespacedPageWithSub:format( i18n.namespaceSpecial, 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 ) ) )
Line 281: Line 276:


header
header
:node( links )
:tag( 'span' )
:tag( 'span' )
:addClass( 'documentation-header-title' )
:addClass( 'documentation-header-title' )
:wikitext( i18n.pageDocHeaderTitle )
:wikitext( i18n.pageDocHeaderTitle )
header
        :node( links )


local codePages = {
local codePages = {