Module:Wikimedia engineering project date categories

From Bonkipedia
Revision as of 03:39, 15 February 2021 by [[mw:]]>Mtarch11 (Undid edits by 154.239.254.56 (talk) to last version by Krinkle)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Module to output Category:WMF Projects subcategories as appropriate for a start and end date, to be used in {{Wikimedia engineering project information}}


-- Module to output [[:Category:WMF Projects]] subcategories
-- as appropriate for a start and end date, to be used in
-- {{Wikimedia engineering project information}}

local p = {}
local lang = mw.language.getContentLanguage()

local function makeCategory( catdate, trail )
    local quarter, year
    quarter = math.ceil( tonumber( lang:formatDate( "m", catdate ) ) / 3 )
    year = lang:formatDate( "Y", catdate )
    return "[[Category:WMF Projects " .. year .. "q" .. tostring( quarter ) .. trail .. "]]"
end

function p.datesToCategories( frame )
    local startdate, curdate, enddate
    local categories = ""
    local trail = ""

    if (not frame.args.startdate) or frame.args.startdate == "" then
        return "[[Category:WMF Projects missing start date]]"
    else
        curdate = frame.args.startdate
        if string.len(curdate) < 4 then
        	return "[[Category:WMF Projects missing start date]]"
    	end
        if string.len(curdate) == 4 then
        	curdate = curdate .. "-01"
    	end
    end

    local title = mw.title.getCurrentTitle()
	if title and title.subpageText and mw.language.isSupportedLanguage(title.subpageText) and not (title.subpageText == mw.language.getContentLanguage():getCode()) then
    	--  Don't populate WMF quarter category with translations of every page
    	return ''
	end

    if (not frame.args.enddate) or frame.args.enddate == "" then
        -- Ends now
        enddate = lang:formatDate( "Y-m-d" )
        -- Current project
        categories = categories .. "[[Category:WMF Projects" .. trail .. "]]"
    else
        enddate = frame.args.enddate
        if string.len(enddate) == 4 then
        	enddate = enddate .. "-12"
    	end
    end

    while lang:formatDate( "U", curdate ) < lang:formatDate( "U", enddate ) do
        -- Hopefully not so many string as to break the garbage collector.
        categories = categories .. makeCategory( curdate, trail )
        curdate = lang:formatDate( "Y-m-d", curdate .. "+3 months" )
    end
    categories = categories .. makeCategory( enddate, trail )
    return categories
end

return p