Module:Hatnote: Difference between revisions

    m>Mr. Stradivarius
    (don't categorise talk namespaces)
    m>Mr. Stradivarius
    (update the makeWikitextError function - don't use Module:Category handler, and use an addTrackingCategory parameter instead of a demo parameter, to make it easy for daughter modules to add a category=no parameter)
    Line 11: Line 11:
    local mArguments -- lazily initialise [[Module:Arguments]]
    local mArguments -- lazily initialise [[Module:Arguments]]
    local yesno -- lazily initialise [[Module:Yesno]]
    local yesno -- lazily initialise [[Module:Yesno]]
    local mCategoryHandler -- lazily initialise [[Module:Category handler]]


    local p = {}
    local p = {}
    Line 76: Line 75:
    end
    end


    function p.makeWikitextError(msg, demo)
    function p.makeWikitextError(msg, addTrackingCategory)
    -- Formats an error message to be returned to wikitext. If demo is not nil
    -- Formats an error message to be returned to wikitext. If
    -- or false, no error category is added.
    -- addTrackingCategory is not false after being returned from
    -- [[Module:Yesno]], and if we are not on a talk page, a tracking category
    -- is added.
    checkType('makeWikitextError', 1, msg, 'string')
    checkType('makeWikitextError', 1, msg, 'string')
    yesno = require('Module:Yesno')
    yesno = require('Module:Yesno')
    mCategoryHandler = require('Module:Category handler')
    local title = mw.title.getCurrentTitle()
    local errorCategory = 'Hatnote templates with errors'
    local category
    local errorCategoryLink = string.format(
    if not title.isTalkPage and yesno(addTrackingCategory) ~= false then
    '[[%s:%s]]',
    category = 'Hatnote templates with errors'
    mw.site.namespaces[14].name,
    category = string.format(
    errorCategory
    '[[%s:%s]]',
    )
    mw.site.namespaces[14].name,
    -- Feed the category link through [[Module:Category handler]] so we can
    category
    -- use its blacklist.
    )
    errorCategoryLink = mCategoryHandler.main{
    else
    talk = '', -- Don't categorise talk namespaces.
    category = ''
    other = errorCategoryLink,
    end
    nocat = demo
    }
    errorCategoryLink = errorCategoryLink or ''
    return string.format(
    return string.format(
    '<strong class="error">Error: %s.</strong>%s',
    '<strong class="error">Error: %s.</strong>%s',
    msg,
    msg,
    errorCategoryLink
    category
    )
    )
    end
    end