Module:Test wikis
Documentation for this module may be created at Module:Test wikis/doc
-- @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( "Expiration" )
: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( "[[User:%s|%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
-- @brief
-- Generates the list of administrators for given test wiki.
--
-- @return
-- Preprocessed wikitext Generated list of administrators for given test wiki
function _module.printTestWikiAdministratorsList( frame )
local output = ""
local html = mw.html.create()
local title = mw.title.getCurrentTitle().text
local administratedTestWikisJson = mw.title.new( "Administrated test wikis.json", "MediaWiki" ):getContent()
local administratedTestWikis = mw.text.jsonDecode( administratedTestWikisJson )
local testWikiAdministrators = {}
html = html
:wikitext( "{{int:wminc-infopage-content-administroters}}" )
if administratedTestWikis[title] and next( administratedTestWikis[title] ) then
html = html
:tag( "ul" )
for user, expires in pairs( administratedTestWikis[title] ) do
html = html
:tag( "li" )
:wikitext( string.format( "[[User:%s|%s]] (expires %s)", user, user, expires ) )
:done()
end
html = html
:done()
else
html = html
:tag( "br" )
:done()
:tag( "small" )
:css( "font-style", "italic" )
:wikitext( "Contact [[Special:ListUsers/sysop|Incubator administrators]]" )
:done()
end
html = html
:allDone()
return frame:preprocess( tostring( html ) )
end
----------------------------------------
return _module