--v16
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"
-- configlocal textSize = '90%'local tableClass="infobox"local tableStyle="margin-left:auto; margin-right:auto; clear:left; float:left; width:auto;"local evenRowStyle = "background-color:#f3f3f3;"local oddRowStyle = ""local labelStyle = "text-align:right; font-weight: bold;"local listStyle = "text-align:left; font-weight: normal;"local greyLinkColor = "#888"
-- globals for this modulelocal debugging = falselocal debugmsg = ""local tableRowNum = 0local includeNewCounties = truelocal useCountyWord = truelocal title_prefix = ""local title_suffix = ""local displayAbbrevCounty = false
local getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local p =
local TwentySixCounties =
local SixCounties =
local newCounties =
local Traditional32Counties =
local GAACounties =
local abbreviatedCountyName =
function makeTableRow(rowLabel, useCountyWord, countyList) debugLog(2, "makeTableRow: [" .. rowLabel .. "]") tableRowNum = tableRowNum + 1 local thisRow if (tableRowNum % 2)
nil) or (mw.ustring.match(rowLabel, "^%s*$"))) then thisRow = thisRow .. '
\n' local i, aCounty debugLog(3, "Process countyList") for i, aCounty in ipairs(countyList) do debugLog(4, "No. [" .. tostring(i) .. ": [" .. aCounty .. "]") myCatName = makeCatName(countyWord .. aCounty, title_prefix, title_suffix) thisRow = thisRow .. "* " .. makeCatLink(myCatName, aCounty) .. "\n" local j, nuCounty if (includeNewCounties and (aCounty
function makeTable debugLog(1, "makeTable") tableRowNum = 0 local myTable = '
function makeAbbreviatedCountyName(s) debugLog(5, "displayAbbrevCounty? ")
if not displayAbbrevCounty then debugLog(nil, " No") return s end debugLog(nil, " Yes") if (abbreviatedCountyName[s] ~= nil) then debugLog(5, "AbbreviatedCountyName for: [" .. s .. "] = [" .. abbreviatedCountyName[s] .. "]") return abbreviatedCountyName[s] end debugLog(5, "No abbreviatedCountyName for: [" .. s .. "]") return send
-- Make a piped link to a category, if it exists-- If it doesn't exist, just display the greyed the link title without linkingfunction makeCatLink(catname, disp) local displaytext if (disp ~= "") and (disp ~= nil) then -- use 'disp' parameter, but strip any trailing disambiguator displaytext = mw.ustring.gsub(disp, "%s+%(.+$", ""); displaytext = makeAbbreviatedCountyName(displaytext) else displaytext = catname end local fmtlink local catPage = mw.title.new(catname, "Category") if (catPage.exists) then fmtlink = "" .. displaytext .. "" else fmtlink = '
' .. displaytext .. "" endreturn fmtlinkend
function makeCatName(countyName, prefix, suffix) local this_cat_name = ; this_cat_name = this_cat_name .. prefix this_cat_name = this_cat_name .. countyName this_cat_name = this_cat_name .. suffix return this_cat_nameend
-- Does the pagename include a bare county name? (i.e. without the prefix "County ")-- This would be one line in regex, but Lua pattern matching is cruder, so-- we need several passes to ensure that any match is of a complete wordfunction findBareCountyNameInPagename(pn, countylist, description) local i, testCounty debugLog(2, "trying bare_county name [" .. pn .."] in county set: " .. description) for i, testCounty in ipairs(countylist) do debugLog(3, "testing new_county: [" .. testCounty .. "]") local testCountyEncoded = mw.ustring.gsub(testCounty, "([%W])", "%%%1") -- For efficiency, the first test is a simple match as a a screening test -- If the bare county name is nowhere in the pagename, then no need for -- more precise checks if (mw.ustring.match(pn, testCountyEncoded)) then debugLog(4, "simple match success") debugLog(4, "match at start, followed by separator? ") if mw.ustring.match(pn, "^" .. testCountyEncoded .. "[^%w]") then debugLog(nil, "Yes") return testCounty else debugLog(nil, "No") end debugLog(4, "match at end, preceded by separator? ") if mw.ustring.match(pn, "[^%w]" .. testCountyEncoded .. "$") then debugLog(nil, "Yes") return testCounty else debugLog(nil, "No") end debugLog(4, "match anywhere, preceded and followed by separator? ") if mw.ustring.match(pn, "[^%w]" .. testCountyEncoded .. "[^%w]") then debugLog(nil, "Yes") return testCounty else debugLog(nil, "No") end else debugLog(4, "simple match fail") end end return nilend
-- check whether a given county name is in a particular setfunction isCountyInSet(s, countySet) local thisCounty = mw.ustring.gsub(s, "^County +", "") local aValidCounty for i, aValidCounty in ipairs(countySet) do if mw.ustring.match(thisCounty, "^" .. aValidCounty .. "$") then return true end end return falseend
function parsePagename(pn) debugLog(1, "parsePagename: [" .. pn .. "]") debugLog(2, "simple parse") match_prefix, match_county, match_suffix = mw.ustring.match(pn, "^(.*)(County%s+%a+)(.*)$") if not (match_county
) then debugLog(3, "County Foo = [" .. match_county .. "]") -- we have a "County Foo" ... but is it one of the 32 counties? debugLog(3, "is [" .. match_county .. "] one of the 32 counties?") if isCountyInSet(match_county, Traditional32Counties) then debugLog(nil, "Yes") else debugLog(nil, "No") return false end else -- simple parse failed debugLog(3, "No match_'County Foo'") local new_county = findBareCountyNameInPagename(pn, newCounties, "New_counties") if new_county
function publishDebugLog if not debugging then return "" end return "
\n\n" .. debugmsg .. "\n
\n"end
-- debugLog builds a log which can be output if debuging is enabled-- each log entry is given a level, so that the output is not simply a flat list-- a debug msg may be appended to the previous msg by setting the level to nilfunction debugLog(level, msg)
if (debugmsg
if (level ~= nil) then -- not appending, so make a new line debugmsg = debugmsg .. "\n" -- then add the level if (level
2) then debugmsg = debugmsg .. "#* " elseif (level
4) then debugmsg = debugmsg .. "#*#* " elseif (level
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
debugLog(1, "Check parameters") debugLog(2, "debug") if (frame.args['debug']
debugLog(2, "usecountyword") if (frame.args['usecountyword']
debugLog(2, "abbrev") if (frame.args['abbrev']
debugLog(2, "newcounties") if (frame.args['newcounties']
-- still need to add a "countyset" parameter, to choose [all 32]/[only 26]/[only 6]/[GAACounties]/[26+6] -- this is just a crude start debugLog(2, "countySet") if (frame.args['countyset']
-- get the page title thispage = mw.title.getCurrentTitle thispagename = thispage.text; debugLog(1, "mw.title.getCurrentTitle") debugLog(2, "thispage.text = [" .. thispage.text .."]") debugLog(2, "thispage.namespace = [" .. thispage.namespace .."]") debugLog(2, "thispage.nsText = [" .. thispage.nsText .."]") debugLog(2, "is it a cat? using (thispage:inNamespace(14)): ") if not (thispage:inNamespace(14)) then debugLog(nil, "No, this is not a category") debugLog(1, "Not a category, so no output") return publishDebugLog end debugLog(nil, "Yes, this is a category")
if not parsePagename(thispagename) then -- some error parsing the title, so don't proceed to output return publishDebugLog end debugLog(1, "all parse done") debugLog(2, "title_prefix = [" .. title_prefix .. "]") debugLog(2, "title_suffix = [" .. title_suffix .. "]")
return publishDebugLog .. makeTable
end
return p