Module:Archive URL counts

local lang_obj = mw.language.getContentLanguage();								-- for use with <wantComma> and <last_update>

local aliases = {
    commons = 'commons.wikimedia',
    donate = 'donate.wikimedia',
    foundation = 'foundation.wikimedia',
    incubator = 'incubator.wikimedia',
    meta = 'meta.wikimedia',
    species = 'species.wikimedia',
    wikidata = 'www.wikidata',
    wikifunctions = 'www.wikifunctions',
    wikimania = 'wikimania.wikimedia',
    wikitech = 'wikitech.wikimedia',
    wikisource = 'www.wikisource',
}

local function trimArg(arg, i)
    arg = mw.text.trim(arg or '')
    if arg == '' then
        if i then
            error('Parameter ' .. i .. ' is missing. See template documentation')
        end
        return nil
    end
    return mw.ustring.lower(arg)
end

local function main(frame)
    local args = frame:getParent().args
    local action = trimArg(args[1], 1)
    
    -- Clean up action if someone uses legacy formatting
    if action:sub(1, 8) == 'numberof' then 
        action = trimArg(action:sub(9), 1)
    end
    
    local site = trimArg(args[2], 2)
    site = aliases[site] or site
    
    -- If no project is specified (e.g. "fr"), default to ".wikipedia"
    -- This also handles the "total" aliases gracefully
    if not site:find('.', 1, true) then
        site = site .. '.wikipedia'
    end
    
    local wantComma = trimArg(args[3]) -- "N" or anything non-blank inserts commas
    local result

    -- Load the cached data table
    local dataObj = mw.loadData('Module:Archive URL counts/data')
    local map = dataObj.map
    local data = dataObj.data

	if 'last_update' == action then												-- if all we want is the date of the last update
		return lang_obj:formatDate ('j F Y', dataObj.last_update);				-- make the date all pretty-like (dmy), return it, and done
	end

    local siteData = data[site]
    
    if siteData and map[action] then
        result = siteData[map[action]]
    end

    if result then
        if wantComma then
            result = lang_obj:formatNum(result)
        end
        return result
    end
    
    -- Return -1 if the site or statistic doesn't exist in the JSON
    return -1
end

return {
    main = main,
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.