Module:Documentation
Revision as of 21:34, 29 August 2013 by what>Hlm Z.
--This module implements Script error: The function "main" does not exist..
local p = {}
function p.corps(frame)
args = frame:getParent().args local page = mw.title.getCurrentTitle() doc = p.docname(page) local corps = {} if page.subpageText == 'sandbox' then
table.insert(corps, '
')
table.insert(corps, frame:preprocess('Template:Template sandbox notice')) end table.insert(corps, p.header(page)) table.insert(corps, p.content(frame, page)) table.insert(corps, p.footer(page)) if args.raw then return frame:preprocess('' .. table.concat(corps) .. '\n:' .. os.clock()) end return table.concat(corps)
end
function p.docname(page)
if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/doc" end if page.subpageText == 'doc' or page.subpageText == 'sandbox' or page.subpageText == 'testcases' then return page.subjectNsText .. ":" .. page.baseText .. "/doc" else return page.subjectNsText .. ":" .. page.text .. "/doc" end
end
function p.ifexist(page)
if not page then return false end if mw.title.new(page).exists then return true end return false
end
function p.header(page)
local header = {'
')
')
table.insert(header, '50px') table.insert(header, ' ') if args.heading then table.insert(header, args.heading) else table.insert(header, 'Template documentation') end table.insert(header, '') if not args.content then table.insert(header, '[[') local arg = mw.title.new(args[1] or doc) if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then table.insert(header, arg:fullUrl('action=view') .. ' view]') table.insert(header, '] [[') table.insert(header, arg:fullUrl('action=edit') .. ' edit]') table.insert(header, '] [[') table.insert(header, arg:fullUrl('action=history') .. ' history]') table.insert(header, '] [[') table.insert(header, page:fullUrl('action=purge') .. ' purge]') else table.insert(header, arg:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload"})) table.insert(header, ' create]') end table.insert(header, ']') endtable.insert(header, '
return table.concat(header)
end
function p.content(frame, page)
local content = {} local arg = args[1] or doc if args.content then table.insert(content, '\n') table.insert(content, args.content) else table.insert(content, frame:preprocess('')) table.insert(content, '\n') if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then table.insert(content, frame:preprocess('Template:' .. arg .. '')) end end table.insert(content, '\n') table.insert(content, frame:preprocess(''))table.insert(content, '\n')
return table.concat(content)
end
function p.footer(page)
local footer = {} local arg = mw.title.new(args[1] or doc)table.insert(footer, '
\n')
if args.content then if args["link box"] then table.insert(footer, args["link box"]) else table.insert(footer, 'This documentation is directly included in this page.') end else if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then table.insert(footer, 'The above documentation is ') table.insert(footer, 'transcluded from [[') table.insert(footer, tostring(arg)) table.insert(footer, ']] ([') table.insert(footer, arg:fullUrl('action=edit')) table.insert(footer, ' edit] | [') table.insert(footer, arg:fullUrl('action=history') .. ' history]).table.insert(footer, '
') end table.insert(footer, 'Editors can experiment in this templates ') local sandbox = arg.subjectNsText .. ":" .. arg.baseText .. "/sandbox" local argsandbox = mw.title.new(sandbox) if p.ifexist(sandbox) then table.insert(footer, 'sandbox') table.insert(footer, ' ([') table.insert(footer, argsandbox:fullUrl('action=edit')) table.insert(footer, ' edit])') else table.insert(footer, 'sandbox ([') table.insert(footer, argsandbox:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload-sandbox"})) table.insert(footer, ' create])') end table.insert(footer, ' and ') local test = arg.subjectNsText .. ":" .. arg.baseText .. "/testcases" local argtest = mw.title.new(test) if p.ifexist(test) then table.insert(footer, 'testcases') table.insert(footer, ' ([') table.insert(footer, argtest:fullUrl('action=edit')) table.insert(footer, ' edit])') else table.insert(footer, 'testcases ([') table.insert(footer, argtest:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload-testcases"})) table.insert(footer, ' create])') end table.insert(footer, ' pages.
Please add categories to the ') table.insert(footer, '[') if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then table.insert(footer, arg:fullUrl('action=edit')) else table.insert(footer, arg:fullUrl({["action"]="edit", ["preload"]="Template:Documentation/preload"})) end table.insert(footer, ' /doc] subpage.') end
')
return table.concat(footer)
end
return p