Module:Sandbox/BrownHairedGirl/IrelandByCountyCatNav2 explained

local 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 .. "" end

return fmtlinkendlocal p =

function nil_to_empty(s) if (s

nil) then return "" end return send

function boolify(s) if (s

nil or s

) then return false end s = s:lower if (s

'y' or s

'yes') then return true end return falseend

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 is_title_specified(prefix, suffix) local prefix_and_suffix = "" prefix_and_suffix = prefix .. suffix if (prefix_and_suffix

) then return false else return true endend

function parse_pagename(pn) match_prefix, match_county, match_suffix = string.match(pn, "^(.*)(County %a+)(.*)$") if (match_county

nil or match_county

) then return false end title_prefix = match_prefix title_suffix = match_suffix

retval = retval .. "\n* thispagename = [" .. thispagename .. "]" retval = retval .. "\n**match_prefix = [" .. match_prefix .."]" retval = retval .. "\n**match_county = [" .. match_county .."]" retval = retval .. "\n**match_suffix = [" .. match_suffix .."]" return retvalend

-- Named arguments, used like: function p.main(frame)-- get parameters, if any local p_before = nil_to_empty(frame.args.before) local p_after = nil_to_empty(frame.args.after) local p_nocounty = frame.args.nocounty

-- parse parameters, if any

-- convert boolean parameters to a boolean value p_nocounty = (boolify(p_nocounty))

-- get the page title thispage = mw.title.getCurrentTitle thispagename = thispage.text;

title_prefix = p_before title_nocounty = p_nocounty title_suffix = p_after

-- now check whether to parse the page titleretval = "* p_before = [" .. p_before .. "]\n* p_after = [" .. p_after .. "]"retval = retval .. "\n*p_before .. p_after = [" .. p_before .. p_after .. "]\n\n\n"

if not (is_title_specified(p_before, p_after)) then if not (parse_pagename(thispagename)) then return "\ncannot parse pagename: [" .. thispagename .. "]" end return parse_pagename(thispagename) else return "\n\n\is_title_specified = yes\n* p_before = [" .. p_before .. "]\n* p_after = [" .. p_after .. "]" end

retval = retval .. "

"
	retval = retval .. '\nbefore=[' .. p_before .. ']' .. '\nafter=[' .. p_after .. ']' .. '\nnocounty=[' .. "p_nocounty" .. ']' 
	retval = retval .. "
" retval = retval .. "\n\n-->\n\n* Cat = [" .. make_cat_name("Mayo", p_before, p_after, p_nocounty) .. "]\n" retval = retval .. "* Catlink = " .. make_cat_link(make_cat_name("Mayo", p_before, p_after, p_nocounty), "Mayo") retval = retval .. "\n* thispage" retval = retval .. "\n**pagename = [" .. thispagename .."]" retval = retval .. "\n**namespace = [" .. thispage.namespace .."]" retval = retval .. "\n**namespace as text = [" .. thispage.nsText .."]" retval = retval .. "\n**is it a cat? = " if (thispage:inNamespace(14)) then retval = retval .. "yes" else retval = retval .. "no" end return retvalend

return p