Editing Module:Reporter

Jump to: navigation, search

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
 
local namespace = mw.title.getCurrentTitle().namespace
 
 
local canDumpCategories = (
 
namespace ~= 10
 
and
 
namespace % 2 == 0
 
)
 
  
 
--[[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?
_canDumpCategories = canDumpCategories,
 
 
_categories = {},
 
_categories = {},
 
_warnings  = {},
 
_warnings  = {},
Line 51: Line 42:
 
]]
 
]]
 
function Reporter:setTitle( title )
 
function Reporter:setTitle( title )
self._title = tostring( title or '' ) -- TODO: default to better name? Escape title? Accept nil to avoid default category?
+
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 dumpCategoriesWhen
+
@method Reporter getTitle
@description Changes the verification for when the categories can be dumped.
+
@description Gets the instance title.
@parameter {function} predicate A predicate that will receive the current
+
@return {string} The instance title.
value of the flag and the default value.
 
@return {Reporter} `self`
 
 
]]
 
]]
function Reporter:dumpCategoriesWhen( predicate )
+
function Reporter:getTitle()
self._canDumpCategories = predicate(
+
return self._title
self._canDumpCategories,
 
canDumpCategories
 
)
 
 
 
return self
 
 
end
 
end
  
Line 116: Line 100:
 
end
 
end
  
local function formatCategory( self, name, sortkey )
+
local function formatCategory( name, sortkey )
return ( sortkey and '[[Category:((%s)) %s|%s]]' or '[[Category:((%s)) %s]]' )
+
return ( sortkey
:format( self._title, name, sortkey )
+
and table.concat{
 +
'[[Category:', name, '|', sortkey, ']]'
 +
}
 +
or table.concat{
 +
'[[Category:', name, ']]'  
 +
}
 +
)
 
end
 
end
  
 
--[[Doc
 
--[[Doc
@function dumpCategories
+
@method Reporter dumpCategories
 
]]
 
]]
 
local function dumpCategories( self )
 
local function dumpCategories( self )
Line 130: Line 120:
 
or
 
or
 
self._errors.exists
 
self._errors.exists
) and formatCategory( self, 'transclusions to be checked', ' ' )
+
) 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 ] ) )
categories,
 
formatCategory( self, 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:tag( 'li' ):wikitext( warning )
+
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:tag( 'li' ):wikitext( err )
+
container:node(
 +
tostring( mwHtmlCreate( 'li' )
 +
:wikitext( err )
 +
)
 +
)
 
end
 
end
  
Line 173: Line 170:
 
end
 
end
  
--[[Doc
 
@method Reporter dump
 
]]
 
 
function Reporter:dump()
 
function Reporter:dump()
return tostring( mwHtmlCreate( 'div' )
+
return table.concat{
:addClass( 'reporter' )
+
'<div class="reporter">',
:node( self._canDumpCategories and dumpCategories( self ) )
+
dumpCategories( self ),
:node( self._errors.exists and dumpErrors( self ) )
+
self._warnings.exists and dumpWarnings( self ) or '',
:node( self._warnings.exists and dumpWarnings( self ) )
+
self._errors.exists and dumpErrors( self ) or '',
)
+
'</div>',
 +
}
 
end
 
end
  
Line 190: Line 185:
 
]=]
 
]=]
 
return setmetatable( Reporter, {
 
return setmetatable( Reporter, {
__call = function( t, title )
+
__call = function( t, ... )
 
assert(
 
assert(
 
t == Reporter,
 
t == Reporter,
Line 196: Line 191:
 
)
 
)
  
return Reporter.new( title )
+
return Reporter.new( ... )
 
end
 
end
 
} )
 
} )
 
-- </pre>
 
-- </pre>

Please note that all contributions to Yugipedia are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International License (see Yugipedia:Licensing for more details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)
Preview page with this template
Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above.

View this template