Module:Documentation: Difference between revisions

No edit summary
Fix section editing and generally retarded code.
Line 5: Line 5:
page = mw.title.getCurrentTitle()
page = mw.title.getCurrentTitle()
namespace = args.type or page.nsText
namespace = args.type or page.nsText
docPage = mw.title.new( args.page or namespace .. ':' .. page.baseText .. '/doc' )
docPage = args.page or namespace .. ':' .. page.baseText .. '/doc'
local out
local out
if page == docPage then
if page.fullText == docPage then
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
out = f:preprocess( '{{subst:Template:Documentation/preload}}' )
else
else
Line 33: Line 33:
end
end


-- Gateway function to page or docPage functions, depending on if viewing the documentation directly
-- Header on the documentation page
local args
function p.docPage( f )
local page
local args = require( 'Module:ProcessArgs' ).norm()
local namespace
local badDoc = args.baddoc
local docPage
if f:callParserFunction( '#dplvar:noheader' ) == '1' then
local pageType = 'template'
if badDoc then
function p.doc( f )
f:callParserFunction( '#dplvar:set', 'baddoc', '1' )
args = require( 'Module:ProcessArgs' ).merge( true )
end
page = mw.title.getCurrentTitle()
return ''
namespace = args.type or page.nsText
end
docPage = mw.title.new( args.page or namespace .. ':' .. page.baseText .. '/doc' )
local page = mw.title.getCurrentTitle()
local namespace = args.type or page.nsText
local pageType = 'template'
if namespace == 'Module' then
if namespace == 'Module' then
pageType = 'module'
pageType = 'module'
Line 55: Line 57:
end
end
if page == docPage then
return p.docPage( f )
else
return p.page( f )
end
end
-- Directly viewing the documentation page
function p.docPage( f )
local badDoc = args.baddoc
local colour = 'EAF4F9'
local colour = 'EAF4F9'
local message = ''
local message = ''
Line 94: Line 86:
end
end


-- Viewing the documentation on the main page
-- Wrapper around the documentation on the main page
function p.page( f )
function p.page( f )
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/doc' )
local args = require( 'Module:ProcessArgs' ).norm()
local page = mw.title.getCurrentTitle()
local namespace = args.type or page.nsText
local docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/doc' )
local noDoc = args.nodoc or not docPage.exists
local noDoc = args.nodoc or not docPage.exists
local badDoc = args.baddoc
local badDoc = args.baddoc
local pageType = 'template'
if namespace == 'Module' then
pageType = 'module'
elseif page.fullText:find( '.css$' ) then
pageType = 'stylesheet'
elseif page.fullText:find( '.js$' ) then
pageType = 'script'
elseif namespace == 'MediaWiki' then
pageType = 'message'
end
local docText = ''
local docText = ''
if not noDoc then
if not noDoc then
docText = docPage:getContent()
f:callParserFunction( '#dplvar:set', 'noheader', '1' )
badDoc = docText:match( '^%s*{{[Dd]ocumentation[^}]-|%s-baddoc%s-=%s-1%s-[^}]-}}' )
docText = mw.text.trim( f:expandTemplate{ title = ':' .. docPage.fullText }  )
docText = mw.text.trim( f:preprocess( docText:gsub( '^%s*{{[Dd]ocumentation[^}]-}}', '' ) ) )
if f:callParserFunction( '#dplvar:baddoc' ) == '1' then
badDoc = 1
end
if docText == '' then
if docText == '' then
noDoc = 1
noDoc = 1
Line 156: Line 165:
local out = {
local out = {
'<div style="background-color:#' .. colour .. ';border:1px solid #AAA;padding:0.8em 1em 0.8em;clear:both">\n',
'<div style="background-color:#' .. colour .. ';border:1px solid #AAA;padding:0.8em 1em 0.7em;clear:both">\n',
'<div style="margin:-0.8em -1em 0.8em;padding: 0.8em 1em 0.7em;background-color:#EAF4F9;border-bottom:1px solid #AAA">\n',
'<div style="margin:-0.8em -1em 0.8em;padding: 0.8em 1em 0.7em;background-color:#EAF4F9;border-bottom:1px solid #AAA">\n',
'<div style="float:right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n',
'<div style="float:right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n',