Content added Content deleted
(fix revision id code) |
(clean up the env table functions and the comments) |
||
Line 158: | Line 158: | ||
function p.getEnvironment(args) |
function p.getEnvironment(args) |
||
--[[ |
|||
-- Returns a table with information about the environment, including |
-- Returns a table with information about the environment, including title objects and other namespace- 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.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: |
-- Data includes: |
||
⚫ | |||
-- env.subjectSpace - the number of the title's subject namespace. |
-- env.subjectSpace - the number of the title's subject namespace. |
||
-- env. |
-- env.docSpace - the number of the namespace the title puts its documentation in. |
||
-- env. |
-- env.docpageRoot - the text of the base page of the /doc, /sandbox and /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 = {}, {} |
local env, envFuncs = {}, {} |
||
-- Set up the metatable. If |
-- Set up the metatable. If triggered we call the corresponding function in the envFuncs table. The value |
||
-- in the env table so we don't |
-- returned by that function is memoized in the env table so that we don't call any of the functions |
||
-- more than once. (Nils won't be memoized.) |
|||
setmetatable(env, { |
setmetatable(env, { |
||
__index = function (t, key) |
__index = function (t, key) |
||
Line 198: | Line 212: | ||
end |
end |
||
return title |
return title |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- The name of the documentation namespace. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return env.title.subjectNsText |
|||
⚫ | |||
⚫ | |||
⚫ | |||
-- The template page with no namespace or interwiki prefixes. |
|||
⚫ | |||
local subpage = title.subpageText |
|||
if subpage == message('sandboxSubpage', 'string') or subpage == message('testcasesSubpage', 'string') then |
|||
⚫ | |||
else |
|||
return title.text |
|||
end |
|||
end |
end |
||
Line 250: | Line 236: | ||
end |
end |
||
return mw.title.new(docpage) |
return mw.title.new(docpage) |
||
end |
|||
⚫ | |||
function envFuncs.docpageRoot() |
|||
⚫ | |||
⚫ | |||
local title = env.title |
|||
return (env.docspace or title.nsText) .. ':' .. (env.templatePage or title.text) |
|||
end |
end |
||
Line 271: | Line 250: | ||
function envFuncs.printTitle() |
function envFuncs.printTitle() |
||
-- Title object for the /Print subpage. |
-- Title object for the /Print subpage. |
||
return |
return env.templateTitle:subPageTitle(message('printSubpage', 'string')) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- The documentation namespace number. For most namespaces this is the same as the |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return subjectSpace + 1 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local templateTitle = env.templateTitle |
|||
⚫ | |||
⚫ | |||
-- Assemble the link. docSpace is never the main namespace, so we can hardcode the colon. |
|||
return docSpaceText .. ':' .. templateTitle.text |
|||
end |
end |
||
Line 685: | Line 691: | ||
function p.makeEndBoxExperimentBlurb(args, env) |
function p.makeEndBoxExperimentBlurb(args, env) |
||
-- Renders the text "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages." |
-- 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 subjectSpace = env.subjectSpace |
||
⚫ | |||
-- Get title objects. |
|||
local templateTitle = env.templateTitle |
local templateTitle = env.templateTitle |
||
local sandboxTitle = env.sandboxTitle |
local sandboxTitle = env.sandboxTitle |
||
local testcasesTitle = env.testcasesTitle |
local testcasesTitle = env.testcasesTitle |
||
⚫ | |||
if not templateTitle or not sandboxTitle or not testcasesTitle then |
if not subjectSpace or not templateTitle or not sandboxTitle or not testcasesTitle then |
||
return nil |
return nil |
||
end |
end |