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 MediaWiki version=mwVersion' }	query.limit = 5000

local result = mw.smw.ask( query )

local extVersions = {} local mwVersions = {} if result and #result then for _, data in pairs( result ) do			if data.extVersion then extVersions[data.extVersion] = data.extVersion end if data.mwVersion then mwVersions[data.mwVersion] = data.mwVersion 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 .. '!' .. mwKeys[row] .. '\n' columnCount = 1 for column = #extKeys, 1, -1 do			query = { 'Has extension::Extension:'..extensionName..'', 'Has extension version::'..extKeys[column]..'', 'Has MediaWiki version::'..mwKeys[row]..'', }			query.format = 'count' query.default = 0 --			mw.logObject(query) result = mw.smw.ask( query ) --			mw.logObject(result) 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