Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Документация
- function p.doc( f )
- local args = f
- if f == mw.getCurrentFrame() then
- args = f.args
- else
- f = mw.getCurrentFrame()
- end
- local settingsPage = mw.text.trim( args[1] )
- local settings = mw.loadData( 'Модуль:' .. settingsPage )
- local idsPage = 'Модуль:' .. ( settings["IDы"] or settings["имя"] .. 'Спрайт/ID' )
- local spriteargs = {}
- for k, v in pairs(args) do
- if type(k) ~= 'number' then
- spriteargs[k] = v
- end
- end
- 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
- if args.refresh then
- body = mw.html.create( '' )
- else
- local idsTitle = mw.title.new( idsPage )
- local spritesheet = settings["изобр"] or settings["имя"] .. 'CSS.png'
- local spriteTitle = mw.title.new( 'Файл:' .. spritesheet )
- local idsProtection = getProtection( idsTitle, 'edit' )
- local spriteProtection = getProtection( spriteTitle, 'upload', 'upload,reupload' )
- body = mw.html.create( 'div' ):attr( {
- id = 'spritedoc',
- ['data-idspage'] = idsTitle.id,
- ['data-idsprotection'] = idsProtection,
- ['data-idstimestamp'] = f:callParserFunction( 'REVISIONTIMESTAMP', idsPage ),
- ['data-spritesheet'] = spritesheet,
- ['data-spriteprotection'] = spriteProtection,
- ['data-pos'] = settings["поз"] or 1,
- ['data-refreshtext'] = mw.text.nowiki( '{{#invoke:Спрайт|doc|' .. settingsPage .. '|обновить=1}}' )
- } )
- end
- local data = mw.loadData( idsPage )
- local sections = {}
- for _, sectionData in ipairs( data["разделы"] or {"Некатегоризованные"} ) do
- local sectionTag = body:tag( 'div' ):addClass( 'spritedoc-section' ):attr( 'data-section-id', sectionData["ID"] )
- -- https://phabricator.wikimedia.org/T73594
- sectionTag:wikitext( '<h3>', sectionData[1], '</h3>' )
- sections[sectionData["ID"]] = { boxes = sectionTag:tag( 'ul' ):addClass( 'spritedoc-boxes' ) }
- end
- local keyedData = {}
- for name, idData in pairs( data["IDы"] ) do
- table.insert( keyedData, {
- ["ключ"] = mw.ustring.lower( name ),
- ["имя"] = name,
- ["данные"] = idData
- } )
- end
- table.sort( keyedData, function( a, b )
- return a["ключ"] < b["ключ"]
- end )
- for _, data in ipairs( keyedData ) do
- local idData = data["данные"]
- local pos = idData["поз"]
- local section = sections[idData["раздел"]]
- local names = section[pos]
- if not names then
- local box = section.boxes:tag( 'li' ):addClass( 'spritedoc-box' ):attr( 'data-pos', pos )
- local lspriteargs = mw.clone(spriteargs)
- lspriteargs["поз"] = pos
- lspriteargs["настройки"] = settingsPage
- box:tag( 'div' ):addClass( 'spritedoc-image' )
- :wikitext( p.base(lspriteargs) )
- 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["имя"] )
- if idData["устарел"] then
- codeElem:addClass( 'spritedoc-deprecated' )
- end
- names:wikitext( tostring( nameElem ) )
- end
- if args["обновить"] then
- return '', tostring( body )
- end
- return f:callParserFunction( '#widget:Stylesheet', { page = 'SpriteDoc' } ), tostring( body )
- end
- return p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement