Changes
clean up the env table functions and the comments
function p.getEnvironment(args)
--[[ -- Returns a table with information about the environment, including title objects and other namespace- or -- path-related data. -- -- Title objects include: -- env.title - the page we are making documentation for (usually the current title to use) -- env.templateTitle - the template (or module, the subject namespacefile, etc.) -- env.docTitle - the /doc subpage. -- env.sandboxTitle - the /sandbox subpage. -- This is called from penv._main using pcall in case we get any errors from exceeding testcasesTitle - the expensive function count/testcases subpage. -- limitenv.printTitle - the print version of the template, or other perils unknownlocated at the /Print subpage.
--
-- Data includes:
-- env.subjectSpace - the number of the title's subject namespace.
-- env.docspace docSpace - the name number of the namespace the title puts its documentation in. -- env.templatePage docpageRoot - the name text of the template base page of the /doc, /sandbox and /testcases pages, with no namespace or interwiki prefixes. -- env.compareLink - a URL link of the Special:ComparePages page comparing the sandbox with the template. -- -- All table lookups are passed through pcall so that errors are caught. If an error occurs, the value -- returned will be nil. --]]
local env, envFuncs = {}, {}
-- Set up the metatable. If a nil value is called, triggered we call that the corresponding function in the envFuncs table and memoize it. The value -- returned by that function is memoized in the env table so that we don't have to call any of the functions -- more than once.(Nils won't be memoized.)
setmetatable(env, {
__index = function (t, key)
end
return title
end
end
return mw.title.new(docpage)
end
function envFuncs.printTitle()
-- Title object for the /Print subpage.
return env.templateTitle:subPageTitle(message('printSubpage', 'string')) end function envFuncs.subjectSpace() -- The subject namespace number. return mw.site.namespaces[env.title.newnamespace].subject.id end function envFuncs.docSpace() -- The documentation namespace number. For most namespaces this is the same as the -- subject namespace. However, pages in the Article, File, MediaWiki or Category -- namespaces must have their /doc, /sandbox and /testcases pages in talk space. local subjectSpace = env.subjectSpace if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then return subjectSpace + 1 else return subjectSpace end end function envFuncs.docpageRoot() -- The base page of the /doc, /sandbox, and /testcases subpages. -- For some namespaces this is the talk page, rather than the template page. local templateTitle = env.templateTitle local docSpace = env.templatePage docSpace local docSpaceText = mw.site. '/' namespaces[docSpace].name -- Assemble the link. message('printSubpage'docSpace is never the main namespace, so we can hardcode the colon. return docSpaceText .. 'string:')).. templateTitle.text
end
function p.makeEndBoxExperimentBlurb(args, env)
-- Renders the text "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages."
-- Get environment data.
local subjectSpace = env.subjectSpace
local templateTitle = env.templateTitle
local sandboxTitle = env.sandboxTitle
local testcasesTitle = env.testcasesTitle
local templatePage = templateTitle.prefixedText if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then
return nil
end