Module:Sandbox/BrownHairedGirl/valueFunc: Difference between revisions

Content deleted Content added
myArgs
width:80% !important;"
Line 11:
-- * county name = "County Sligo"
-- * suffix = "-related lists"
 
local ROI_counties = {
'Carlow',
'Cavan',
'Clare',
'Cork',
'Donegal',
'Dublin',
'Galway',
'Kerry',
'Kildare',
'Kilkenny',
'Laois',
'Leitrim',
'Limerick',
'Longford',
'Louth',
'Mayo',
'Meath',
'Monaghan',
'Offaly',
'Roscommon',
'Sligo',
'Tipperary',
'Waterford',
'Westmeath',
'Wexford',
'Wicklow'
}
 
local Norniron_counties = {
'Antrim',
'Armagh',
'Down',
'Fermanagh',
'Londonderry',
'Tyrone'
}
 
local New_counties = {
'Dún Laoghaire–Rathdown',
'Fingal',
'South Dublin'
}
 
 
 
function nil_or_value(s)
Line 18 ⟶ 64:
return s
end
 
function makeTable()
local i, myCounty
local myTable = '<table class="infobox" style="margin-left:auto; margin-right:auto; font-size: 90%; clear:left; float:left; width:80% !important;">\n'
myTable = myTable .. '<tr>\n'
-- myTable = myTable .. '<td colspan="2" style="text-align:center; background-color:#f3f3f3"></td>\n'
myTable = myTable .. '</tr>\n'
myTable = myTable .. '<td style="text-align:right; font-weight: bold;">' .. 'Republic of Ireland</td>\n'
myTable = myTable .. '<td style="text-align:center;"><div class="hlist">\n'
for i, myCounty in ipairs(ROI_counties) do
myCatName = make_cat_name(myCounty, title_prefix, title_suffix, title_nocountyword)
myTable = myTable .. "* " .. make_cat_link(myCatName, myCounty) .. "\n"
local j, nuCounty
if (myCounty == "Dublin") then
for j, nuCounty in ipairs(New_counties) do
myCatName = make_cat_name(nuCounty, title_prefix, title_suffix, true)
myTable = myTable .. "** " .. make_cat_link(myCatName, nuCounty) .. "\n"
end
myCatName = make_cat_name("Dublin (city)", title_prefix, title_suffix, title_nocountyword)
myTable = myTable .. "** " .. make_cat_link(myCatName, "city") .. "\n"
end
end
 
myTable = myTable .. "</div></td></tr>"
myTable = myTable .. '<tr style="margin:1.5em; background-color:#f3f3f3">\n'
myTable = myTable .. '<td style="text-align:right; font-weight: bold;">' .. 'Northern Ireland</td>\n'
myTable = myTable .. '<td style="text-align:center;"> <div class="hlist">\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 .. "</div></td></tr></table>\n"
return myTable
end
 
local debugmsg = " "nil
local getArgs = require('Module:Arguments').getArgs
local p = {}
Line 55 ⟶ 133:
return this_cat_name
end
 
 
function find_new_county_name_in_pagename(pn)
local i = 1
while (new_counties[i] ~= nil) do
local testCounty = new_counties[i]
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
if i > 10 then
return nil
end
end
return nil
end
 
 
function parse_pagename(pn)
Line 61 ⟶ 164:
match_prefix, match_county, match_suffix = string.match(pn, "^(.*)(County%s+%a+)(.*)$")
if (match_county == nil or match_county == '') then
debuglog(3, "No match_countymatch_'County Foo'")
if (true) then return false end
debuglog(2, "try new counties")
local new_county = find_new_county_name_in_pagename(pn)
if new_county == nil then
debuglog(3, "no match in new counties")
return false
end
debuglog(3, "found new county: [" .. new_county .. "]")
match_prefix, match_county, match_suffix = string.match(pn, "^(.*)(" .. 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 .. "]")
Line 71 ⟶ 186:
 
function debuglog(level, msg)
 
if false then
if (debugmsg == ""nil) then -- we are not debugging
return false
end
 
if (string.match(debugmsg, "^%s+$")) then
debugmsg = "'''==Debugging''': ==\n\n"
end
 
end
debugmsg = debugmsg .. "\n"
if (level == 1) then
Line 87 ⟶ 202:
elseif (level == 3) then
debugmsg = debugmsg .. "#*# "
elseif (level == 4) then
debugmsg = debugmsg .. "#*#* "
end
debugmsg = debugmsg .. " " .. msg
return true
end
Line 130 ⟶ 247:
debuglog(1, "set main variables")
debuglog(2, "title_prefix = [" .. title_prefix .. "]")
debuglog(2, "title_prefixtitle_suffix = [" .. title_prefixtitle_suffix .. "]")
-- get the page title
Line 152 ⟶ 269:
if ((title_prefix .. title_suffix) == '') then
debuglog(1, "Yes, we need to parse the page title")
parse_pagename(thispagename)
else
debuglog(1, "No, we don't need to parse the page title")
end
debuglog(1, "all parse done")
return debugmsg
debuglog(2, "title_prefix = [" .. title_prefix .. "]")
debuglog(2, "title_suffix = [" .. title_suffix .. "]")
 
if (debugmsg == nil) then
debugmsg = ""
else
debugmsg = debugmsg .. "\n== Output ==\n"
end
return debugmsg .. makeTable()