--[[ v02
]]
-- globals for this module
local p = {}
local MyLog = ""
local monthList = {
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
}
function splitToWords(str)
result = {}
index = 1
MyLog = MyLog .. "<br />\n" .. "str = " .. str
s = mw.ustring.gsub(str, "^[%s%p]+", "") -- strip leading whitespace or punctuation
MyLog = MyLog .. "<br />\n" .. "s = " .. s
sx = mw.ustring.gsub(s, "^([^%s%p]+[%s%p]*).+$", "%1") -- test
MyLog = MyLog .. "<br />\n" .. "sx = [" .. sx .. "]"
for s2 in mw.ustring.gmatch(s, "[^%s%p]+[%s%p]*") do
MyLog = MyLog .. "<br />\n" .. "item " .. index .. " = [" .. s2 .."]"
result[index] = s2
index = index + 1
end
return result
end
-- 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
-- if there is a match, then
foundMonthNames = {}
for i, aMonth in ipairs(monthList) do
if (findMonthNameInPagename(pn, aMonth) ~= nil) then
foundMonthNames[aMonth] = mw.ustring.find(pn, aMonth)
end
end
-- did we get any matches?
if (table.getn(foundMonthNames) == 0) then
-- no match
return nil
end
-- so we have matches
table.sort(foundMonthNames)
return foundMonthNames[1]
end
function p.main(frame)
-- get the page title
thispage = mw.title.getCurrentTitle()
thispagename = thispage.text;
retvalx = ""
for n, w in ipairs (splitToWords(thispagename)) do
retvalx = retvalx .. "* " .. n .. " = " .. w .. "\n"
end
return MyLog .. "\n----\n\n" .. retvalx
-- return checkPagename(thispagename)
end
return p