Module:Dochead: Difference between revisions
todo |
No edit summary |
||
| Line 47: | Line 47: | ||
end | end | ||
return cats | |||
end | |||
-- Helper function: categorize modules | |||
local function categorize_module(pagename) | |||
local cats = "" | |||
if pagename:match("/doc$") then | |||
cats = "[[Category:Module documentation]]" | |||
else | |||
cats = "[[Category:Lua modules]]" | |||
end | |||
return cats | return cats | ||
end | end | ||
| Line 55: | Line 66: | ||
-- Then check whether that template invokes the module | -- Then check whether that template invokes the module | ||
local has_template = iutils.page_exists("Template:" .. corr_template) | local has_template = iutils.page_exists("Template:" .. corr_template) | ||
-- Check whether to use detect_corr_page option | -- Check whether to use detect_corr_page option | ||
| Line 66: | Line 72: | ||
if header ~= "dualuse" and header ~= "metatemplate" and header ~= "noinvoke" then | if header ~= "dualuse" and header ~= "metatemplate" and header ~= "noinvoke" then | ||
has_template = has_template and detect_corr_page | has_template = has_template and detect_corr_page | ||
end | |||
-- If the module has a template, check for whether it invokes it. | |||
if has_template then | |||
local wikitext = iutils.get_and_preprocess_content("Template", corr_template) | |||
local invokes = iutils.find_invokes(wikitext) | |||
has_template = has_template and iutils.invocation_exists(invokes, pagename) | |||
end | end | ||
| Line 132: | Line 145: | ||
end | end | ||
-- Produce categories | |||
local cats = categorize_module(pagename) | |||
-- Return | |||
if result == "" then | if result == "" then | ||
return "" | return "" .. cats | ||
else | else | ||
return string.format(":''%s''", result) | return string.format(":''%s''", result) .. cats | ||
end | end | ||
end | |||
-- Helper function: categorize template | |||
local function categorize_template(pagename, has_invoke) | |||
local cats = "" | |||
if pagename:match("/doc$") then | |||
cats = "[[Category:Template documentation]]" | |||
else | |||
cats = "[[Category:Templates]]" | |||
if has_invoke then | |||
cats = cats .. " [[Category:Lua-based templates]]" | |||
end | |||
end | |||
return cats | |||
end | end | ||
| Line 162: | Line 193: | ||
-- Then check whether this template invokes the module | -- Then check whether this template invokes the module | ||
local has_module = iutils.page_exists("Module:" .. corr_module) | local has_module = iutils.page_exists("Module:" .. corr_module) | ||
-- Check whether to use detect_corr_page option | -- Check whether to use detect_corr_page option | ||
| Line 176: | Line 201: | ||
has_module = has_module and detect_corr_page | has_module = has_module and detect_corr_page | ||
end | end | ||
-- Check for whether the template invokes that module, regardless of whether | |||
-- it uses the corresponding module. | |||
local wikitext = iutils.get_and_preprocess_content("Template", pagename) | |||
local invokes = iutils.find_invokes(wikitext) | |||
local is_module_invoked = iutils.invocation_exists(invokes, corr_module) | |||
-- Heading meanings and usage on templates | -- Heading meanings and usage on templates | ||
| Line 254: | Line 285: | ||
end | end | ||
end | end | ||
-- Find all invocations for the template and add it as an addl hatnote. | |||
local invocation_hatnote = make_invocation_hatnote(invokes) | |||
-- Categorize | |||
local cats = categorize_template(pagename, #invokes > 0) | |||
if result == "" and invocation_hatnote == "" then | if result == "" and invocation_hatnote == "" then | ||
return "" | return "" | ||
elseif result == "" and invocation_hatnote ~= "" then | elseif result == "" and invocation_hatnote ~= "" then | ||
return string.format(":''%s''", invocation_hatnote) | return string.format(":''%s''", invocation_hatnote) .. cats | ||
elseif result ~= "" and invocation_hatnote == "" then | elseif result ~= "" and invocation_hatnote == "" then | ||
return string.format(":''%s''", result) | return string.format(":''%s''", result) .. cats | ||
else | else | ||
return string.format(":''%s''\n:''%s''", result, invocation_hatnote) | return string.format(":''%s''\n:''%s''", result, invocation_hatnote) .. cats | ||
end | end | ||
end | end | ||
| Line 283: | Line 320: | ||
-- Call appropriate hatnote-making function | -- Call appropriate hatnote-making function | ||
-- Remove /doc suffix if this is on a /doc page to ensure links are made | -- Remove /doc suffix if this is on a /doc page to ensure links are made | ||
-- properly. | -- properly. :gsub("/doc$", "") | ||
local result = "" | local result = "" | ||
if namespace == "Module" then | if namespace == "Module" then | ||
result = p.make_module_hatnote(header, pagename | result = p.make_module_hatnote(header, pagename, corr_template, detect_corr_page) | ||
elseif namespace == "Template" then | elseif namespace == "Template" then | ||
result = p.make_template_hatnote(header, pagename | result = p.make_template_hatnote(header, pagename, corr_module, detect_corr_page) | ||
else | else | ||
result = ":''This documentation template is in the wrong namespace. It should be within the Template or Module namespaces.''\n" | result = ":''This documentation template is in the wrong namespace. It should be within the Template or Module namespaces.''\n" | ||
end | end | ||
return result | |||
end | end | ||