This documentation is transcluded from Module:Log/doc. Changes can be proposed in the talk page.
This module is unused.
This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add
{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
L 11 — methodtable.makeOutput L 45 — methodtable.setFrame L 53 — Log.main L 78 — Log.info L 87 — Log.success L 96 — Log.warning L 105 — Log.error L 112 — Log.new |
This is an internal module intended for the output of information and error messages.
local Log = {} local metatable = {} local methodtable = {} metatable.__index = methodtable --- Creates the actual output, either a HTML comment if options.silent is true, or a mw-message-box --- @param severity string --- @param message string function methodtable.makeOutput( self, severity, message ) local currentDate = mw.getContentLanguage():formatDate( 'c' ) if type( message ) ~= 'string' and type( message ) ~= 'number' then message = 'Message must be of type \'string\' or \'number\'.' end local content -- Output as HTML Comment if self.options.silent ~= nil then content = string.format( '[%s] - %s: %s', currentDate, severity, message ) content = mw.html.create( 'p' ) :css( 'display', 'none' ) :wikitext( content ) else -- Output as HTML content = mw.html.create( 'p' ) :addClass( 'log' ) :addClass( 'mw-message-box' ) :addClass( 'mw-message-box-' .. severity ) :attr( 'title', currentDate ) :wikitext( message ) end return tostring( content ) end --- Set the frame and load args --- @param frame table function methodtable.setFrame( self, frame ) self.currentFrame = frame self.frameArgs = require( 'Module:Arguments' ).getArgs( frame ) end --- Template entry --- @param frame table function Log.main( frame ) local instance = Log:new() instance:setFrame( frame ) local severity = string.lower( instance.frameArgs[ 1 ] or instance.frameArgs[ 'severity' ] or 'info' ) local message = instance.frameArgs[ 2 ] or instance.frameArgs[ 'message' ] local silent = string.lower( instance.frameArgs[ 3 ] or instance.frameArgs[ 'silent' ] or '' ) if silent == '1' or silent == 'true' then silent = true else silent = nil end instance.options = { silent = silent } return instance:makeOutput( severity, message ) end --- Output an info log --- @param message string The message Content --- @param options table Output options function Log.info( message, options ) local instance = Log:new( options ) return instance:makeOutput( 'info', message ) end --- Output a success log --- @param message string The message Content --- @param options table Output options function Log.success( message, options ) local instance = Log:new( options ) return instance:makeOutput( 'success', message ) end --- Output a warning log --- @param message string The message Content --- @param options table Output options function Log.warning( message, options ) local instance = Log:new( options ) return instance:makeOutput( 'warning', message ) end --- Output a error log --- @param message string The message Content --- @param options table Output options function Log.error( message, options ) local instance = Log:new( options ) return instance:makeOutput( 'error', message ) end --- New Instance function Log.new( self, options ) if options == true then options = { silent = true } else options = options or {} end local instance = { options = options } setmetatable( instance, metatable ) return instance end return Log