Module:DetectMarkup
Appearance
[edit] Documentation
Purpose
[edit]This module is designed for use in Wikimedia templates to detect whether a page contains the {{verify}} template. It returns "true" if {{verify}} is present in the page's wikitext, and "false" otherwise.
This functionality supports automated workflows that help identify markup in draft articles, enabling template logic or tools to take appropriate action based on whether cleanup markup is present.
Usage
[edit]This module is typically invoked within a template to conditionally display content based on whether the page includes {{verify}}.
Basic Usage in a Template
[edit]{{#invoke:DetectMarkup|detectMarkup}}
- Returns
"true"if the page contains{{verify}}(with or without parameters). - Returns
"false"if the template is not present.
Conditional Display Example
[edit]This example changes output based on the result from the module:
{{#switch: {{#invoke:DetectMarkup|detectMarkup}}
| true = <span style="color:orange;">This page contains markup for verification.</span>
| false = <span style="color:green;">No verification markup detected on this page.</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 if
{{verify}}appears in the wikitext, allowing for optional parameters. - If the template is found, the module returns
"true". - If not found, the module returns
"false".
Limitations
[edit]local p = {}
-- List of templates to detect. Can be expanded in the future.
local templatesToDetect = {
"verify"
}
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
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