--v01
-- configlocal textSize = '90%'local tableClass="infobox"local tableFallbackMaxWidth="auto"local tableMaxWidth="calc(100% - 300px)"local tableStyle="margin-left:auto; margin-right:auto; clear:left; float:left;"local RowStyle = ""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 title_prefix = ""local title_suffix = ""local thisPageDecade = nil
local getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local p =
function makeTableRow debugLog(2, "makeTableRow") thisRow = '
thisRow = thisRow .. '
\n' for i = -5, 5 do thisRow = thisRow .. "* " .. makeCatLink(thisPageDecade + (i * 10)) .. "\n" end thisRow = thisRow .. '
function makeTable debugLog(1, "makeTable") tableRowNum = 0 local myTable = '
-- Make a piped link to a decade category, if it exists-- If it doesn't exist, just display the greyed the link title without linkingfunction makeCatLink(x) local decadeFulltext = tostring(math.abs(x)) .. 's' if x < 0 then decadeFulltext = decadeFulltext .. " BC" end local catname = title_prefix .. decadeFulltext .. title_suffix
local fmtlink local catPage = mw.title.new(catname, "Category") if (catPage.exists) then fmtlink = "" .. decadeFulltext .. "" else fmtlink = '
' .. decadeFulltext .. "" 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
function patternSearchEncode(s) return mw.ustring.gsub(s, "([%W])", "%%%1")end
-- parse the pagename to find 3 parts: prefix, decade, suffixfunction parsePagename(pn) debugLog(1, "parsePagename: [" .. pn .. "]") match_prefix, match_decade, match_suffix = mw.ustring.match(pn, "^(.-)(%d+0s BC)(.*)$") if match_decade
nil then debugLog(2, 'Invalid. [' .. pn .. '] no decade"') return false end debugLog(2, 'Split [' .. pn .. ']: /' .. match_prefix .. '/' .. match_decade ..'/' .. match_suffix ..'/') if (match_prefix ~= nil) and (match_prefix ~= "") then if (mw.ustring.sub(match_prefix, -1) ~= ' ') then debugLog(2, 'Invalid. [' .. pn .. '] has no space before decade') return false end end
if (match_suffix ~= nil) and (match_suffix ~= "") then if (mw.ustring.sub(match_suffix, 1, 1) ~= ' ') then debugLog(2, 'Invalid. [' .. pn .. '] has no space after decade') return false end end -- if we got here, all is valid -- next, check for BC local isBC = false if (mw.ustring.sub(match_decade, -3)
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 local i for i = 1, level do if (i % 2)
function getYesNoParam(args, thisParamName, defaultVal) local returnValue debugLog(2, "Evaluate yes/no parameter: [" .. thisParamName .. "] = [" .. (((args[thisParamName]
function p.main(frame) debugLog(1, "Check parameters") debugging = getYesNoParam(frame.args, "debug", false)
-- 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