Jump to content

Module:Ref info

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 12:33, 27 March 2016 (create;). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module counts the number of times that various reference tags and cs1|2 templates appear.
-- {{#invoke:ref_count|ref_count}}

local p = {}

function p.ref_count(frame)
	local text = mw.title.getCurrentTitle():getContent();						-- the content of the current page
	local ref_count;															-- count of <ref>...</ref> tags
	local named_ref_count;														-- count of <ref name=...>...</ref> tags
	local self_closed_ref_count													-- count of <ref name=.../> tags
	local cs1_count;
	local cs2_count;
	local temp;
	
	local temp, ref_count = mw.ustring.gsub(text, '(<ref>.+</ref>', '%1');		-- count unnamed refs
	local temp, named_ref_count = mw.ustring.gsub(text, '(<ref%s*name%s*=.+>.+</ref>', '%1');		-- count named refs
	local temp, self_closed_ref_count = mw.ustring.gsub(text, '(<ref%s*name%s*=.+/>', '%1');		-- count named refs
	return string.format ('unnamed refs = %s\nnamed refs = %s\nself closed = %s', ref_count, named_ref_count, self_closed_ref_count);
end

return p