Jump to content

Module:Title monthname/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrownHairedGirl (talk | contribs) at 12:38, 16 July 2020 (Created page with '--v01 -- globals for this module local p = {} local monthList = { 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'Se...'). 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)
--[[ v01
]]


-- globals for this module
local p = {}

local monthList = {
	'January',
	'February',
	'March',
	'April',
	'May',
	'June',
	'July',
	'August',
	'September',
	'October',
	'November',
	'December'
}


-- parse the pagename to see if the supplied monthname can be matched as a complete word
-- i.e. that any preceding or trailing character is eithar a space character or a punctuation character
function findMonthNameInPagename(pn, month)
	-- first check whether the string is found at all
	if (mw.ustring.find(pn, month) == nil) then
		return nil
	end
	
	-- So the pagename does contain the monthname
	-- Now we need to check that it's a complete word
	-- The test above will match the month "May" in the string "County Mayo"
	-- ... and we need to eliminate such matches
	
	-- check for complete match
	if pn == month  then
		return month
	end
	-- check for match at start of string
	if (mw.ustring.match(pn, "^" .. month .. "[%s%p]") ~= nil) then
		return month
	end
	-- check for match at end of string
	if (mw.ustring.match(pn, "[%s%p]" .. month .. "$") ~= nil) then
		return month
	end
	-- check for match in middle of string
	if (mw.ustring.match(pn, "[%s%p]" .. month .. "[%s%p]") ~= nil) then
		return month
	end
	
	-- we haven't got a match, so this is a fail
	return nil
end

function checkPagename(pn)
	-- check each month in turn
	for i, aMonth in ipairs(monthList) do
		if (findMonthNameInPagename(pn, aMonth)  ~= nil) then
			return aMonth
		end
	end

	-- no match
	return nil

end

function p.main(frame)
	-- get the page title
	thispage = mw.title.getCurrentTitle()
	thispagename = thispage.text;
	

return checkPagename(thispagename)

end

return p