-- each title consists of 3 parts -- * prefix -- * county name -- * suffix -- e.g. "Foo in County Mayo" -- * prefix = "Foo in " -- * county name = "County Mayo" -- * suffix = "" -- e.g. "County Sligo-related lists" -- * prefix = "" -- * county name = "County Sligo" -- * suffix = "-related lists"
local ROI_counties =
local Norniron_counties =
local New_counties =
function nil_or_value(s) if (s
function makeTable local i, myCounty local myTable = '
' .. 'Northern Ireland | \n' for i, myCounty in ipairs(Norniron_counties) do myCatName = make_cat_name(myCounty, title_prefix, title_suffix, title_nocountyword) myTable = myTable .. "* " .. make_cat_link(myCatName, myCounty) .. "\n" end myTable = myTable .. " |
local debugmsg = nillocal getArgs = require('Module:Arguments').getArgslocal p = function make_cat_link(catname, disp) local displaytext if (disp ~= "") then displaytext = disp else displaytext = catname end local link = "" .. displaytext .. "" local fmtlink local linktitle = mw.title.new(catname, "Category") if (linktitle.exists) then fmtlink = link else fmtlink = "
" .. displaytext .. "" endreturn fmtlinkend
function make_cat_name(countyname, prefix, suffix, nocounty) local this_cat_name = ; this_cat_name = this_cat_name .. prefix if not (nocounty) then this_cat_name = this_cat_name .. 'County '; end this_cat_name = this_cat_name .. countyname this_cat_name = this_cat_name .. suffix return this_cat_nameend
function find_new_county_name_in_pagename(pn) local i, testCounty for i, testCounty in ipairs(ROI_counties) do debuglog(4, "testing new_county: [" .. testCounty .. "]") if (mw.ustring.match(pn, testCounty)) then if mw.ustring.match(pn, "^" .. testCounty .. "[^%w]") then return testCounty elseif mw.ustring.match(pn, "[^%w]" .. testCounty .. "$") then return testCounty elseif mw.ustring.match(pn, "[^%w]" .. testCounty .. "[^%w]") then return testCounty elseif mw.ustring.match(pn, "[^%w]" .. testCounty .. "[^%w]") then return testCounty end end end return nilend
function parse_pagename(pn) debuglog(1, "parse_pagename: [" .. pn .. "]") debuglog(2, "simple parse") match_prefix, match_county, match_suffix = string.match(pn, "^(.*)(County%s+%a+)(.*)$") if (match_county
) then debuglog(3, "No match_'County Foo'") debuglog(2, "try new counties") local new_county = find_new_county_name_in_pagename(pn) if new_county
end title_prefix = match_prefix title_suffix = match_suffix debuglog(2, "parse successful") debuglog(3, "match_prefix = [" .. match_prefix .. "]") debuglog(3, "match_county = [" .. match_county .. "]") debuglog(3, "match_suffix = [" .. match_suffix .. "]") return trueend
function debuglog(level, msg)
if (debugmsg
if (string.match(debugmsg, "^%s+$")) then debugmsg = "
\n\n" end
debugmsg = debugmsg .. "\n" if (level
2) then debugmsg = debugmsg .. "#* " elseif (level
4) then debugmsg = debugmsg .. "#*#* " end debugmsg = debugmsg .. " " .. msg return trueend
function argValueFunc(value) if (value
function p.main(frame)-- getArgs-- In all cases, convert to blank (i.e. )-- * a nil value-- * a value consisting only of whitespace-- for the third parameter ("nospace"), trim whitespace and convert to lowercase
local myArgs = myArgs[1] = argValueFunc(frame.args[1]) myArgs[2] = argValueFunc(frame.args[2]) myArgs[3] = argValueFunc(frame.args[3]) myArgs[3] = mw.text.trim(myArgs[3]:lower)
debuglog(1, "myArgs") debuglog(2, "myArgs[1] = [" .. myArgs[1] .. "]") debuglog(2, "myArgs[2] = [" .. myArgs[2] .. "]") debuglog(2, "myArgs[3] = [" .. myArgs[3] .. "]")
-- now set the key variables title_prefix = myArgs[1] title_suffix = myArgs[2] title_nocountyword = false if (myArgs[3]
-- do we need to parse the page title? -- if neither title_prefix nor title_suffix was supplied as a parameter, then yes -- test by concatenating them, and see if the combination is blank if ((title_prefix .. title_suffix)
if (debugmsg
Output
end
return p