Module:Test wikis

-- @brief -- Utilities related to test wikis. -- -- @author -- meta:User:Danny B. local _module = {}

function kpairs( tbl, ... ) local keys = {} for key in pairs( tbl ) do		table.insert( keys, key ) end table.sort( keys, arg[1] ) local i = 0 local iterator = function i = i + 1 if keys[i] == nil then return nil else return keys[i], tbl[keys[i]] end end return iterator end

-- @brief -- Generates the table of Test wiki administrators. -- -- @return -- Preprocessed wikitext Generated table of Test wiki administrators function _module.printTestWikiAdministratorsByExpiration( frame ) local output = "" local html = mw.html.create local administratedTestWikisJson = mw.title.new( "Administrated test wikis.json", "MediaWiki" ):getContent local administratedTestWikis = mw.text.jsonDecode( administratedTestWikisJson ) local testWikiAdministrators = {} for wiki, data in pairs( administratedTestWikis ) do		for user, expires in pairs( data ) do			if not testWikiAdministrators[expires] then testWikiAdministrators[expires] = {} end if not testWikiAdministrators[expires][user] then testWikiAdministrators[expires][user] = {} end table.insert( testWikiAdministrators[expires][user], wiki ) end end html = html :tag( "table" ) :addClass( "wikitable" ) :addClass( "sortable" ) :addClass( "testWikiAdministrators" ) :newline :tag( "tr" ) :tag( "th" ) :wikitext( "User" ) :done :tag( "th" ) :wikitext( "Expires when" ) :done :tag( "th" ) :wikitext( "Project(s)" ) :done :done :newline for expires, data in kpairs( testWikiAdministrators ) do		for user, wiki in kpairs( data ) do			html = html :tag( "tr" ) :addClass( os.date("%Y-%m-%d") > expires and "expired" or nil ) :tag( "td" ) :wikitext( string.format( "%s", user, user ) ) :done :tag( "td" ) :wikitext( expires ) :done :tag( "td" ) :wikitext( "" .. table.concat( wiki, ", " ) .. "" ) :done :done :newline end end html = html :allDone :newline return frame:preprocess( tostring( html ) ) end

return _module