Module:Dochead: Difference between revisions

Ganaram inukshuk (talk | contribs)
undo changes to add wikipedia sidebox (not even rswiki does anything akin to "see documentation on wikipedia")
Tag: Manual revert
Ganaram inukshuk (talk | contribs)
for options that don't explicitly require a corresponding template/module, have the option to turn off corresponding-page detection (default is true)
Line 2: Line 2:
local getArgs = require("Module:Arguments").getArgs
local getArgs = require("Module:Arguments").getArgs
local iutils  = require("Module:Introspection utils")
local iutils  = require("Module:Introspection utils")
local yesno  = require("Module:Yesno")


local p = {}
local p = {}
Line 46: Line 47:


-- Helper function to handle modules
-- Helper function to handle modules
function p.make_module_hatnote(header, pagename, corr_template)
function p.make_module_hatnote(header, pagename, corr_template, detect_corr_page)
-- Check whether corresponding template exists
-- Check whether corresponding template exists
-- Then check whether that template invokes the module
-- Then check whether that template invokes the module
Line 56: Line 57:
end
end
-- Check whether to use detect_corr_page option
-- If the header option is dualuse, metatemplate, or noinvoke, this option
-- is ignored. For any other option, it's not.
if header ~= "dualuse" or header ~= "metatemplate" or header ~= "noinvoke" then
has_template = has_template and detect_corr_page
end
-- Heading meanings and usage on module
-- - dualuse means a template is implement by a module, but its template may
--  be bypassed by using its module directly from other modules.
-- - metatemplate is a special case of dualuse; the template-module pair is
--  for a metatemplate, a template used to build other templates.
-- - noinvoke indicates a lua-based template, but the module's code is so
--  specialized that its code should not be used by other modules or
--  invoked by other templates.
-- - metamodule and library indicate a module whose code is used mainly for
--  other modules. Such modules generally don't have a corresponding
--  template.
-- Does the module have a template?
-- - dualuse, metatemplate, and noinvoke: YES (REQUIRED!!)
-- - metamodule/library: GENERALLY NO
local result = ""
local result = ""
if header == "dualuse" then
if header == "dualuse" then
Line 132: Line 154:


-- Helper function to handle templates
-- Helper function to handle templates
function p.make_template_hatnote(header, pagename, corr_module)
function p.make_template_hatnote(header, pagename, corr_module, detect_corr_page)
-- Check whether corresponding module exists
-- Check whether corresponding module exists
-- 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) and detect_corr_page
local wikitext = iutils.get_and_preprocess_content("Template", pagename)
local wikitext = iutils.get_and_preprocess_content("Template", pagename)
local invokes = iutils.find_invokes(wikitext)
local invokes = iutils.find_invokes(wikitext)
local is_module_invoked = iutils.invocation_exists(invokes, corr_module)
local is_module_invoked = iutils.invocation_exists(invokes, corr_module)


-- Find all invocations for the template
-- Find all invocations for the template and add it as an addl hatnote.
local invocation_hatnote = make_invocation_hatnote(invokes)
local invocation_hatnote = make_invocation_hatnote(invokes)
-- Check whether to use detect_corr_page option
-- If the header option is dualuse or metatemplate, this option is ignored.
-- For any other option, it's not (although it also has no effect on
-- noinvoke or library/metamodule).
if header ~= "dualuse" or header ~= "metatemplate" then
has_module = has_module and detect_corr_page
end
-- Heading meanings and usage on templates
-- - dualuse means a template is implement by a module, but its template may
--  be bypassed by using its module directly from other modules.
-- - metatemplate is a special case of dualuse; the template-module pair is
--  for a metatemplate, a template used to build other templates.
-- - noinvoke and metamodule/library don't have use for templates.
-- Does the template have a module?
-- - dualuse and metatemplate: YES (REQUIRED!!)
-- - noinvoke and metamodule/library: options don't apply to templates.
-- RATIONALE FOR NOINVOKE NOT APPLYING: a template may invoke functions from
-- more than one module, but one of them must be the "main" module. Since
-- there's no way to autodetect that, that info must be manually entered.
-- If that doesn't happen
local result = ""
local result = ""
if header == "dualuse" then
if header == "dualuse" then
Line 152: Line 195:
elseif has_module and not is_module_invoked then
elseif has_module and not is_module_invoked then
result = string.format(
result = string.format(
"This template has a corresponding Lua module [[Module:%s]] that it does not use.",
"This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.",
corr_module
corr_module
)
)
Line 170: Line 213:
elseif has_module and not is_module_invoked then
elseif has_module and not is_module_invoked then
result = string.format(
result = string.format(
"This metatemplate has a corresponding Lua module [[Module:%s]] that it does not use.",
"This metatemplate has a corresponding Lua module [[Module:%s]], but does not invoke its functions.",
corr_module
corr_module
)
)
Line 189: Line 232:
elseif has_module and header ~= "" and not is_module_invoked then
elseif has_module and header ~= "" and not is_module_invoked then
result = string.format(
result = string.format(
"%s. This template has a corresponding Lua module [[Module:%s]] that it does not use.",
"%s. This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.",
header,
header,
corr_module
corr_module
Line 200: Line 243:
elseif has_module and header == "" and not is_module_invoked then
elseif has_module and header == "" and not is_module_invoked then
result = string.format(
result = string.format(
"This template has a corresponding Lua module [[Module:%s]] that it does not use.",
"This template has a corresponding Lua module [[Module:%s]], but does not invoke its functions.",
corr_module
corr_module
)
)
Line 227: Line 270:
local corr_template = args["temp"] or pagename
local corr_template = args["temp"] or pagename
local corr_module  = args["mod"]  or pagename
local corr_module  = args["mod"]  or pagename
local detect_corr_page = args["detect_corr_page"]


-- If header is none, skip everything
-- If header is none, skip everything
Line 277: Line 321:
args["temp"] = args["temp"] or args["pagename"]
args["temp"] = args["temp"] or args["pagename"]
args["mod" ] = args["mod" ] or args["pagename"]
args["mod" ] = args["mod" ] or args["pagename"]
-- Option to detect corresponding page
args["detect_corr_page"] = yesno(args["detect_corr_page"], true)


return p._dochead(args)
return p._dochead(args)