Jump to content

Module:Ref info and Module:Ref info/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
Account for no-parameter templates when grabbing template names
 
Faster logic for rp/refbegin/dead links/webarchive (not as impactful but still useful) (also the sanity check isn't needed since it already exists at an earlier stage)
 
Line 209: Line 209:


_, tally = mw.ustring.gsub (template, '|%s*date%s*=%s*%d%d%d%d%-%d%d%-%d%d', '%1'); -- yyyy-mm-dd
_, tally = mw.ustring.gsub (template, '|%s*date%s*=%s*%d%d%d%d%-%d%d%-%d%d', '%1'); -- yyyy-mm-dd
count = count + tally; -- accumulate a total

return count;
end


--[[--------------------------< C O U N T _ C S 1 _ D A T E S _ D M Y _ A C C E S S >--------------------------

Using the lists of cs1|2 templates, make a count of just those templates that have |access-date=DD Month YYYY where
DD is one or two digits or a range DD-DD Month YYYY

]]

local function count_cs1_dates_dmy_access (template, count)
local _, tally;

_, tally = mw.ustring.gsub (template, '|%s*access%-?date%s*=%s*%d?%d%s+%a+%s+%d%d%d%d', '%1'); -- dd Month yyyy
count = count + tally; -- accumulate a total

return count;
end


--[[--------------------------< C O U N T _ C S 1 _ D A T E S _ M D Y _ A C C E S S >--------------------------

Using the lists of cs1|2 templates, make a count of just those templates that have |accesss-date=Month DD, YYYY where
DD is one or two digits or a range Month DD-DD, YYYY

]]

local function count_cs1_dates_mdy_access (template, count)
local _, tally;

_, tally = mw.ustring.gsub (template, '|%s*access%-?date%s*=%s*%a+%s+%d?%d%s*,%s+%d%d%d%d', '%1'); -- Month dd, yyyy
count = count + tally; -- accumulate a total

return count;
end


--[[--------------------------< C O U N T _ C S 1 _ D A T E S _ Y M D _ A C C E S S >--------------------------

Using the lists of cs1|2 templates, make a count of just those templates that have |access-date=YYYY-MM-DD

]]

local function count_cs1_dates_ymd_access (template, count)
local _, tally;

_, tally = mw.ustring.gsub (template, '|%s*access%-?date%s*=%s*%d%d%d%d%-%d%d%-%d%d', '%1'); -- yyyy-mm-dd
count = count + tally; -- accumulate a total

return count;
end


--[[--------------------------< C O U N T _ C S 1 _ D A T E S _ D M Y _ A R C H I V E >------------------------

Using the lists of cs1|2 templates, make a count of just those templates that have |archive-date=DD Month YYYY where
DD is one or two digits or a range DD-DD Month YYYY

]]

local function count_cs1_dates_dmy_archive (template, count)
local _, tally;

_, tally = mw.ustring.gsub (template, '|%s*archive%-?date%s*=%s*%d?%d%s+%a+%s+%d%d%d%d', '%1'); -- dd Month yyyy
count = count + tally; -- accumulate a total

return count;
end


--[[--------------------------< C O U N T _ C S 1 _ D A T E S _ M D Y _ A R C H I V E >------------------------

Using the lists of cs1|2 templates, make a count of just those templates that have |archive-date=Month DD, YYYY where
DD is one or two digits or a range Month DD-DD, YYYY

]]

local function count_cs1_dates_mdy_archive (template, count)
local _, tally;

_, tally = mw.ustring.gsub (template, '|%s*archive%-?date%s*=%s*%a+%s+%d?%d%s*,%s+%d%d%d%d', '%1'); -- Month dd, yyyy
count = count + tally; -- accumulate a total

return count;
end


--[[--------------------------< C O U N T _ C S 1 _ D A T E S _ Y M D _ A R C H I V E >------------------------

Using the lists of cs1|2 templates, make a count of just those templates that have |archive-date=YYYY-MM-DD

]]

local function count_cs1_dates_ymd_archive (template, count)
local _, tally;

_, tally = mw.ustring.gsub (template, '|%s*archive%-?date%s*=%s*%d%d%d%d%-%d%d%-%d%d', '%1'); -- yyyy-mm-dd
count = count + tally; -- accumulate a total
count = count + tally; -- accumulate a total


Line 393: Line 293:
for _, template in ipairs (template_list) do -- go through all cs1|2 like templates
for _, template in ipairs (template_list) do -- go through all cs1|2 like templates
if template:match("^" .. pattern) then
if template:match("^" .. pattern) then
local name = template:match ('^{{%s*([^|}]-)%s*[|}]'); -- get template name
local name = template:match ('^{{%s*([^|}]-)%s*|'); -- get template name
if not template_name_list[name] then -- if not already saved
if not template_name_list[name] then -- if not already saved
template_name_list[name] = 1; -- save it
template_name_list[name] = 1; -- save it
Line 405: Line 305:
object['cs1_mdy_dates']['count'] = count_cs1_dates_mdy (template, object['cs1_mdy_dates']['count']); -- count of |date=mdy
object['cs1_mdy_dates']['count'] = count_cs1_dates_mdy (template, object['cs1_mdy_dates']['count']); -- count of |date=mdy
object['cs1_ymd_dates']['count'] = count_cs1_dates_ymd (template, object['cs1_ymd_dates']['count']); -- count of |date=ymd
object['cs1_ymd_dates']['count'] = count_cs1_dates_ymd (template, object['cs1_ymd_dates']['count']); -- count of |date=ymd

object['cs1_dmy_dates_access']['count'] = count_cs1_dates_dmy_access (template, object['cs1_dmy_dates_access']['count']); -- count of |access-date=dmy
object['cs1_mdy_dates_access']['count'] = count_cs1_dates_mdy_access (template, object['cs1_mdy_dates_access']['count']); -- count of |access-date=mdy
object['cs1_ymd_dates_access']['count'] = count_cs1_dates_ymd_access (template, object['cs1_ymd_dates_access']['count']); -- count of |access-date=ymd

object['cs1_dmy_dates_archive']['count'] = count_cs1_dates_dmy_archive (template, object['cs1_dmy_dates_archive']['count']); -- count of |archive-date=dmy
object['cs1_mdy_dates_archive']['count'] = count_cs1_dates_mdy_archive (template, object['cs1_mdy_dates_archive']['count']); -- count of |archive-date=mdy
object['cs1_ymd_dates_archive']['count'] = count_cs1_dates_ymd_archive (template, object['cs1_ymd_dates_archive']['count']); -- count of |archive-date=ymd


object['cs1_dates_df_dmy']['count'] = count_cs1_df_dmy (template, object['cs1_dates_df_dmy']['count']); -- count of |df=dmy
object['cs1_dates_df_dmy']['count'] = count_cs1_df_dmy (template, object['cs1_dates_df_dmy']['count']); -- count of |df=dmy
Line 494: Line 386:


if template then -- necessary?
if template then -- necessary?
local name = template:match ('{{%s*([^|}]-)%s*[|}]'); -- get template name
local name = template:match ('{{%s*([^|}]-)%s*|'); -- get template name
name = name:gsub (' +', ' '); -- replace multiple space chars with a single char
name = name:gsub (' +', ' '); -- replace multiple space chars with a single char
Line 530: Line 422:


if template then -- necessary?
if template then -- necessary?
local name = template:match ('{{%s*([^|}]-)%s*[|}]'); -- get template name
local name = template:match ('{{%s*([^|}]-)%s*|'); -- get template name
name = name:gsub (' +', ' '); -- replace multiple space chars with a single char
name = name:gsub (' +', ' '); -- replace multiple space chars with a single char
Line 610: Line 502:
for _, template in ipairs (templates) do
for _, template in ipairs (templates) do
if template:match ("^" .. pattern) then
if template:match ("^" .. pattern) then
local name = template:match ('^{{%s*([^|}]-)%s*[|}]'); -- get template name
local name = template:match ('^{{%s*([^|}]-)%s*|'); -- get template name
if not vcite_template_name_list[name] then -- if not already saved
if not vcite_template_name_list[name] then -- if not already saved
vcite_template_name_list[name] = 1; -- save it
vcite_template_name_list[name] = 1; -- save it
Line 659: Line 551:
for _, template in ipairs (templates) do
for _, template in ipairs (templates) do
if template:match ("^" .. pattern) then
if template:match ("^" .. pattern) then
local name = template:match ('{{%s*([^|}]-)%s*[|}]'); -- get template name
local name = template:match ('{{%s*([^|}]-)%s*|'); -- get template name
if not template_name_list[name] then -- if not already saved
if not template_name_list[name] then -- if not already saved
template_name_list[name] = 1; -- save it
template_name_list[name] = 1; -- save it
Line 1,015: Line 907:
['cs1_templates'] = { -- count cs1 templates only
['cs1_templates'] = { -- count cs1 templates only
['func'] = count_cs1,
['func'] = count_cs1,
['pattern'] = '({{%%s*%s%%f[%%A]%%s*|)', -- will be modified in the func by string.format(); %f to count templates only once: {{cite web|... and {{cite we|...
['pattern'] = '({{%%s*%s%%s*|)', -- will be modified in the func by string.format()
['count'] = 0,
['count'] = 0,
['label'] = 'cs1 templates'
['label'] = 'cs1 templates'
Line 1,151: Line 1,043:
['label'] = 'cs1|2 ymd dates'
['label'] = 'cs1|2 ymd dates'
},
},

['cs1_dmy_dates_archive'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['pattern'] = nil,
['count'] = 0,
['label'] = 'cs1|2 dmy archive dates'
},
['cs1_mdy_dates_archive'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['pattern'] = nil,
['count'] = 0,
['label'] = 'cs1|2 mdy archive dates'
},
['cs1_ymd_dates_archive'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['pattern'] = nil,
['count'] = 0,
['label'] = 'cs1|2 ymd archive dates'
},

['cs1_dmy_dates_access'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['pattern'] = nil,
['count'] = 0,
['label'] = 'cs1|2 dmy access dates'
},
['cs1_mdy_dates_access'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['pattern'] = nil,
['count'] = 0,
['label'] = 'cs1|2 mdy access dates'
},
['cs1_ymd_dates_access'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['pattern'] = nil,
['count'] = 0,
['label'] = 'cs1|2 ymd access dates'
},

['cs1_last'] = { -- count cs1 templates only
['cs1_last'] = { -- count cs1 templates only
['func'] = nil, -- handled by cs1_cs2_info_get()
['func'] = nil, -- handled by cs1_cs2_info_get()
Line 1,258: Line 1,111:
'cs1_mdy_dates',
'cs1_mdy_dates',
'cs1_ymd_dates',
'cs1_ymd_dates',
'cs1_dmy_dates_access',
'cs1_mdy_dates_access',
'cs1_ymd_dates_access',
'cs1_dmy_dates_archive',
'cs1_mdy_dates_archive',
'cs1_ymd_dates_archive',
'cs1_last',
'cs1_last',
'cs1_author',
'cs1_author',