Editing Module:Reporter
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page is not enabled for semantic in-text annotations due to namespace restrictions. Details about how to enable the namespace can be found on the configuration help page.
Latest revision | Your text | ||
Line 8: | Line 8: | ||
local mwHtmlCreate = mw.html.create | local mwHtmlCreate = mw.html.create | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
--[[Doc | --[[Doc | ||
Line 33: | Line 25: | ||
function Reporter.new( title ) | function Reporter.new( title ) | ||
local data = { -- TODO: use local references as fields? | local data = { -- TODO: use local references as fields? | ||
− | |||
_categories = {}, | _categories = {}, | ||
_warnings = {}, | _warnings = {}, | ||
Line 51: | Line 42: | ||
]] | ]] | ||
function Reporter:setTitle( title ) | function Reporter:setTitle( title ) | ||
− | self._title = tostring( title or '' | + | self._title = title ~= nil and tostring( title ) or '' -- TODO: default to better name? Escape title? Accept nil to avoid default category? |
return self | return self | ||
Line 57: | Line 48: | ||
--[[Doc | --[[Doc | ||
− | @method Reporter | + | @method Reporter getTitle |
− | @description | + | @description Gets the instance title. |
− | @ | + | @return {string} The instance title. |
− | |||
− | |||
]] | ]] | ||
− | function Reporter: | + | function Reporter:getTitle() |
− | self. | + | return self._title |
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 116: | Line 100: | ||
end | end | ||
− | local function formatCategory( | + | local function formatCategory( name, sortkey ) |
− | return ( sortkey and '[[Category: | + | return ( sortkey |
− | + | and table.concat{ | |
+ | '[[Category:', name, '|', sortkey, ']]' | ||
+ | } | ||
+ | or table.concat{ | ||
+ | '[[Category:', name, ']]' | ||
+ | } | ||
+ | ) | ||
end | end | ||
--[[Doc | --[[Doc | ||
− | @ | + | @method Reporter dumpCategories |
]] | ]] | ||
local function dumpCategories( self ) | local function dumpCategories( self ) | ||
Line 130: | Line 120: | ||
or | or | ||
self._errors.exists | self._errors.exists | ||
− | ) and | + | ) and table.concat{ |
+ | '[[Category:((', self._title, ')) transclusions to be checked]]' | ||
+ | }, | ||
} | } | ||
for index, categoryPair in ipairs( self._categories ) do | for index, categoryPair in ipairs( self._categories ) do | ||
− | table.insert( | + | table.insert( categories, formatCategory( categoryPair[ 1 ], categoryPair[ 2 ] ) ) |
− | |||
− | |||
− | |||
end | end | ||
Line 152: | Line 141: | ||
for _, warning in ipairs( self._warnings ) do | for _, warning in ipairs( self._warnings ) do | ||
− | container: | + | container:node( |
+ | tostring( mwHtmlCreate( 'li' ) | ||
+ | :wikitext( warning ) | ||
+ | ) | ||
+ | ) | ||
end | end | ||
Line 167: | Line 160: | ||
for _, err in ipairs( self._errors ) do | for _, err in ipairs( self._errors ) do | ||
− | container: | + | container:node( |
+ | tostring( mwHtmlCreate( 'li' ) | ||
+ | :wikitext( err ) | ||
+ | ) | ||
+ | ) | ||
end | end | ||
Line 173: | Line 170: | ||
end | end | ||
− | |||
− | |||
− | |||
function Reporter:dump() | function Reporter:dump() | ||
− | return | + | return table.concat{ |
− | + | '<div class="reporter">', | |
− | + | dumpCategories( self ), | |
− | + | self._warnings.exists and dumpWarnings( self ) or '', | |
− | + | self._errors.exists and dumpErrors( self ) or '', | |
− | + | '</div>', | |
+ | } | ||
end | end | ||
Line 190: | Line 185: | ||
]=] | ]=] | ||
return setmetatable( Reporter, { | return setmetatable( Reporter, { | ||
− | __call = function( t, | + | __call = function( t, ... ) |
assert( | assert( | ||
t == Reporter, | t == Reporter, | ||
Line 196: | Line 191: | ||
) | ) | ||
− | return Reporter.new( | + | return Reporter.new( ... ) |
end | end | ||
} ) | } ) | ||
-- </pre> | -- </pre> |