มอดูล:Ref info

-- This module counts the number of times that various reference tags and cs1|2 templates appear.
-- ref_info
-- 
-- aristotle
require('Module:No globals');
local data = mw.loadData ('Module:Ref info/data');
--mw.logObject (data.cs12_stripped_list, 'data.cs12_stripped_list')
local collapsible_tables = {
	'cs1' = ,																-- collapsible wiki-tables of names and counts
	'cs2' = ,
	'cs1_like' = ,
	'vcite' = ,
	'sfn' = ,
	'harv' = ,
	}
----------------------------------------------------------
makes a collapsed html table that holds a list of cs1 or cs2 template used in an article.  The list occupies a
single row of the parent table.
local function template_name_table_make (name_list, group)
	local name_table = {};
	local function comp (a, b)													-- used in following table.sort()
		return a:lower() ----------------------------------------------------
this is a general purpose function used to count occurrences of  in 
local function count_pattern (text, pattern)
	local _;
	local count;
	_, count = mw.ustring.gsub (text, pattern, '%1');
	return count;
end
--last1= (or any of the selected aliases of these).
local function count_cs1_last (template, count)
	local _, tally;
	for _, param in ipairs (data.last_param_patterns) do
		_, tally = mw.ustring.gsub (template, '|%s*' .. param .. '%s*=%s*', '%1');		-- count occurences of that pattern
		count = count + tally;													-- accumulate a total
	end
	return count;
end
--author1= (or any of the selected aliases of these).
local function count_cs1_author (template, count)
	local _, tally;
	for _, param in ipairs (data.author_param_patterns) do
		_, tally = mw.ustring.gsub (template, '|%s*' .. param .. '%s*=%s*', '%1');		-- count occurences of that pattern
		count = count + tally;													-- accumulate a total
	end
	return count;
end
--authors= (or any of the selected aliases).
local function count_cs1_authors (template, count)
	local _, tally;
	for _, param in ipairs (data.authors_param_patterns) do
		_, tally = mw.ustring.gsub (template, '|%s*' .. param .. '%s*=%s*', '%1');		-- count occurences of that pattern
		count = count + tally;													-- accumulate a total
	end
	return count;
end
--vauthors=.
local function count_cs1_vauthors (template, count)
	local _, tally;
	_, tally = mw.ustring.gsub (template, '|%s*vauthors%s*=%s*', '%1');	-- count occurences of that pattern
	count = count + tally;														-- accumulate a total
	return count;
end
--date=DD Month YYYY where
DD is one or two digits or a range DD-DD Month YYYY
local function count_cs1_dates_dmy (template, count)
	local _, tally;
	_, tally = mw.ustring.gsub (template, '|%s*date%s*=%s*%d?%d%s+%a+%s+%d%d%d%d', '%1');			-- dd Month yyyy
	count = count + tally;														-- accumulate a total
	_, tally = mw.ustring.gsub (template, '|%s*date%s*=%s*%d?%d%-–%d?%d%s+%a+%s+%d%d%d%d', '%1');	-- dd-dd Month yyyy
	count = count + tally;														-- accumulate a total
	return count;
end
--date=Month DD, YYYY where
DD is one or two digits or a range Month DD-DD, YYYY
local function count_cs1_dates_mdy (template, count)
	local _, tally;
	_, tally = mw.ustring.gsub (template, '|%s*date%s*=%s*%a+%s+%d?%d%s*,%s+%d%d%d%d', '%1');				-- Month dd, yyyy
	count = count + tally;														-- accumulate a total
	_, tally = mw.ustring.gsub (template, '|%s*date%s*=%s*%a+%s+%d?%d%-–%d?%d%s*,%s+%d%d%d%d', '%1');		-- Month dd-dd, yyyy
	count = count + tally;														-- accumulate a total
	return count;
end
--date=YYYY-MM-DD
local function count_cs1_dates_ymd (template, count)
	local _, tally;
	_, 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
--df=xxx (with a value)
local function count_cs1_df_dmy (template, count)
	local _, tally;
	_, tally = mw.ustring.gsub (template, '|%s*df%s*=%s*dmy%-?a?l?l?', '%1');	-- |df=dmy |df=dmy-all
	count = count + tally;														-- accumulate a total
	return count;
end
--df=xxx (with a value)
local function count_cs1_df_mdy (template, count)
	local _, tally;
	_, tally = mw.ustring.gsub (template, '|%s*df%s*=%s*mdy%-?a?l?l?', '%1');	-- |df=mdy |df=mdy-all
	count = count + tally;														-- accumulate a total
	return count;
end
--df=xxx (with a value)
local function count_cs1_df_ymd (template, count)
	local _, tally;
	_, tally = mw.ustring.gsub (template, '|%s*df%s*=%s*ymd%-?a?l?l?', '%1');	-- |df=ymd |df=ymd-all
	count = count + tally;														-- accumulate a total
	return count;
end
--mode=cs2
local function count_cs12_mode (template, count, mode)
	local _, tally;
	mode = 1 == mode and 'cs1' or 'cs2';
	
	_, tally = mw.ustring.gsub (template, '|%s*mode%s*=%s*' .. mode, '%1');		-- |mode=cs1 or |mode=cs2
	count = count + tally;														-- accumulate a total
	return count;
end
--2 templates used.  Count
different author-name styles, date styles.
local function cs1_cs2_info_get (Article_content, pattern, template_name_list, object)
	local tstart, tend = Article_content:find (pattern);						-- find the first cs1 template
	local total = 0;
	
	while tstart do																-- nil when cs1|2 template not found
		local template = Article_content:match ('%b{}', tstart);				-- get the whole template
		if template then														-- necessary?
			local name = template:match ('