Module:Geological time/sandbox
Appearance
![]() | This is the module sandbox page for Module:Geological time (diff). |
![]() | This Lua module is used on approximately 3,900 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Automatically produce see also hatnote for geological categories that links to categories for adjacent time spans.
For test cases, see {{Geological category see also/testcases}}
Usage
{{#invoke:Geological time|seeAlso}}
is the standard usage.
{{#invoke:Geological time|seeAlso|article_title}}
performs a test for any article title. For example:
{{#invoke:Geological time|seeAlso|Category:Jurassic animals}}
→
Two specialized entry points for finding time spans before and after the argument:
{{#invoke:Geological time|before|Jurassic}}
→ Triassic
{{#invoke:Geological time|after|Triassic}}
→ Jurassic
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local hatnoteModule = require('Module:Hatnote')
local hatnote = hatnoteModule._hatnote
local formatLink = hatnoteModule._formatLink
local makeWikitextError = hatnoteModule.makeWikitextError
local p = {}
p.eon = {'Hadean', 'Archean', 'Proterozoic', 'Phanerozoic'}
p.era = {'Eoarchean', 'Paleoarchean', 'Mesoarchean', 'Neoarchean',
'Paleoproterozoic', 'Mesoproterozoic', 'Neoproterozoic',
'Paleozoic', 'Mesozoic', 'Cenozoic'}
p.period = {'Siderian', 'Rhyacian', 'Orosirian', 'Statherian',
'Calymmian', 'Ectasian', 'Stenian',
'Tonian', 'Cryogenian', 'Ediacaran',
'Cambrian', 'Ordovician', 'Silurian', 'Devonian', 'Carboniferous', 'Permian',
'Triassic', 'Jurassic', 'Cretaceous', 'Paleogene', 'Neogene', 'Quaternary'}
p.epoch = {'Terraneuvian', 'Cambrian Series 2', 'Miaolingian', 'Furongian',
'Early Ordovician', 'Middle Ordovician', 'Late Ordovician',
'Llandovery', 'Wenlock', 'Ludlow', 'Pridoli',
'Early Devonian', 'Middle Devonian', 'Late Devonian',
'Mississippian', 'Pennsylvanian',
'Cisuralian', 'Guadalupian', 'Lopingian',
'Early Triassic', 'Middle Triassic', 'Late Triassic',
'Early Jurassic', 'Middle Jurassic', 'Late Jurassic',
'Early Cretaceous', 'Late Cretaceous',
'Paleocene', 'Eocene', 'Oligocene',
'Miocene', 'Pliocene', 'Pleistocene', 'Holocene'}
p.age = {'Fortunian', 'Cambrian Stage 2', 'Cambrian Stage 3', 'Cambrian Stage 4',
'Wuliuan', 'Drumian', 'Guzhangian', 'Paibian', 'Jiangshanian', 'Cambrian Stage 10',
'Tremadocian', 'Floian', 'Dapingian', 'Darriwilian', 'Sandbian', 'Katian', 'Hirnantian',
'Rhuddanian', 'Aeronian', 'Telychian', 'Sheinwoodian', 'Homerian', 'Gortian', 'Ludfordian', 'Pridoli',
'Lochkovian', 'Pragian', 'Emsian', 'Eifelian', 'Givetian', 'Frasnian', 'Famennian',
'Tournaisian', 'Viséan', 'Serpukhovian', 'Bashkirian', {main='Moscovian', suffix='(Carboniferous)'}, 'Kasimovian', 'Gzhelian',
'Asselian', 'Sakmarian', 'Artinskian', 'Kungurian', 'Roadian', 'Wordian', 'Capitanian', 'Wuchiapingian', 'Changhsingian',
'Induan', 'Olenekian', 'Anisian', 'Ladinian', 'Carnian', 'Norian', 'Rhaetian',
'Hettangian', 'Sinemurian', 'Pliensbachian', 'Toarcian', 'Aalenian', 'Bajocian',
'Bathonian', 'Callovian', {main='Oxfordian', suffix='(stage)'}, 'Kimmeridgian', 'Tithonian',
'Berriasian','Valanginian','Hauterivian','Barremian','Aptian','Albian',
'Cenomanian','Turonian','Coniacian','Santonian','Campanian','Maastrichtian',
'Danian','Selandian','Thanetian','Ypresian','Lutetian','Bartonian','Priabonian','Rupelian','Chattian',
{main='Aquitanian', suffix='(stage)'},'Burdigalian','Langhian','Serravallian','Tortonian','Messinian','Zanclean','Piacenzian',
'Gelasian',{main='Calabrian', suffix='(stage)'},'Calabrian','Late Pleistocene','Greenlandian','Northgrippian','Meghalayan'}
local function startsWith(s, sub)
local sLen = mw.ustring.len(s)
local subLen = mw.ustring.len(sub)
if subLen > sLen then
return false
end
if mw.ustring.sub(s:lower(),1,subLen) == sub:lower() then
return mw.ustring.sub(s,subLen+1)
end
return false
end
local function searchStringList(span)
if type(span) == "table" then
return {span.main.." "..span.suffix, span.main}
end
return {span}
end
local function matchedString(span, suffix)
if type(span) == "table" then
if suffix == "" then
return span.main.." "..span.suffix
end
return span.main..suffix
end
return span..suffix
end
local function find(s)
for _, list in ipairs({p.eon, p.era, p.period, p.epoch, p.age}) do
local listLen = #list
for i, span in ipairs(list) do
for searchString in searchStringList(span) do
local suffix = startsWith(s, searchString)
if suffix then
local prev = i > 1 and matchedString(list[i-1], suffix)
local next = i < listLen and matchedString(list[i+1], suffix)
return {prev=prev, next=next}
end
end
end
end
return nil
end
function p._pair(namespace, prev, next)
local prevTitle = prev and mw.title.new(prev,namespace)
local nextTitle = next and mw.title.new(next,namespace)
if not prevTitle and not nextTitle then
return ""
end
prevTitle = prevTitle and prevTitle.exists and prevTitle
nextTitle = nextTitle and nextTitle.exists and nextTitle
if not prevTitle and not nextTitle then
return ""
end
local note = "See also the"
if prevTitle then
note = note.." preceding "..formatLink{link=prevTitle.fullText}
end
if prevTitle and nextTitle then
note = note.." and the"
end
if nextTitle then
note = note.." succeeding "..formatLink{link=nextTitle.fullText}
end
return hatnote(note,{extraclasses="seealso"})
end
function p._seeAlso(args)
local title = args[1] and mw.title.new(args[1]) or mw.title.getCurrentTitle()
if not title then
return makeWikitextError("Title failure in Module:Geological time")
end
local basetext = title.baseText
local namespace = title.namespace
local adjacent = find(basetext)
if not adjacent then
return mw.title.getCurrentTitle().nsText == "Template" and "" or makeWikitextError("Cannot find geological time frame in "..basetext)
end
return p._pair(namespace, adjacent.prev, adjacent.next)
end
function p.seeAlso(frame)
local args = getArgs(frame)
return p._seeAlso(args)
end
return p