Module:Documentation: Difference between revisions

mNo edit summary
m 1 revision imported
Tags: Mobile edit Mobile web edit
 
(9 intermediate revisions by 5 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}}
Line 81: Line 82:


-- 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
if not static.Documentation then
Line 87: Line 90:


-- 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 111: 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 153: Line 151:
local badDoc = args.baddoc
local badDoc = args.baddoc


mw.logObject( badDoc, 'Module:Documentation: badDoc' )
if badDoc then
if badDoc then
static.Documentation.badDoc = '1'
static.Documentation.badDoc = '1'
Line 166: 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 177: 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 188: 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 225: Line 217:
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
if static.Documentation.badDoc and static.Documentation.badDoc == '1' then
if static.Documentation.badDoc and static.Documentation.badDoc == '1' then
mw.logObject( static, 'static' )
badDoc = 1
badDoc = 1
end
end
Line 262: 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 284: 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 = {