Jump to content

Module:DetectDraft

From Wikinews, the free news source you can write!
[edit] Documentation

Purpose

This module is designed for use in Wikimedia templates to determine whether a page contains any of the following draft or maintenance templates:

It returns "true" if any of these templates are present in the page's wikitext, and "false" otherwise.

Standard Wikinews conventions dictate that articles move through draft and maintenance stages before publication. Typical sequences include {{develop}} → {{review}} → {{tasks}} (if needed) → {{published}}, or {{stale}} / {{abandoned}} / {{delete}} if not progressing. Therefore, if an article contains one of the checked templates, it is assumed to be a draft or under maintenance.

Usage

This module is typically invoked within a template to conditionally display content based on whether the page includes any of the above templates.

Basic Usage in a Template

{{#invoke:DetectDraft|detectTemplates}}
  • Returns "true" if the page contains any of the draft or maintenance templates listed above.
  • Returns "false" if none of these templates are present.

Conditional Display Example

This example changes output based on the result from the module:

{{#switch: {{#invoke:DetectDraft|detectTemplates}}
  | true  = <span style="color:green;">This page is under development, review, or maintenance.</span>
  | false = <span style="color:red;">This page is not marked as under development or maintenance.</span>
  | #default = <span style="color:gray;">Unable to determine page status.</span>
}}

How It Works

  1. The module retrieves the wikitext of the current page.
  2. It checks if any of the supported templates appear in the wikitext (case insensitive).
  3. If one or more are found, the module returns "true".
  4. If none are found, it returns "false".

Limitations

  • The module only checks the raw wikitext of the page. If one of the supported templates is transcluded indirectly via another template, it may not be detected.
  • The module does not validate template parameters. It only checks for presence.
local p = {}

function p.detectTemplates(frame)
    local title = mw.title.getCurrentTitle()
    local content = title:getContent()
    
    if not content then
        return "false"
    end
    
    -- Check if the page contains {{develop}}, {{review}}, or {{tasks}}
    if content:match("{{%s*[Dd]evelop%s*}}") 
        or content:match("{{%s*[Rr]eview%s*}}")
        or content:match("{{%s*[Bb]reaking%s*[Rr]eview%s*}}")
        or content:match("{{%s*[Tt]asks%s*[|}]")
        or content:match("{{%s*[Dd]elete%s*[|}]")
        or content:match("{{%s*[Ss]tale[^}]*}}")
        or content:match("{{%s*[Aa]bandoned[^}]*}}") then
        return "true"
    else
        return "false"
    end
end

return p