Module:DetectMarkup
Appearance
[edit] Documentation
Purpose
[edit]This module is designed for use in Wikimedia templates to detect whether a page contains cleanup-related draft markup.
It returns "true" if any supported cleanup templates are present in the page's wikitext, and "false" otherwise.
The module currently detects the following templates, in any capitalization and with or without parameters:
This functionality supports automated workflows that identify draft-only markup in articles, allowing templates and tools to take appropriate action (such as warnings, styling changes, or conditional display).
Usage
[edit]This module is typically invoked within a template to conditionally display content based on whether a page includes any cleanup templates detected by the module.
Basic Usage in a Template
[edit]{{#invoke:DetectMarkup|detectMarkup}}
- Returns
"true"if the page contains: - Returns
"false"if none of the supported templates are present.
Conditional Display Example
[edit]{{#switch: {{#invoke:DetectMarkup|detectMarkup}}
| true = <span style="color:orange;">Draft-only markup detected on this page.</span>
| false = <span style="color:green;">No cleanup markup detected.</span>
| #default = <span style="color:gray;">Unable to determine markup status.</span>
}}
How It Works
[edit]- The module retrieves the raw wikitext of the current page.
- It checks for any occurrence of supported cleanup templates.
- Matching is case-insensitive (e.g.,
Template:VERIFY,,Template:VErIfYall match). - Named or unnamed parameters are allowed (e.g.,
somethingorfoo).
- Matching is case-insensitive (e.g.,
- If at least one supported template is found, the module returns
"true". - If none are found, the module returns
"false".
Limitations
[edit]- The module checks only the page’s raw wikitext. If a supported template is transcluded indirectly (via another template), it may not be detected.
- Only the templates explicitly listed in the module are detected. Additional templates can be added by modifying the
templatesToDetecttable.
local p = {}
-- List of templates to detect. Can be expanded in the future.
-- Currently detects:
-- {{verify}} – any case, with or without parameters
-- {{highlight}} – any case, with or without parameters
local templatesToDetect = {
"verify",
"highlight"
}
function p.detectMarkup(frame)
local title = mw.title.getCurrentTitle()
local content = title:getContent()
if not content then
return "false"
end
-- Loop through each template name and check for its presence (case-insensitive)
for _, template in ipairs(templatesToDetect) do
-- Base pattern: {{ template [ | or } ]
local pattern = "{{%s*" .. template .. "%s*[|}]"
if mw.ustring.match(content, pattern)
or mw.ustring.match(content, pattern:lower())
or mw.ustring.match(content, pattern:upper())
then
return "true"
end
-- Case-insensitive match using Lua pattern magic
local ciPattern = "{{%s*[" ..
template:sub(1,1):lower() .. template:sub(1,1):upper() ..
"]" ..
template:sub(2):gsub(".", function(c)
return "[" .. c:lower() .. c:upper() .. "]"
end) ..
"%s*[|}]"
if mw.ustring.match(content, ciPattern) then
return "true"
end
end
return "false"
end
return p