Module:Utils

local p = {}

function p.getHostFromURL( frame ) s = frame.args[1] return (s.."/"):match("://(.-)[:/]") end

function p.stripAPIURL( frame ) s = frame.args[1] return s:match("https?://(.+)") end

function p.getBranchNumber( frame ) s = frame.args[1] return s:match("%.(%d+)") end

function p.getExtensionVersions( frame ) extensionName = frame.args[1] local query = { 'Has extension::Extension:'..extensionName..'', 'Has extension version::!~*MLEB*', '?Has extension version=extVersion', '?Has branch number=mwVersion' }	query.limit = 5000

local result = mw.smw.ask( query )

local extVersions = {} local mwVersions = {} local counts = {} if result and #result then for _, data in pairs( result ) do			if data.extVersion and type(data.extVersion) == 'string' then extVersions[data.extVersion] = data.extVersion end if data.mwVersion and type(data.mwVersion) == 'number' then mwVersions[data.mwVersion] = data.mwVersion end if data.extVersion and type(data.extVersion) == 'string' and data.mwVersion and type(data.mwVersion) == 'number' then if counts[data.extVersion] == nil then counts[data.extVersion] = {} end if counts[data.extVersion][data.mwVersion] == nil then counts[data.extVersion][data.mwVersion] = 0; end counts[data.extVersion][data.mwVersion] = counts[data.extVersion][data.mwVersion] + 1 end end end

local extKeys = {} for k in pairs(extVersions) do		table.insert(extKeys, k)	end table.sort(extKeys)

local mwKeys = {} for k in pairs(mwVersions) do		table.insert(mwKeys, k)	end table.sort(mwKeys)

local output = '\n{| width=80% class="wikitable sortable"\n' .. '|+ Version Breakdown for ' .. extensionName .. '\n' .. '! Versions\n'

local columnCount = 1 for column = #extKeys, 1, -1 do output = output .. '!' .. extKeys[column] .. '\n' columnCount = columnCount + 1 if columnCount > 10 then break end end

local rowCount = 1 for row = #mwKeys, 1, -1 do output = output .. '|-\n' output = output .. '! 1.' .. mwKeys[row] .. '\n' columnCount = 1 for column = #extKeys, 1, -1 do			if counts[extKeys[column]] and counts[extKeys[column]][mwKeys[row]] then result = counts[extKeys[column]][mwKeys[row]] else result = '' end output = output .. '|' .. result .. '\n' columnCount = columnCount + 1 if columnCount > 10 then break end end rowCount = rowCount + 1 if rowCount > 20 then break end end output = output .. '|}\n'

return output end

return p