Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Documentation: Difference between revisions

Content added Content deleted
(fix revision id code)
(clean up the env table functions and the comments)
Line 158:
 
function p.getEnvironment(args)
--[[
-- Returns a table with information about the environment, including the title to use,objects theand subjectother namespace,- etc.or
-- This is called from p._main using pcall in case we get any errors from exceeding the expensive function count
-- path-related data.
-- limit, or other perils unknown.
--
-- Title objects include:
-- env.title - the title object of the page we are making documentation for (usually the current title)
-- env.templateTitle - the template (or module, file, etc.)
-- env.docTitle - the /doc subpage.
-- env.sandboxTitle - the /sandbox subpage.
-- env.testcasesTitle - the /testcases subpage.
-- env.printTitle - the print version of the template, located at the /Print subpage.
--
-- Data includes:
-- env.title - the title object of the page we are making documentation for (usually the current title)
-- env.subjectSpace - the number of the title's subject namespace.
-- env.docspacedocSpace - the namenumber of the namespace the title puts its documentation in.
-- env.templatePagedocpageRoot - the nametext of the templatebase page withof nothe namespace/doc, or/sandbox interwikiand prefixes/testcases pages, with namespace.
-- 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 thatthe corresponding function in the envFuncs table. andThe memoize itvalue
-- 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.
-- more than once. (Nils won't be memoized.)
setmetatable(env, {
__index = function (t, key)
Line 198 ⟶ 212:
end
return title
end
 
function envFuncs.subjectSpace()
-- The subject namespace number.
return mw.site.namespaces[env.title.namespace].subject.id
end
 
function envFuncs.docspace()
-- The name of the documentation namespace.
local subjectSpace = env.subjectSpace
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
-- Pages in the Article, File, MediaWiki or Category namespaces must have their
-- /doc, /sandbox and /testcases pages in talk space.
return mw.site.namespaces[subjectSpace].talk.name
else
return env.title.subjectNsText
end
end
 
function envFuncs.templatePage()
-- The template page with no namespace or interwiki prefixes.
local title = env.title
local subpage = title.subpageText
if subpage == message('sandboxSubpage', 'string') or subpage == message('testcasesSubpage', 'string') then
return title.baseText
else
return title.text
end
end
 
Line 250 ⟶ 236:
end
return mw.title.new(docpage)
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 title = env.title
return (env.docspace or title.nsText) .. ':' .. (env.templatePage or title.text)
end
Line 271 ⟶ 250:
function envFuncs.printTitle()
-- Title object for the /Print subpage.
return mwenv.title.newtemplateTitle:subPageTitle(env.templatePage .. '/' .. message('printSubpage', 'string'))
end
 
function envFuncs.subjectSpace()
-- The subject namespace number.
return mw.site.namespaces[env.title.namespace].subject.id
end
 
function envFuncs.docspacedocSpace()
-- The documentation namespace number. For most namespaces this is the same as the
-- Pagessubject namespace. However, pages in the Article, File, MediaWiki or Category namespaces must have their
-- 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 title.baseTextsubjectSpace
end
end
 
function envFuncs.templatePagedocpageRoot()
-- 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 titledocSpace = env.titledocSpace
returnlocal docSpaceText = mw.site.namespaces[subjectSpacedocSpace].talk.name
-- Assemble the link. docSpace is never the main namespace, so we can hardcode the colon.
return docSpaceText .. ':' .. templateTitle.text
end
Line 685 ⟶ 691:
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 templatePage = env.templatePage
-- Get title objects.
local templateTitle = env.templateTitle
local sandboxTitle = env.sandboxTitle
local testcasesTitle = env.testcasesTitle
local templatePage = envtemplateTitle.templatePageprefixedText
if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then
return nil
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.