Module:Sprite : Différence entre versions

De Minecraft Wiki
Aller à : navigation, rechercher
m (Uncategorized --> Sans catégorie)
 
(2 révisions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
 
local p = {}
 
local p = {}
function p.base(f)
+
function p.base( f )
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
+
args = require( 'Module:ProcessArgs' ).merge( true )
else
+
else
f = mw.getCurrentFrame()
+
f = mw.getCurrentFrame()
end
+
end
  +
 
local data = args.data and mw.loadData('Module:' .. args.data) or {}
+
local data = args.data and mw.loadData( 'Module:' .. args.data ) or {}
local settings = data.settings
+
local settings = data.settings
  +
 
-- Default settings
+
-- Default settings
local default = {
+
local default = {
scale = 1,
+
scale = 1,
sheetsize = 256,
+
sheetsize = 256,
size = 16,
+
size = 16,
pos = 1,
+
pos = 1,
align = 'text-top'
+
align = 'text-top'
  +
}
}
 
  +
 
local defaultStyle = default
+
local defaultStyle = default
if settings then
+
if settings then
if not settings.stylesheet then
+
if not settings.stylesheet then
-- Make a separate clone of the current default settings
+
-- Make a separate clone of the current default settings
defaultStyle = mw.clone(default)
+
defaultStyle = mw.clone( default )
end
+
end
for k, v in pairs(settings) do default[k] = v end
+
for k, v in pairs( settings ) do
  +
default[k] = v
end
 
  +
end
 
  +
end
local setting = function(arg) return args[arg] or default[arg] end
 
  +
 
  +
local setting = function( arg )
local sprite = mw.html.create('span'):addClass('sprite')
 
  +
return args[arg] or default[arg]
sprite:tag('br')
 
  +
end
 
  +
-- mw.html's css method performs very slow escaping, which doubles the time it takes
 
  +
local sprite = mw.html.create( 'span' ):addClass( 'sprite' )
-- to run, so we'll construct the styles manually, and put them in the cssText
 
  +
sprite:tag( 'br' )
-- method, which only does html escaping (which isn't slow)
 
  +
local styles = {}
 
  +
-- mw.html's css method performs very slow escaping, which doubles the time it takes
 
  +
-- to run, so we'll construct the styles manually, and put them in the cssText
if setting('url') then
 
  +
-- method, which only does html escaping (which isn't slow)
styles[#styles + 1] = 'background-image:' .. setting('url')
 
  +
local styles = {}
end
 
  +
if setting('stylesheet') then
 
sprite:addClass(setting('classname') or
+
if setting( 'url' ) then
  +
styles[#styles + 1] = 'background-image:' .. setting( 'url' )
mw.ustring.lower(setting('name'):gsub(' ', '-')) ..
 
  +
end
'-sprite')
 
elseif not setting('url') then
+
if setting( 'stylesheet' ) then
  +
sprite:addClass(
styles[#styles + 1] = 'background-image:' ..
 
  +
setting( 'classname' ) or
p.getUrl(
 
setting('image') or setting('name') ..
+
mw.ustring.lower( setting( 'name' ):gsub( ' ', '-' ) ) .. '-sprite'
  +
)
'Sprite.png')
 
  +
elseif not setting( 'url' ) then
end
 
  +
styles[#styles + 1] = 'background-image:' .. p.getUrl(
local class = setting('class')
 
  +
setting( 'image' ) or setting( 'name' ) .. 'Sprite.png'
if class then sprite:addClass(class) end
 
  +
)
 
  +
end
local size = setting('size')
 
local sheetWidth = setting('sheetsize')
+
local class = setting( 'class' )
  +
if class then
local tiles = sheetWidth / size
 
  +
sprite:addClass( class )
local pos = setting('pos') - 1
 
  +
end
local scale = setting('scale')
 
  +
local autoScale = setting('autoscale')
 
  +
local size = setting( 'size' )
 
  +
local sheetWidth = setting( 'sheetsize' )
if pos then
 
local left = pos % tiles * size * scale
+
local tiles = sheetWidth / size
local top = math.floor(pos / tiles) * size * scale
+
local pos = setting( 'pos' ) - 1
  +
local scale = setting( 'scale' )
styles[#styles + 1] =
 
  +
local autoScale = setting( 'autoscale' )
'background-position:-' .. left .. 'px -' .. top .. 'px'
 
  +
end
 
  +
if pos then
 
  +
local left = pos % tiles * size * scale
if not autoScale and scale ~= defaultStyle.scale then
 
  +
local top = math.floor( pos / tiles ) * size * scale
styles[#styles + 1] = 'background-size:' .. sheetWidth * scale ..
 
  +
styles[#styles + 1] = 'background-position:-' .. left .. 'px -' .. top .. 'px'
'px auto'
 
end
+
end
  +
if size ~= defaultStyle.size or
 
(not autoScale and scale ~= defaultStyle.scale) then
+
if not autoScale and scale ~= defaultStyle.scale then
styles[#styles + 1] = 'height:' .. size * scale .. 'px'
+
styles[#styles + 1] = 'background-size:' .. sheetWidth * scale .. 'px auto'
  +
end
styles[#styles + 1] = 'width:' .. size * scale .. 'px'
 
  +
if size ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then
end
 
  +
styles[#styles + 1] = 'height:' .. size * scale .. 'px'
 
  +
styles[#styles + 1] = 'width:' .. size * scale .. 'px'
local align = setting('align')
 
  +
end
if align ~= defaultStyle.align then
 
  +
styles[#styles + 1] = 'vertical-align:' .. align
 
  +
local align = setting( 'align' )
end
 
  +
if align ~= defaultStyle.align then
styles[#styles + 1] = setting('css')
 
  +
styles[#styles + 1] = 'vertical-align:' .. align
 
  +
end
sprite:cssText(table.concat(styles, ';'))
 
  +
styles[#styles + 1] = setting( 'css' )
 
  +
local text = setting('text')
 
  +
sprite:cssText( table.concat( styles, ';' ) )
local root
 
  +
local spriteText
 
if text then
+
local text = setting( 'text' )
  +
local root
root = mw.html.create('span'):addClass('nowrap')
 
  +
local spriteText
spriteText = mw.html.create('span'):addClass('sprite-text'):wikitext(
 
  +
if text then
text)
 
  +
root = mw.html.create( 'span' ):addClass( 'nowrap' )
end
 
  +
spriteText = mw.html.create( 'span' ):addClass( 'sprite-text' ):wikitext( text )
 
  +
end
local title = setting('title')
 
  +
if title then (root or sprite):attr('title', title) end
 
  +
local title = setting( 'title' )
 
  +
if title then
local link = setting('link') or ''
 
  +
( root or sprite ):attr( 'title', title )
if link ~= '' and mw.ustring.lower(link) ~= 'none' then
 
  +
end
-- External link
 
  +
if link:find('//') then
 
  +
if not root then
return '[' .. link .. ' ' .. tostring(root) .. ']'
 
  +
root = mw.html.create( '' )
end
 
  +
end
 
  +
root:node( sprite )
-- Internal link
 
  +
if spriteText then
local linkPrefix = setting('linkprefix') or ''
 
  +
root:node( spriteText )
return '[[' .. linkPrefix .. link .. '|' .. tostring(root) .. ']]'
 
end
+
end
  +
 
  +
local link = setting( 'link' ) or ''
if not root then root = mw.html.create('') end
 
  +
if link ~= '' and mw.ustring.lower( link ) ~= 'none' then
root:node(sprite)
 
  +
-- External link
if spriteText then root:node(spriteText) end
 
  +
if link:find( '//' ) then
 
return tostring(root)
+
return '[' .. link .. ' ' .. tostring( root ) .. ']'
  +
end
  +
  +
-- Internal link
  +
local linkPrefix = setting( 'linkprefix' ) or ''
  +
return '[[' .. linkPrefix .. link .. '|' .. tostring( root ) .. ']]'
  +
end
  +
  +
return tostring( root )
 
end
 
end
   
function p.sprite(f)
+
function p.sprite( f )
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
+
args = require( 'Module:ProcessArgs' ).merge( true )
else
+
else
f = mw.getCurrentFrame()
+
f = mw.getCurrentFrame()
end
+
end
  +
 
local data = args.data and mw.loadData('Module:' .. args.data) or {}
+
local data = args.data and mw.loadData( 'Module:' .. args.data ) or {}
local categories = {}
+
local categories = {}
local idData = args.iddata
+
local idData = args.iddata
if not idData then
+
if not idData then
local name = args.name or data.settings.name
+
local name = args.name or data.settings.name
local id = mw.text.trim(tostring(args[1] or ''))
+
local id = mw.text.trim( tostring( args[1] or '' ) )
idData = data.ids[id] or
+
idData = data.ids[id] or data.ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )]
  +
end
data.ids[mw.ustring.lower(id):gsub('[%s%+]', '-')]
 
  +
end
 
  +
local title = mw.title.getCurrentTitle()
 
  +
-- Remove categories on language pages, talk pages, and in User/UserWiki/UserProfile namespaces
local title = mw.title.getCurrentTitle()
 
  +
local disallowCats = args.nocat or title.isTalkPage or title.nsText:find( '^Utilisateur' )
-- Remove categories on language pages, talk pages, and in User/UserWiki/UserProfile namespaces
 
  +
if idData then
local disallowCats = args.nocat or title.isTalkPage or
 
  +
if idData.deprecated and not disallowCats then
title.nsText:find('^Utilisateur')
 
  +
categories[#categories + 1] = '[[Catégorie:Pages utilisant des noms de sprites obsolètes]]'
if idData then
 
  +
if args[1] then
if idData.deprecated and not disallowCats then
 
  +
categories[#categories + 1] = '[[Catégorie:Pages utilisant le sprite obsolète ' .. mw.ustring.lower(mw.ustring.gsub(args[1], ' ', '-')) .. ']]'
categories[#categories + 1] =
 
  +
end
'[[Catégorie:Pages utilisant des noms de sprites obsolètes]]'
 
  +
end
if args[1] then
 
  +
categories[#categories + 1] =
 
  +
args.pos = idData.pos
'[[Catégorie:Pages utilisant le sprite obsolète ' ..
 
  +
elseif not disallowCats then
mw.ustring.lower(mw.ustring.gsub(args[1], ' ', '-')) ..
 
  +
categories[#categories + 1] = '[[Catégorie:Pages avec des sprites manquants]]'
']]'
 
  +
end
end
 
  +
end
 
  +
return p.base( args ), table.concat( categories )
 
args.pos = idData.pos
 
elseif not disallowCats then
 
categories[#categories + 1] =
 
'[[Catégorie:Pages avec des sprites manquants]]'
 
end
 
 
return p.base(args), table.concat(categories)
 
 
end
 
end
   
function p.link(f)
+
function p.link( f )
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
+
args = require( 'Module:ProcessArgs' ).merge( true )
end
+
end
  +
 
local link = args[1]
+
local link = args[1]
if args[1] and not args.id then
+
if args[1] and not args.id then
link = args[1]:match('^(.-)%+') or args[1]
+
link = args[1]:match( '^(.-)%+' ) or args[1]
end
+
end
local text
+
local text
if not args.notext then text = args.text or args[2] or link end
+
if not args.notext then
  +
text = args.text or args[2] or link
 
  +
end
args[1] = args.id or args[1]
 
  +
args.link = args.link or link
 
args.text = text
+
args[1] = args.id or args[1]
  +
args.link = args.link or link
 
  +
args.text = text
return p.sprite(args)
 
  +
  +
return p.sprite( args )
 
end
 
end
   
function p.getUrl(spritesheet, query)
+
function p.getUrl( spritesheet, query )
return mw.getCurrentFrame():expandTemplate{
+
return mw.getCurrentFrame():expandTemplate{ title = 'FileUrl', args = { spritesheet, query = query } }
title = 'FileUrl',
 
args = {spritesheet, query = query}
 
}
 
 
end
 
end
   
function p.doc(f)
+
function p.doc( f )
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = f.args
+
args = f.args
else
+
else
f = mw.getCurrentFrame()
+
f = mw.getCurrentFrame()
end
+
end
local dataPage = mw.text.trim(args[1])
+
local dataPage = mw.text.trim( args[1] )
local data = mw.loadData('Module:' .. dataPage)
+
local data = mw.loadData( 'Module:' .. dataPage )
  +
 
local getProtection = function(title, action, extra)
+
local getProtection = function( title, action, extra )
local protections = {'edit'}
+
local protections = { 'edit' }
if extra then protections[#protections + 1] = extra end
+
if extra then
  +
protections[#protections + 1] = extra
 
  +
end
local addProtection = function(protection)
 
  +
if protection == 'autoconfirmed' then
 
protection = 'editsemiprotected'
+
local addProtection = function( protection )
elseif protection == 'sysop' then
+
if protection == 'autoconfirmed' then
protection = 'editprotected'
+
protection = 'editsemiprotected'
  +
elseif protection == 'sysop' then
end
 
  +
protection = 'editprotected'
 
  +
end
protections[#protections + 1] = protection
 
  +
end
 
  +
protections[#protections + 1] = protection
 
  +
end
local direct = title.protectionLevels[action] or {}
 
  +
for _, protection in ipairs(direct) do addProtection(protection) end
 
local cascading = title.cascadingProtection.restrictions[action] or {}
+
local direct = title.protectionLevels[action] or {}
  +
for _, protection in ipairs( direct ) do
if #cascading > 0 then protections[#protections + 1] = 'protect' end
 
for _, protection in ipairs(cascading) do
+
addProtection( protection )
  +
end
addProtection(protection)
 
  +
local cascading = title.cascadingProtection.restrictions[action] or {}
end
 
  +
if #cascading > 0 then
 
  +
protections[#protections + 1] = 'protect'
return table.concat(protections, ',')
 
end
+
end
  +
for _, protection in ipairs( cascading ) do
 
  +
addProtection( protection )
local dataTitle = mw.title.new('Module:' .. dataPage)
 
  +
end
local spritesheet = data.settings.image or data.settings.name ..
 
  +
'Sprite.png'
 
  +
return table.concat( protections, ',' )
local spriteTitle = mw.title.new('File:' .. spritesheet)
 
  +
end
local dataProtection = getProtection(dataTitle, 'edit')
 
  +
local spriteProtection = getProtection(spriteTitle, 'upload',
 
  +
local dataTitle = mw.title.new( 'Module:' .. dataPage )
'upload,reupload')
 
  +
local spritesheet = data.settings.image or data.settings.name .. 'Sprite.png'
local body = mw.html.create('div'):attr(
 
  +
local spriteTitle = mw.title.new( 'File:' .. spritesheet )
{
 
  +
local dataProtection = getProtection( dataTitle, 'edit' )
id = 'spritedoc',
 
  +
local spriteProtection = getProtection( spriteTitle, 'upload', 'upload,reupload' )
['data-dataprotection'] = dataProtection,
 
  +
local body = mw.html.create( 'div' ):attr( {
['data-datatimestamp'] = f:callParserFunction('REVISIONTIMESTAMP',
 
  +
id = 'spritedoc',
'Module:' .. dataPage),
 
['data-datapage'] = 'Module:' .. dataPage,
+
['data-dataprotection'] = dataProtection,
  +
['data-datatimestamp'] = f:callParserFunction( 'REVISIONTIMESTAMP', 'Module:' .. dataPage ),
['data-spritesheet'] = spritesheet,
 
['data-spriteprotection'] = spriteProtection,
+
['data-datapage'] = 'Module:' .. dataPage,
  +
['data-spritesheet'] = spritesheet,
['data-urlfunc'] = "require( [[Module:Sprite]] ).getUrl( '" ..
 
  +
['data-spriteprotection'] = spriteProtection,
spritesheet .. "', '$1' )",
 
  +
['data-urlfunc'] = "require( [[Module:Sprite]] ).getUrl( '" .. spritesheet .. "', '$1' )",
['data-refreshtext'] = mw.text.nowiki(
 
'{{#invoke:sprite|doc|' .. dataPage .. '|refresh=1}}'),
+
['data-refreshtext'] = mw.text.nowiki( '{{#invoke:sprite|doc|' .. dataPage .. '|refresh=1}}' ),
['data-settings'] = mw.text.jsonEncode(data.settings)
+
['data-settings'] = mw.text.jsonEncode( data.settings ),
  +
} )
})
 
  +
 
local sections = {}
+
local sections = {}
for _, sectionData in ipairs(data.sections or {name = 'Uncategorized'}) do
+
for _, sectionData in ipairs( data.sections or { name = 'Sans catégorie' } ) do
local sectionTag = body:tag('div'):addClass('spritedoc-section'):attr(
+
local sectionTag = body:tag( 'div' ):addClass( 'spritedoc-section' ):attr( 'data-section-id', sectionData.id )
'data-section-id', sectionData.id)
+
sectionTag:tag( 'h3' ):wikitext( sectionData.name )
sectionTag:tag('h3'):wikitext(sectionData.name)
+
sections[sectionData.id] = { boxes = sectionTag:tag( 'ul' ):addClass( 'spritedoc-boxes' ) }
  +
end
sections[sectionData.id] = {
 
  +
boxes = sectionTag:tag('ul'):addClass('spritedoc-boxes')
 
  +
local keyedData = {}
}
 
  +
local i = 1
end
 
  +
for name, idData in pairs( data.ids ) do
 
local keyedData = {}
+
keyedData[i] = {
  +
sortKey = mw.ustring.lower( name ),
local i = 1
 
  +
name = name,
for name, idData in pairs(data.ids) do
 
  +
data = idData
keyedData[i] = {
 
  +
}
sortKey = mw.ustring.lower(name),
 
  +
i = i + 1
name = name,
 
  +
end
data = idData
 
  +
table.sort( keyedData, function( a, b )
}
 
  +
return a.sortKey < b.sortKey
i = i + 1
 
  +
end )
end
 
  +
table.sort(keyedData, function(a, b) return a.sortKey < b.sortKey end)
 
  +
for _, data in ipairs( keyedData ) do
 
  +
local idData = data.data
for _, data in ipairs(keyedData) do
 
local idData = data.data
+
local pos = idData.pos
local pos = idData.pos
+
local section = sections[idData.section]
local section = sections[idData.section]
+
local names = section[pos]
local names = section[pos]
+
if not names then
  +
local box = section.boxes:tag( 'li' ):addClass( 'spritedoc-box' ):attr( 'data-pos', pos )
if not names then
 
local box = section.boxes:tag('li'):addClass('spritedoc-box'):attr(
+
box:tag( 'div' ):addClass( 'spritedoc-image' )
  +
:wikitext( p.base{ pos = pos, data = dataPage } )
'data-pos', pos)
 
  +
box:tag('div'):addClass('spritedoc-image'):wikitext(
 
  +
names = box:tag( 'ul' ):addClass( 'spritedoc-names' )
p.base {pos = pos, data = dataPage})
 
  +
section[pos] = names
 
  +
end
names = box:tag('ul'):addClass('spritedoc-names')
 
  +
local nameElem = mw.html.create( 'li' ):addClass( 'spritedoc-name' )
section[pos] = names
 
  +
local codeElem = nameElem:tag( 'code' ):wikitext( data.name )
end
 
  +
local nameElem = mw.html.create('li'):addClass('spritedoc-name')
 
  +
if idData.deprecated then
local codeElem = nameElem:tag('code'):wikitext(data.name)
 
  +
codeElem:addClass( 'spritedoc-deprecated' )
 
  +
end
if idData.deprecated then
 
  +
names:wikitext( tostring( nameElem ) )
codeElem:addClass('spritedoc-deprecated')
 
end
+
end
  +
names:wikitext(tostring(nameElem))
 
  +
if args.refresh then
end
 
  +
return '', tostring( body )
 
  +
end
if args.refresh then return '', tostring(body) end
 
return f:callParserFunction('#widget:SpriteDoc.css'), tostring(body)
+
return f:callParserFunction( '#widget:SpriteDoc.css' ), tostring( body )
 
end
 
end
 
return p
 
return p

Version actuelle datée du 8 avril 2021 à 08:23

[créer | historique | purger]Documentation
Ce module n'a pas de documentation. Si vous savez comment l'utiliser, merci de la créer.
local p = {}
function p.base( f )
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	
	local data = args.data and mw.loadData( 'Module:' .. args.data ) or {}
	local settings = data.settings
	
	-- Default settings
	local default = {
		scale = 1,
		sheetsize = 256,
		size = 16,
		pos = 1,
		align = 'text-top'
	}
	
	local defaultStyle = default
	if settings then
		if not settings.stylesheet then
			-- Make a separate clone of the current default settings
			defaultStyle = mw.clone( default )
		end
		for k, v in pairs( settings ) do
			default[k] = v
		end
	end
	
	local setting = function( arg )
		return args[arg] or default[arg]
	end
	
	local sprite = mw.html.create( 'span' ):addClass( 'sprite' )
	sprite:tag( 'br' )
	
	-- mw.html's css method performs very slow escaping, which doubles the time it takes
	-- to run, so we'll construct the styles manually, and put them in the cssText
	-- method, which only does html escaping (which isn't slow)
	local styles = {}
	
	if setting( 'url' ) then
		styles[#styles + 1] = 'background-image:' .. setting( 'url' )
	end
	if setting( 'stylesheet' ) then
		sprite:addClass(
			setting( 'classname' ) or
			mw.ustring.lower( setting( 'name' ):gsub( ' ', '-' ) ) .. '-sprite'
		)
	elseif not setting( 'url' ) then
		styles[#styles + 1] = 'background-image:' .. p.getUrl(
			setting( 'image' ) or setting( 'name' ) .. 'Sprite.png'
		)
	end
	local class = setting( 'class' )
	if class then
		sprite:addClass( class )
	end
	
	local size = setting( 'size' )
	local sheetWidth = setting( 'sheetsize' )
	local tiles = sheetWidth / size
	local pos = setting( 'pos' ) - 1
	local scale = setting( 'scale' )
	local autoScale = setting( 'autoscale' )
	
	if pos then
		local left = pos % tiles * size * scale
		local top = math.floor( pos / tiles ) * size * scale
		styles[#styles + 1] = 'background-position:-' .. left .. 'px -' .. top .. 'px'
	end
	
	if not autoScale and scale ~= defaultStyle.scale then
		styles[#styles + 1] = 'background-size:' .. sheetWidth * scale .. 'px auto'
	end
	if size ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then
		styles[#styles + 1] = 'height:' .. size * scale .. 'px'
		styles[#styles + 1] = 'width:' .. size * scale .. 'px'
	end
	
	local align = setting( 'align' )
	if align ~= defaultStyle.align then
		styles[#styles + 1] = 'vertical-align:' .. align
	end
	styles[#styles + 1] = setting( 'css' )
	
	sprite:cssText( table.concat( styles, ';' ) )
	
	local text = setting( 'text' )
	local root
	local spriteText
	if text then
		root = mw.html.create( 'span' ):addClass( 'nowrap' )
		spriteText = mw.html.create( 'span' ):addClass( 'sprite-text' ):wikitext( text )
	end
	
	local title = setting( 'title' )
	if title then
		( root or sprite ):attr( 'title', title )
	end
	
	if not root then
		root = mw.html.create( '' )
	end
	root:node( sprite )
	if spriteText then
		root:node( spriteText )
	end
	
	local link = setting( 'link' ) or ''
	if link ~= '' and mw.ustring.lower( link ) ~= 'none' then
		-- External link
		if link:find( '//' ) then
			return '[' .. link .. ' ' .. tostring( root ) .. ']'
		end
		
		-- Internal link
		local linkPrefix = setting( 'linkprefix' ) or ''
		return '[[' .. linkPrefix .. link .. '|' .. tostring( root ) .. ']]'
	end
	
	return tostring( root )
end

function p.sprite( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	
	local data = args.data and mw.loadData( 'Module:' .. args.data ) or {}
	local categories = {}
	local idData = args.iddata
	if not idData then
		local name = args.name or data.settings.name
		local id = mw.text.trim( tostring( args[1] or '' ) )
		idData = data.ids[id] or data.ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )]
	end
	
	local title = mw.title.getCurrentTitle()
	-- Remove categories on language pages, talk pages, and in User/UserWiki/UserProfile namespaces
	local disallowCats = args.nocat or title.isTalkPage or title.nsText:find( '^Utilisateur' )
	if idData then
		if idData.deprecated and not disallowCats then
			categories[#categories + 1] = '[[Catégorie:Pages utilisant des noms de sprites obsolètes]]'
			if args[1] then
				categories[#categories + 1] = '[[Catégorie:Pages utilisant le sprite obsolète ' .. mw.ustring.lower(mw.ustring.gsub(args[1], ' ', '-')) .. ']]'
			end
		end
		
		args.pos = idData.pos
	elseif not disallowCats then
		categories[#categories + 1] = '[[Catégorie:Pages avec des sprites manquants]]'
	end
	
	return p.base( args ), table.concat( categories )
end

function p.link( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end
	
	local link = args[1]
	if args[1] and not args.id then
		link = args[1]:match( '^(.-)%+' ) or args[1]
	end
	local text
	if not args.notext then
		text = args.text or args[2] or link
	end
	
	args[1] = args.id or args[1]
	args.link = args.link or link
	args.text = text
	
	return p.sprite( args )
end

function p.getUrl( spritesheet, query )
	return mw.getCurrentFrame():expandTemplate{ title = 'FileUrl', args = { spritesheet, query = query } }
end

function p.doc( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f.args
	else
		f = mw.getCurrentFrame()
	end
	local dataPage = mw.text.trim( args[1] )
	local data = mw.loadData( 'Module:' .. dataPage )
	
	local getProtection = function( title, action, extra )
		local protections = { 'edit' }
		if extra then
			protections[#protections + 1] = extra
		end
		
		local addProtection = function( protection )
			if protection == 'autoconfirmed' then
				protection = 'editsemiprotected'
			elseif protection == 'sysop' then
				protection = 'editprotected'
			end
			
			protections[#protections + 1] = protection
		end
		
		local direct = title.protectionLevels[action] or {}
		for _, protection in ipairs( direct ) do
			addProtection( protection )
		end
		local cascading = title.cascadingProtection.restrictions[action] or {}
		if #cascading > 0 then
			protections[#protections + 1] = 'protect'
		end
		for _, protection in ipairs( cascading ) do
			addProtection( protection )
		end
		
		return table.concat( protections, ',' )
	end
	
	local dataTitle = mw.title.new( 'Module:' .. dataPage )
	local spritesheet = data.settings.image or data.settings.name .. 'Sprite.png'
	local spriteTitle = mw.title.new( 'File:' .. spritesheet )
	local dataProtection = getProtection( dataTitle, 'edit' )
	local spriteProtection = getProtection( spriteTitle, 'upload', 'upload,reupload' )
	local body = mw.html.create( 'div' ):attr( {
		id = 'spritedoc',
		['data-dataprotection'] = dataProtection,
		['data-datatimestamp'] = f:callParserFunction( 'REVISIONTIMESTAMP', 'Module:' .. dataPage ),
		['data-datapage'] = 'Module:' .. dataPage,
		['data-spritesheet'] = spritesheet,
		['data-spriteprotection'] = spriteProtection,
		['data-urlfunc'] = "require( [[Module:Sprite]] ).getUrl( '" .. spritesheet .. "', '$1' )",
		['data-refreshtext'] = mw.text.nowiki( '{{#invoke:sprite|doc|' .. dataPage .. '|refresh=1}}' ),
		['data-settings'] = mw.text.jsonEncode( data.settings ),
	} )
	
	local sections = {}
	for _, sectionData in ipairs( data.sections or { name = 'Sans catégorie' } ) do
		local sectionTag = body:tag( 'div' ):addClass( 'spritedoc-section' ):attr( 'data-section-id', sectionData.id )
		sectionTag:tag( 'h3' ):wikitext( sectionData.name )
		sections[sectionData.id] = { boxes = sectionTag:tag( 'ul' ):addClass( 'spritedoc-boxes' ) }
	end
	
	local keyedData = {}
	local i = 1
	for name, idData in pairs( data.ids ) do
		keyedData[i] = {
			sortKey = mw.ustring.lower( name ),
			name = name,
			data = idData
		}
		i = i + 1
	end
	table.sort( keyedData, function( a, b )
		return a.sortKey < b.sortKey
	end )
	
	for _, data in ipairs( keyedData ) do
		local idData = data.data
		local pos = idData.pos
		local section = sections[idData.section]
		local names = section[pos]
		if not names then
			local box = section.boxes:tag( 'li' ):addClass( 'spritedoc-box' ):attr( 'data-pos', pos )
			box:tag( 'div' ):addClass( 'spritedoc-image' )
				:wikitext( p.base{ pos = pos, data = dataPage } )
			
			names = box:tag( 'ul' ):addClass( 'spritedoc-names' )
			section[pos] = names
		end
		local nameElem = mw.html.create( 'li' ):addClass( 'spritedoc-name' )
		local codeElem = nameElem:tag( 'code' ):wikitext( data.name )
		
		if idData.deprecated then
			codeElem:addClass( 'spritedoc-deprecated' )
		end
		names:wikitext( tostring( nameElem ) )
	end
	
	if args.refresh then
		return '', tostring( body )
	end
	return f:callParserFunction( '#widget:SpriteDoc.css' ), tostring( body )
end
return p