More actions
Lua error in Module:DependencyList at line 575: attempt to index field 'smw' (a nil value). Module:Documentation implements Template:Documentation for templates and modules.
require("strict");
local dependencyList = require( 'Module:DependencyList' )
local yn = require( 'Module:Yesno' )
local dt, hc;
do
local _module_paramtest = require("Module:Paramtest");
dt = _module_paramtest.default_to;
hc = _module_paramtest.has_content;
end
local p = {}
local function processArgs(frame, isLegacyOrHeader)
local title = mw.title.getCurrentTitle()
local args = frame:getParent().args
local page, docPage;
do
local argName_page = isLegacyOrHeader and 1 or nil;
local argName_docPage = isLegacyOrHeader and "docPage" or 1;
page = argName_page ~= nil and args[argName_page]
or mw.ustring.gsub(title.fullText, "/doc$", "");
docPage = dt(args[argName_docPage], page .. "/doc");
end
local opts = frame.args;
return title, args, opts, page, docPage;
end
function p.doc( frame )
local isLegacy = true;
local header = p.header(frame, isLegacy);
if hc(header) then
return header;
end
return p.main(frame, isLegacy);
end
function p.header(frame, isLegacy)
local title = mw.title.getCurrentTitle();
-- subpage header
local isDoc = title.subpageText == 'doc' or yn(frame.args.demo);
if (isDoc or not isLegacy) then
local _, args, opts, page = processArgs(frame, true);
local onModule = title.namespace == 828
local ret = mw.html.create( 'table' )
:addClass( 'messagebox' )
:addClass( 'info' )
:tag( 'tr' )
:tag( 'td' )
:css( 'width', '40px' )
:wikitext( '[[File:Information icon-grey.svg|35px|centre|link=]]' )
:done()
:tag( 'td' )
:tag( 'b' )
:wikitext( 'This is a documentation subpage for [[' .. page .. ']].' )
:done()
:tag( 'div' )
:css({ ['font-size'] = '0.85em', ['line-height'] = '1.4em' })
:wikitext(
string.format(
'It contains usage information, categories, and other content that is not part of the original %s page.',
onModule and 'module' or 'template'
)
)
:done()
:done()
:done()
:done()
local ret2, cats = p._dependencyListAndToc(title, args, opts, {
-- Namespaces with dependency lists:
[10] = true, -- Template namespace
[116] = true, -- Calculator namespace
[828] = true, -- Module namespace
});
if isDoc then
if (isLegacy and hc(args.content)) then
ret2 = ret2 .. "\n" .. args.content;
end
return tostring(ret) .. ret2 .. (cats or "")
end
return ret2
end
return "";
end
function p.main(frame, isLegacy)
local title, args, opts, _, docPage = processArgs(frame, isLegacy);
local ret, cats, ret1, ret2, ret3
local onModule = title.namespace == 828
-- template header
-- don't use mw.html as we aren't closing the main div tag
ret1 = '<div class="documentation">'
ret2 = mw.html.create( nil )
:tag( 'div' )
:addClass( 'documentation-header' )
:tag( 'span' )
:addClass( 'documentation-title' )
:wikitext( string.format('%s documentation', onModule and 'Module' or 'Template') )
:done()
:done()
:tag( 'div' )
:addClass( 'documentation-subheader' )
:tag( 'span' )
:addClass( 'documentation-documentation' )
:wikitext( 'This documentation is transcluded from [[' .. docPage .. ']]. ' )
:done()
:tag( 'span' )
:addClass( 'documentation-links plainlinks' )
:wikitext(
'[[' .. tostring( mw.uri.fullUrl(docPage, {action='edit'} ) ) .. ' edit]] ' ..
'[[' .. tostring( mw.uri.fullUrl(docPage, {action='history'} ) ) .. ' history]] ' ..
'[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, {action='purge'} ) ) .. ' purge]</span>]'
)
:done()
:done()
ret3 = isLegacy and (p._dependencyListAndToc(title, args, opts)) or ""
if yn(args.isData, false) and title.namespace == 828 then
ret3 = ret3 .. '[[Category:Data modules]]'
end
local mboxes = "";
if hc(args.mboxes) then
mboxes = args.mboxes;
end
if hc(args.content) then
ret3 = ret3 .. "\n"
.. args.content
.. "\n</div></div>";
elseif (not isLegacy) then
local docContent = "{{:" .. docPage .. "}}";
ret3 = ret3 .. "\n"
.. frame:preprocess(docContent)
.. "\n</div></div>";
end
return ret1
.. tostring( ret2 )
.. '<div class="documentation-content">'
.. ret3;
end
function p._dependencyListAndToc(title, args, opts, depListCatNums)
local addDependencyList = yn(args.DependencyList, true);
if (addDependencyList == nil) then addDependencyList = true; end
local addModuleToc = yn(args.ModuleToc, true);
if (addModuleToc == nil) then addModuleToc = true; end
local cats;
local toc = {};
if (
addDependencyList
and (not depListCatNums or depListCatNums[title.namespace])
) then
table.insert(toc, dependencyList._main(nil, args.category, args.isUsed));
end
if title.namespace == 10 then -- Template namespace
cats = '[[Category:Template documentation|' .. title.baseText .. ']]'
elseif title.namespace == 828 then -- Module namespace
cats = '[[Category:Module documentation|' .. title.baseText .. ']]'
table.insert(toc, addModuleToc and require('Module:Module toc').main() or nil);
if yn(args.isData, false) then
table.insert(toc, '<div class="seealso"><code>mw.loadData</code> compatible</div>')
end
end
if hc(opts.preamble) then
table.insert(toc, 1, opts.preamble);
end
return table.concat(toc), cats;
end
return p