--v00.1
each title consists of 3 parts * prefix * province name * suffix e.g. "Foo in Ulster" * prefix = "Foo in " * province name = "Ulster" * suffix = "" e.g. "Connacht-related lists" * prefix = "" * province name = "Connacht" * suffix = "-related lists"
-- configlocal textSize = '90%'local tableClass="toc"local tableFallbackMaxWidth="auto"local tableMaxWidth="calc(100% - 25em)" -- Template:GeoGroup has width: 23em<-- local tableStyle="margin-left:0; margin-right:auto; clear:left !important; margin-top:0 !important; float:left; width:auto;"local tableStyle="margin-left:0; margin-right:auto; clear:left !important; margin-top:0 !important; width:auto;"local tableRowStyle = "vertical-align:top; background-color:#f3f3f3;"-- local labelStyle = "text-align:right; font-weight: bold; padding: 0.25em 0.5em 0.25em 0.5em;"local labelStyle = "text-align:right; font-weight: normal; font-style: italic; padding: 0.25em 0.5em 0.25em 0.5em;"local listStyle = "text-align:left; font-weight: normal; padding: 0.25em 0.5em 0.25em 0.5em;"local greyLinkColor = "#888"
local callingTemplates =
-- globals for this modulelocal debugging = falselocal debugmsg = ""local title_prefix = ""local title_suffix = ""local title_prefixlocal title_suffixlocal thisPageProvincelocal greyLinkCount = 0local blueLinkCount = 0local parentname = ""local templateName
local horizontal = require('Module:List').horizontallocal getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local p =
local IrelandProvinces =
local 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 nillocal function debugLog(level, msg)
if (debugmsg
if (level ~= nil) then -- not appending, so make a new line debugmsg = debugmsg .. "\n" -- then add the level local i for i = 1, level do if (i % 2)
local function trackingCategory -- discount this page, which will always be coded as a blue link, but rendered as bold un-navigable blueLinkCount = blueLinkCount - 1 if greyLinkCount
0 then return "" end if greyLinkCount
2 then return "" end return ""end
-- Make a piped link to a category, if it exists-- If it doesn't exist, just display the greyed the link title without linkinglocal function 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+%(.+$", ""); else displaytext = catname end local fmtlink local catPage = mw.title.new(catname, "Category") if (catPage.exists) then fmtlink = "" .. displaytext .. "" blueLinkCount = blueLinkCount + 1 else fmtlink = '
' .. displaytext .. "" greyLinkCount = greyLinkCount + 1 endreturn fmtlinkend
local function makeCatName(provinceName, prefix, suffix) return prefix .. provinceName .. suffixend
local function makeTableRow(rowLabel, provinceList) debugLog(2, "makeTableRow, label: ") if (rowLabel
nil) or (rowLabel
local function makeTable debugLog(1, "makeTable") local myTable = '
-- Does the pagename include a province name?local function findProvinceNameInPagename(pn) debugLog(2, "checking [" .. pn .."] for a province name") for i, aProvince in ipairs(IrelandProvinces) do debugLog(3, "testing: [" .. aProvince .. "]") if (string.find(pn, aProvince, 1, true)
debugLog(4, "match whole name? ") if (pn
debugLog(4, "match at start, followed by separator? ") if mw.ustring.match(pn, "^" .. aProvince .. "[^%w]") then debugLog(nil, "Yes") return aProvince end debugLog(nil, "No") debugLog(4, "match at end, preceded by separator? ") if mw.ustring.match(pn, "[^%w]" .. aProvince .. "$") then debugLog(nil, "Yes") return aProvince end debugLog(nil, "No")
debugLog(4, "match anywhere, preceded and followed by separator? ") if mw.ustring.match(pn, "[^%w]" .. aProvince .. "[^%w]") then debugLog(nil, "Yes") return aProvince end debugLog(nil, "No") end end return nilend
-- parse the pagename to find 3 parts: prefix, province name, suffixlocal function parsePagename(pn) debugLog(1, "parsePagename: [" .. pn .. "]") local validProvinceName validProvinceName = findProvinceNameInPagename(pn)
if validProvinceName
local function getYesNoParam(args, thisParamName, defaultVal) local paramVal = args[thisParamName] if paramVal
debugLog(2, "Evaluate yes/no parameter: [" .. thisParamName .. "] = [" .. paramVal .. "]") debugLog(3, "default = " .. ((defaultVal and "Yes") or "No")) debugLog(3, "Evaluate as: ") local returnValue if paramVal
local function makeErrorMsg(s) return '
' .. parentname .. ' Error: ' .. s .. '
\n'endlocal function isValidParent(p) local i, aParent for i, aParent in ipairs(callingTemplates) do if p
function p.main(frame) local parent = frame:getParent if parent then parentname = parent:getTitle:gsub('/sandbox$', ) end
if (parentname
Error: ' .. parentname .. ' is not a valid wrapper for \n' errormsg = errormsg .. '
Valid wrappers: ' local i, aParent for i, aParent in ipairs(callingTemplates) do errormsg = errormsg .. '' .. aParent .. '' end errormsg = errormsg .. '
-- 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 makeErrorMsg("only for use on a category page") .. 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 local trackingCatInvalid = "" return makeErrorMsg('the name of this category does not include a valid Irish province') .. publishDebugLog .. trackingCatInvalid end debugLog(1, "all parse done") debugLog(2, "title_prefix = [" .. title_prefix .. "]") debugLog(2, "title_suffix = [" .. title_suffix .. "]")
return publishDebugLog .. makeTable .. trackingCategory
end
return p