Module:CS1 suggested updates table

Documentation for this module may be created at Module:CS1 suggested updates table/doc

Code

require ('strict');

local increment_values_t = {													-- table of recommended increment values
	OCLC = 70000000,															-- these values taken from historical update values at en.wikipedia
	OSTI = 10000,
	PMC = 200000,
	PMID = 500000,
	RFC = 300,
	SSRN = 100000,
	S2CID = 2000000,
	}
	
local id_limits_data_t = {};													-- to hold identifier limits from the tabular data file in simple form
local identifier_order_t = {};													-- a sequence of known identifiers
for _, limit_t in ipairs (mw.ext.data.get ("CS1/Identifier limits.tab").data) do	-- build a simple table of those limits
	id_limits_data_t[limit_t[1]] = limit_t[2];									-- <limit[1]> is identifier label; <limit[2]> is upper limit for that identifier
	table.insert (identifier_order_t, limit_t[1]);								-- add the identifier label to the order list
end

table.sort (identifier_order_t);												-- ascending sort


--[[--------------------------< M A I N >----------------------------------------------------------------------

Citation Style 1 and Citation Style 2 validate certain identifier values by making sure that these values are
less than or equal to  a specified upper limit.  This is a very crude check which serves mostly to catch extraneous
digits.  Identifier values are not static so the limits listed in c:Data:CS1/Identifier limits.tab must occasionally
be updated.

This module creates a wikitable of suggested new values for these identifier limits.  Essentially, the table
holds values that are calculated from the current limits defined in c:Data:CS1/Identifier limits.tab plus the values
listed in the <increment_values_t> table.  The values in <increment_values_t> are taken from previous manual
updates at en.wikipedia en:Module:Citation/CS1/Configuration.

When updating c:Data:CS1/Identifier limits.tab editors should only update those values the *need* to be updated.  Please
do not defeat the purpose of these limts by setting unreasonably high values.

]]

local function main()
	local update_table = mw.html.create ("table")								-- create a wikitable of recommended update values
		:addClass ("wikitable")
		:attr ('style', 'float: right; margin-left:0.2em');						-- move it to the right

	update_table:node (mw.html.create ('caption'):wikitext ('Suggested update values'));	-- add a table caption
		
	update_table:node (mw.html.create ("tr")									-- create a header row
		:node (mw.html.create ("th"):attr ('style', 'width: 10em;'):wikitext ("Identifier"))
		:node (mw.html.create ("th"):attr ('style', 'width: 10em;'):wikitext ("Value"))
		);
		
	for _, identifier in ipairs (identifier_order_t) do							-- spin through the identifiers in order
		update_table:node (mw.html.create ("tr")								-- create a new table row
			:node (mw.html.create ("td"):wikitext (identifier))					-- add the identifier
			:node (mw.html.create ("td"):wikitext (id_limits_data_t[identifier] + increment_values_t[identifier]))	-- add the recommended value (current value + increment)
			);
	end

	return update_table:allDone();												-- and done
end


--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]

return {
	main = main
	}