Module:Unsigned
From Portals of Phereon Wiki
Original version from https://minecraft.gamepedia.com/Module:Unsigned
p.unsigned
implements {{unsigned}}
and {{undated}}
.
p.auto
implements {{autoUnsigned}}
Dependencies[]
- Module:ProcessArgs (
p.unsigned
only) - Module:IPAddress
local p = {}
function base( args )
local type = args.type or 'Unsigned'
local user = args.user
local date = args.date
if date and not date:find( '%(UTC%)$' ) then
date = date .. ' (UTC)'
end
local nowiki = ''
if mw.isSubsting() then
nowiki = '<nowiki/>'
end
local text = {
'<small>–Preceding ' .. mw.ustring.lower( type ) .. ' comment was added',
'. Please sign your posts with ~~' .. nowiki .. '~~</small>'
}
if date then
table.insert( text, 2, ' at ' .. date )
end
if user then
local userLinks
if not user:find( '[^:%x%.%d]' ) and require( 'Module:IPAddress' ).isIP( user ) then
userLinks = '[[Special:Contribs/' .. user .. '|' .. user .. ']] ([[User talk:' .. user .. '|talk]])'
else
userLinks = '[[User:' .. user .. '|' .. user .. ']] ([[User talk:' .. user .. '|talk]] • [[Special:Contribs/' .. user .. '|contribs]])'
end
table.insert( text, 2, ' by ' .. userLinks )
end
return table.concat( text )
end
p.unsigned = function( f )
local args = require( 'Module:ProcessArgs' ).norm( f.args or f )
local type = args.type or 'Unsigned'
local user = args.user
local date = args.date
local category = { '<!-- Template:' .. type .. ' -->' }
if mw.isSubsting() then
-- Don't allow substitution with missing required arg
if type == 'Unsigned' and not user then
local dateArg = ''
if date then
dateArg = '||' .. date
end
return '{{Unsigned' .. dateArg .. '}}'
elseif type == 'Undated' and not date then
return '{{Undated}}'
end
elseif mw.title:getCurrentTitle().namespace ~= 10 then
if type == 'Unsigned' and not user then
table.insert( category, '[[Category:Unsigned template used incorrectly]]' )
elseif type == 'Undated' and not date then
table.insert( category, '[[Category:Undated template used incorrectly]]' )
end
table.insert( category, '[[Category:Pages with templates requiring substitution]]' )
end
return base( args ) .. table.concat( category )
end
p.auto = function( f )
if mw.isSubsting() or mw.title:getCurrentTitle().namespace == 10 then
local date = string.lower( f.args.date or f.date )
local args = {
user = f:preprocess( '{{safesubst:REVISIONUSER: {{safesubst:FULLPAGENAME}}}}' ),
date = f:preprocess( '{{safesubst:#timel:G:i, d F Y|{{safesubst:REVISIONTIMESTAMP: {{safesubst:FULLPAGENAME}} }}}}' )
}
if date == '1' or date == 'only' then
args.type = 'Undated'
args.user = nil
elseif date == '0' or date == 'none' then
args.date = nil
end
return base( args ) .. '<!-- Template:AutoUnsigned -->'
else
return '<span class="error">Template:AutoUnsigned must be substituted</span>[[Category:AutoUnsigned template used incorrectly]]'
end
end
return p