Module:Sprite: Difference between revisions
Inverted conditions are confusing. |
Add protection information to doc data |
||
| Line 188: | Line 188: | ||
local settings = mw.loadData( 'Module:' .. settingsPage ) | local settings = mw.loadData( 'Module:' .. settingsPage ) | ||
local idsPage = 'Module:' .. ( settings.ids or settings.name .. '/IDs' ) | local idsPage = 'Module:' .. ( settings.ids or settings.name .. '/IDs' ) | ||
local getProtection = function( title, action, extra ) | |||
local protections = { 'edit' } | |||
if extra then | |||
table.insert( protections, extra ) | |||
end | |||
local addProtection = function( protection ) | |||
if protection == 'autoconfirmed' then | |||
protection = 'editsemiprotected' | |||
elseif protection == 'sysop' then | |||
protection = 'editprotected' | |||
end | |||
table.insert( protections, protection ) | |||
end | |||
local direct = title.protectionLevels[action] | |||
for _, protection in ipairs( direct ) do | |||
addProtection( protection ) | |||
end | |||
local cascading = title.cascadingProtection.restrictions[action] or {} | |||
if #cascading > 0 then | |||
table.insert( protections, 'protect' ) | |||
end | |||
for _, protection in ipairs( cascading ) do | |||
addProtection( protection ) | |||
end | |||
return table.concat( protections, ',' ) | |||
end | |||
local body | local body | ||
| Line 193: | Line 224: | ||
body = mw.html.create( '' ) | body = mw.html.create( '' ) | ||
else | else | ||
local | local idsTitle = mw.title.new( idsPage ) | ||
local spritesheet = settings.image or settings.name .. 'Sprite.png' | |||
local spriteTitle = mw.title.new( 'File:' .. spritesheet ) | |||
local idsProtection = getProtection( idsTitle, 'edit' ) | |||
local spriteProtection = getProtection( spriteTitle, 'upload', 'upload,reupload' ) | |||
body = mw.html.create( 'div' ):attr( { | body = mw.html.create( 'div' ):attr( { | ||
id = 'spritedoc', | id = 'spritedoc', | ||
['data-idspage'] = | ['data-idspage'] = idsTitle.id, | ||
['data-idstimestamp'] = ' | ['data-idsprotection'] = idsProtection, | ||
['data- | ['data-idstimestamp'] = f:callParserFunction( 'REVISIONTIMESTAMP', idsPage ), | ||
['data-spritesheet'] = spritesheet, | |||
['data-spriteprotection'] = spriteProtection, | |||
['data-pos'] = settings.pos or 1, | ['data-pos'] = settings.pos or 1, | ||
['data-refreshtext'] = mw.text.nowiki( '{{#invoke:sprite|doc|' .. settingsPage .. '|refresh=1}}' ) | ['data-refreshtext'] = mw.text.nowiki( '{{#invoke:sprite|doc|' .. settingsPage .. '|refresh=1}}' ) | ||