Module:Documentation: Difference between revisions
Fixes |
Add direct doc content, for those small page-specific templates that really don't need a dedicated doc page. |
||
| Line 23: | Line 23: | ||
local out | local out | ||
if page | if not args.content and page == docPage then | ||
out = f:preprocess( '{{subst:Template:Documentation/preload}}' ) | out = f:preprocess( '{{subst:Template:Documentation/preload}}' ) | ||
else | else | ||
local templateArgs = {} | local templateArgs = {} | ||
if | for _, key in ipairs{ 'type', 'page', 'content' } do | ||
local val = args[key] | |||
if val then | |||
table.insert( templateArgs, key .. '=' .. val ) | |||
end | |||
end | end | ||
out = '{{documentation|' .. table.concat( templateArgs, '|' ) .. '}}' | |||
if not args.content then | |||
out = '\n<!-- Put categories/interwiki on the documentation page -->' | |||
end | end | ||
out = out:gsub( '|}}', '}}' ) | out = out:gsub( '|}}', '}}' ) | ||
end | end | ||
| Line 97: | Line 100: | ||
local page = mw.title.getCurrentTitle() | local page = mw.title.getCurrentTitle() | ||
local namespace = page.nsText | local namespace = page.nsText | ||
local docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/doc' ) | local docText = mw.text.trim( args.content or '' ) | ||
if docText == '' then docText = nil end | |||
local docPage | |||
local noDoc | |||
if docText then | |||
docPage = page | |||
else | |||
docPage = mw.title.new( args.page or namespace .. ':' .. page.text .. '/doc' ) | |||
noDoc = args.nodoc or not docPage.exists | |||
end | |||
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 | |||
f:callParserFunction( '#dplvar:set', '$doc noheader', '1' ) | f:callParserFunction( '#dplvar:set', '$doc noheader', '1' ) | ||
docText = mw.text.trim( f:expandTemplate{ title = ':' .. docPage.fullText } ) | docText = mw.text.trim( f:expandTemplate{ title = ':' .. docPage.fullText } ) | ||
| Line 113: | Line 124: | ||
docText = nil | docText = nil | ||
noDoc = 1 | noDoc = 1 | ||
end | end | ||
end | |||
if docText then | |||
docText = '\n' .. docText .. '\n' | |||
end | end | ||
| Line 150: | Line 162: | ||
'[' .. page:fullUrl( 'action=purge' ) .. ' purge]' | '[' .. page:fullUrl( 'action=purge' ) .. ' purge]' | ||
} | } | ||
if not noDoc then | if not noDoc and page ~= docPage then | ||
table.insert( links, 1, '[[' .. docPage.fullText .. '|view]]' ) | table.insert( links, 1, '[[' .. docPage.fullText .. '|view]]' ) | ||
end | end | ||
| Line 197: | Line 209: | ||
:wikitext( docText ) | :wikitext( docText ) | ||
if not noDoc then | if not noDoc and page ~= docPage then | ||
body | body | ||
:tag( 'div' ) | :tag( 'div' ) | ||