Module:User error: Difference between revisions

From The Satanic Wiki
Jump to navigation Jump to search
(Created page with "-- <nowiki> -------------------------------------------------------------------------------- -- A less intimidating version of the built-in "error()" function, to help -- edit...")
 
No edit summary
 
Line 7: Line 7:


return function (message, ...)
return function (message, ...)
     checkType('Dev:User error', 1, message, 'string')
     checkType('Module:User error', 1, message, 'string')


     local element = mw.html.create('strong')
     local element = mw.html.create('strong')
Line 16: Line 16:
         local category = select(i, ...)
         local category = select(i, ...)


         checkType('Dev:User error', i + 1, category, 'string')
         checkType('Module:User error', i + 1, category, 'string')


         if category ~= '' then
         if category ~= '' then

Latest revision as of 05:13, 2 May 2021

Documentation for this module may be created at Module:User error/doc

-- <nowiki>
--------------------------------------------------------------------------------
-- A less intimidating version of the built-in "error()" function, to help
-- editors fix their mistakes when transcluding a template.
--------------------------------------------------------------------------------
local checkType = require('libraryUtil').checkType

return function (message, ...)
    checkType('Module:User error', 1, message, 'string')

    local element = mw.html.create('strong')
        :addClass('error')
        :wikitext('Error: ' .. message .. '.')

    for i = 1, select('#', ...) do
        local category = select(i, ...)

        checkType('Module:User error', i + 1, category, 'string')

        if category ~= '' then
            element:wikitext('[[Category:' .. category .. ']]')
        end
    end

    return tostring(element)
end

-- </nowiki>
-- (Add categories here.)