stringtranslate.com

Module:Gadgets

local p = {}p.parse = function()local text = mw.title.new('MediaWiki:Gadgets-definition'):getContent()local lines = mw.text.split(text, '\n', false)local repo = {}for _, line in ipairs(lines) doif line:sub(1, 1) == '*' thenlocal name, options, pages = p.parse_line(line)if name and #pages ~= 0 thenrepo[name] = { options = options, pages = pages }endendendreturn repoendp.parse_line = function(def) local pattern = "^%*%s*(.+)%s*(%b[])%s*(.-)$"local name, opts, pageList = string.match(def, pattern)name = mw.text.trim(name)-- Process options string into a Lua table local options = {}if opts then -- Extracting the options without square brackets and trimming spaces opts = opts:sub(2, -2):gsub("%s+", "")  for pair in opts:gmatch("%s*([^|]+)%s*|?") do local key, value = pair:match("%s*([^=]+)%s*=%s*([^=|]+)%s*") if key and value then options[key:match("%s*(.-)%s*$")] = value:match("^%s*(.-)%s*$") else key = pair:match("%s*(.-)%s*$") options[key] = true endendend-- Process page list into an arraylocal pages = {}if pageList then for page in pageList:gmatch("[^|]+") do table.insert(pages, mw.text.trim(page)) end end return name, options, pagesendp.get_type = function(def) if def.options.type == 'general' or def.options.type == 'styles' thenreturn def.options.typeendif def.options.dependencies ~= nil thenreturn 'general'endfor _, page in ipairs(def.pages) doif not string.match(page, '%.css$') thenreturn 'general'endendreturn 'styles'endp.get_usage = function(name)-- escape name for use in patternname = name:gsub("[%-%.%+%[%]%(%)%$%^%%%?%*]", "%%%1"):gsub("_", " ")-- rely on [[Wikipedia:GUS2Wiki]] until [[phab:T354890]] is implementedlocal _, _, count = mw.title.new('Wikipedia:GUS2Wiki'):getContent():find('\n'..name..',(%S+)\n')return tonumber(count) or -1endreturn p