require('strict')local getArgs = require('Module:Arguments').getArgslocal catPair = require('Module:Category pair')._pair
local p =
-- Ordered list of eons, era, periods, etc. The code will search through-- these lists for a match, then return an appropriate link to the timespans-- adjacent to those matchesp.eon = p.era = p.period = p.epoch = p.series = p.age =
-- Determine whether a query string matches a stored timespan string-- Arguments:-- s: query string-- sub: standard name of timespan-- Returns:-- false if there is no match-- prefix and suffix of match, otherwiselocal function matches(s, sub) local sLen = mw.ustring.len(s) local subLen = mw.ustring.len(sub) if subLen > sLen then return false end local lowerS = mw.ustring.lower(s) local lowerSub = mw.ustring.lower(sub) local startOffset, endOffset = mw.ustring.find(lowerS,lowerSub,1,true) if not startOffset then return false end return (mw.ustring.sub(s,1,startOffset-1) or ""), (mw.ustring.sub(s,endOffset+1) or "")end
-- Create list of strings to search corresponding to a standard timespan-- Some timespans are disambiguated: first search for the dabbed title, then-- the base title. Otherwise just search for the standard timespan string-- Argument:-- span = value in timespan lists (above)-- Returns:-- list of strings to search in query stringlocal function searchStringList(span) if type(span)
-- When an adjacent time span is found, this function returns the-- corresponding basename for the page.-- Arguments:-- span: adjacent entry from table, above-- prefix: prefix of query string before match-- suffix: remainder of original query string beyond match-- Returns:-- page title---- If the adjacent time span is dabbed, then return the dab if the suffix-- is empty. If the suffix is non-empty (e.g., "life"), append it to the base-- name of the span (e.g., "Oxfordian") --> "Oxfordian life"local function matchedString(span, prefix, suffix) if type(span)
"" and suffix
-- Function to find the page titles of time spans adjacent to a query string-- Arguments:-- s: query string to search forlocal function find(s) -- Search from most-specific to least, to catch "Cambrian Series 2" before "Cambrian" for _, list in ipairs do local listLen = #list for i, span in ipairs(list) do -- Each timespan might have more than one search string for _, searchString in ipairs(searchStringList(span)) do local prefix, suffix = matches(s, searchString) if suffix then local prevSpan = i > 1 and matchedString(list[i-1], prefix, suffix) local nextSpan = i < listLen and matchedString(list[i+1], prefix, suffix) -- return first match found return end end end end return nil end
-- Lua entry point to generate see also hatnote for geological time spans adjanct in time-- Arguments:-- args[1]: name of page to generate adjacency (current page if None)-- Returns:-- See also previous and next, formatted as a hatnotefunction p._seeAlso(args) local title = args[1] and mw.title.new(args[1]) or mw.title.getCurrentTitle local basetext = title.baseText local namespace = title.namespace local adjacent = find(basetext) if not adjacent then local warning = require('Module:If preview')._warning local warn = warning if mw.title.getCurrentTitle.nsText ~= "Template" then warn = warn.."" end return warn end local prevTitle = adjacent and adjacent.prev and mw.title.new(adjacent.prev, namespace) local nextTitle = adjacent and adjacent.next and mw.title.new(adjacent.next, namespace) return catPair(prevTitle, nextTitle)end
-- Template entry pointfunction p.seeAlso(frame) local args = getArgs(frame) return p._seeAlso(args)end
return p