Anonymous user
Module:Documentation: Difference between revisions
clean up the env table functions and the comments
(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
-- path-related data.
--
-- Title objects include:
-- env.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.
-- env.
-- 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
-- returned by that function is memoized in the env table so that we don't
-- 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()▼
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▼
end▼
end▼
function envFuncs.templatePage()▼
local title = env.title▼
return title.baseText▼
end
Line 250 ⟶ 236:
end
return mw.title.new(docpage)
-- The base page of the /doc, /sandbox, and /testcases subpages.▼
-- For some namespaces this is the talk page, rather than the template page.▼
end
Line 271 ⟶ 250:
function envFuncs.printTitle()
-- Title object for the /Print subpage.
return
▲ end
▲ function envFuncs.subjectSpace()
▲ -- The subject namespace number.
▲ return mw.site.namespaces[env.title.namespace].subject.id
▲ end
-- The documentation namespace number. For most namespaces this is the same as the
▲
▲ local subjectSpace = env.subjectSpace
▲ if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
return subjectSpace + 1
▲ else
▲ end
▲ end
▲ -- 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
-- 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▼
local templateTitle = env.templateTitle
local sandboxTitle = env.sandboxTitle
local testcasesTitle = env.testcasesTitle
if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then
return nil
end
|