Module:Archive URL counts
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module depends on the following other modules: |
- Module:Archive URL counts implements template {{Archive URL counts}}.
- It includes the sub-module Module:Archive URL counts/data which is executed only once per page [not per template invocation] to ensure fast loading times. This sub-module pulls data from Wikimedia Commons:
- c:Data:Wikipedia statistics/exturls.tab for statistics regarding external archive URLs across all Wikimedia wikis.
- exturls.tab is updated automatically by the Numberofurl bot.
- The module was originally developed on Enwiki.
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,
}