Module:Documentation: Difference between revisions

mNo edit summary
No edit summary
Line 144: Line 144:
local docText = trim( args.content or '' )
local docText = trim( args.content or '' )
if docText == '' then docText = nil end
if docText == '' then docText = nil end
 
local docPage
local docPage
local noDoc
local noDoc
Line 155: Line 155:
local badDoc = args.baddoc
local badDoc = args.baddoc
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
local pageType = mw.ustring.lower( args.type or getType( namespace, page ) )
 
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 }  )
Line 171: Line 171:
docText = '\n' .. docText .. '\n'
docText = '\n' .. docText .. '\n'
end
end
 
local docClass = ''
local docClass = ''
local message
local message
Line 195: Line 195:
end
end
end
end
 
-- Generates the [view][edit][history][refresh] or [create][refresh] links
-- Generates the [view][edit][history][refresh] or [create][refresh] links
local links = mw.html.create( 'span' )
local links = mw.html.create( 'span' )
:attr( 'id', 'documentation-header-tools' )
:attr( 'id', 'documentation-header-tools' )


local purgeLink = '[[Special:Purge/' .. docPage.fullText .. '|' .. i18n.linkTextPurge .. ']]'
local linkList = {}
if not noDoc and page ~= docPage then
if not noDoc and page ~= docPage then
local viewLink = '[[' .. docPage.fullText .. '|' .. i18n.linkTextView .. ']]'
table.insert( linkList, i18n.linkFormat:format( '[[' .. docPage.fullText .. '|' .. i18n.linkTextView .. ']]' ) )
local editLink = '[[Special:EditPage/' .. docPage.fullText .. '|' .. i18n.linkTextEdit .. ']]'
table.insert( linkList, i18n.linkFormat:format( '[[Special:EditPage/' .. docPage.fullText .. '|' .. i18n.linkTextEdit .. ']]' ) )
local historyLink = '[[Special:PageHistory/' .. docPage.fullText .. '|' .. i18n.linkTextHistory .. ']]'
table.insert( linkList, i18n.linkFormat:format( '[[Special:PageHistory/' .. docPage.fullText .. '|' .. i18n.linkTextHistory .. ']]' ) )
links:wikitext("[" .. viewLink .. "] [" .. editLink .. "] [" .. historyLink .. "] [" .. purgeLink .. "]")
else
else
local createLink = '[' .. docPage:canonicalUrl{action = 'edit', preload = 'Template:Documentation/preload' } .. ' ' .. i18n.linkTextCreate .. ']'
table.insert( linkList, i18n.linkFormat:format( '[' .. docPage:canonicalUrl{ action = 'edit', preload = 'Template:Documentation/preload' } .. ' ' .. i18n.linkTextCreate .. ']' ) )
links:wikitext("[" .. createLink .. "] [" .. purgeLink .. "]")
end
end
table.insert( linkList, '[[Special:Purge/' .. docPage.fullText .. '|' .. i18n.linkTextPurge .. ']]' )
links:wikitext( i18n.linkBar:format( table.concat( linkList, i18n.linkSeparator ) ) )
 
local body = mw.html.create( 'div' ):addClass( 'documentation' )
local body = mw.html.create( 'div' ):addClass( 'documentation' )
body
body
:addClass( docClass )
:addClass( docClass )
 
local header = mw.html.create( 'div' )
local header = mw.html.create( 'div' )
:addClass( 'documentation-header-top' )
:addClass( 'documentation-header-top' )
 
header
header
:node( links )
:node( links )
Line 223: Line 223:
:addClass('documentation-header-title' )
:addClass('documentation-header-title' )
:wikitext( 'Documentation' )
:wikitext( 'Documentation' )
 
local codePages = {
local codePages = {
module = true,
module = true,
Line 235: Line 235:
:wikitext( '[[#the-code|Jump to code ↴]]' )
:wikitext( '[[#the-code|Jump to code ↴]]' )
end
end
 
body
body
:node( header ):done()
:node( header ):done()
:wikitext( message )
:wikitext( message )
:wikitext( docText )
:wikitext( docText )
 
if not noDoc and page ~= docPage then
if not noDoc and page ~= docPage then
body
body
Line 248: Line 248:
:wikitext( 'The above documentation is transcluded from [[', docPage.fullText, ']].' )
:wikitext( 'The above documentation is transcluded from [[', docPage.fullText, ']].' )
end
end
 
if category then
if category then
body:wikitext( f:expandTemplate{ title = 'Translation category', args = { category, project = '0' } } )
body:wikitext( f:expandTemplate{ title = 'Translation category', args = { category, project = '0' } } )
end
end
 
local anchor = ''
local anchor = ''
if not noDoc and pageType ~= 'template' and pageType ~= 'message' then
if not noDoc and pageType ~= 'template' and pageType ~= 'message' then
anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' )
anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' )
end
end
 
return mw.getCurrentFrame():extensionTag('templatestyles', '', {src='Module:Documentation/styles.css'}) .. tostring( body ) .. tostring( anchor )
return mw.getCurrentFrame():extensionTag('templatestyles', '', {src='Module:Documentation/styles.css'}) .. tostring( body ) .. tostring( anchor )
end
end


return p
return p