Module:Dochead: Difference between revisions
temporarily disable categories for none header, pending a proper fix |
autocategorize metatemplates |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 74: | Line 74: | ||
else | else | ||
result = string.format( | result = string.format( | ||
"This module has a | "This module has a corresponding template that is currently missing or does not use this module. ([[Special:EditPage/Template:%s|edit template]])", | ||
corr_template:gsub("/doc$", "") | corr_template:gsub("/doc$", "") | ||
) | ) | ||
| Line 92: | Line 92: | ||
if has_template then | if has_template then | ||
result = string.format( | result = string.format( | ||
"This module should not be invoked directly; use its corresponding instead: [[Template:%s]].", | "This module should not be invoked directly; use its corresponding template instead: [[Template:%s]].", | ||
corr_template:gsub("/doc$", "") | corr_template:gsub("/doc$", "") | ||
) | ) | ||
| Line 107: | Line 107: | ||
elseif header == "data" or pagename:gsub("/doc$", ""):match("/data$") then | elseif header == "data" or pagename:gsub("/doc$", ""):match("/data$") then | ||
result = "This module primarily serves to provide data values for other modules and has no corresponding template." | result = "This module primarily serves to provide data values for other modules and has no corresponding template." | ||
elseif header == "none" then | |||
result = "" | |||
else | else | ||
| Line 125: | Line 128: | ||
return "" .. cats | return "" .. cats | ||
else | else | ||
return string.format(":''%s''%s\n", result, cats) | return string.format(": ''%s''%s\n", result, cats) | ||
end | end | ||
end | end | ||
-- Helper function: categorize template | -- Helper function: categorize template | ||
local function categorize_template(pagename, has_invoke) | local function categorize_template(pagename, has_invoke, is_metatemplate) | ||
local cats = "" | local cats = "" | ||
if pagename:match("/doc$") then | if pagename:match("/doc$") then | ||
| Line 138: | Line 141: | ||
if has_invoke then | if has_invoke then | ||
cats = cats .. " [[Category:Lua-based templates]]" | cats = cats .. " [[Category:Lua-based templates]]" | ||
end | |||
if is_metatemplate then | |||
cats = cats .. " [[Category:Metatemplates]]" | |||
end | end | ||
end | end | ||
| Line 264: | Line 270: | ||
-- Categorize | -- Categorize | ||
local cats = categorize_template(pagename, #invokes > 0) | local cats = categorize_template(pagename, #invokes > 0, header == "metatemplate") | ||
if result == "" and invocation_hatnote == "" then | if header == "none" then | ||
return cats | |||
elseif result == "" and invocation_hatnote == "" then | |||
return "" | return "" | ||
elseif result == "" and invocation_hatnote ~= "" then | elseif result == "" and invocation_hatnote ~= "" then | ||
return string.format(":''%s''%s\n", invocation_hatnote, cats) | return string.format(": ''%s''%s\n", invocation_hatnote, cats) | ||
elseif result ~= "" and invocation_hatnote == "" then | elseif result ~= "" and invocation_hatnote == "" then | ||
return string.format(":''%s''%s\n", result, cats) | return string.format(": ''%s''%s\n", result, cats) | ||
else | else | ||
return string.format(":''%s''\n:''%s''%s\n", result, invocation_hatnote, cats) | return string.format(": ''%s''\n: ''%s'' %s\n", result, invocation_hatnote, cats) | ||
end | end | ||
end | end | ||
| Line 301: | Line 309: | ||
result = p.make_template_hatnote(header, pagename, corr_module, detect_corr_page) | 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 | ||
| Line 331: | Line 339: | ||
-- Option to detect corresponding page (default true) | -- Option to detect corresponding page (default true) | ||
args["detect_corr_page"] = args["detect_corr_page"] == nil and true or yesno(args["detect_corr_page"]) | args["detect_corr_page"] = args["detect_corr_page"] == nil and true or yesno(args["detect_corr_page"]) | ||
local result = p._dochead(args) | |||
-- Debugger option to show generated WikiText | |||
local wtext = yesno(frame.args["wtext"] or args["wtext"]) | |||
if wtext == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return | return frame:preprocess(result) | ||
end | end | ||