Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/BrownHairedGirl/IrelandByCountyCatNav2
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function make_cat_link(catname, disp) local displaytext if (disp ~= "") then displaytext = disp else displaytext = catname end local link = "[[:Category:" .. catname .. "|" .. displaytext .. "]]" local fmtlink local linktitle = mw.title.new( catname, "Category" ) if (linktitle.exists) then fmtlink = link else fmtlink = "<span style=\"color:#888\">" .. displaytext .. "</span>" end return fmtlink end local p = {} function nil_to_empty(s) if (s == nil) then return "" end return s end 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 false end 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_name end 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 end end 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 retval end -- Named arguments, used like: {{#invoke:IrelandByCountyCatNav|before=foo|after=}} 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 title retval = "* 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 .. "<pre>" retval = retval .. '\nbefore=[' .. p_before .. ']' .. '\nafter=[' .. p_after .. ']' .. '\nnocounty=[' .. "p_nocounty" .. ']' retval = retval .. "</pre>" 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 retval end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/BrownHairedGirl/IrelandByCountyCatNav2/doc
(
edit
)