Module:Archive
Appearance
![]() | This Lua module is used on approximately 322,000 pages, or roughly 1% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | 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. |
![]() | This module depends on the following other modules: |
This module produces a banner for talk archive pages. The module detects surrounding archives automatically and creates navigational links to them, hence the name.
Usage
This module is accessed via a template, Template:Archive. See the template page for documentation.
Dependencies
This module uses a configuration module at Module:Archive/config. It also uses Module:Highest archive number, Module:Arguments, Module:Yesno, and Module:Message box.
--
-- This module implements {{Automatic archive navigator}}
--
local p = {}
local args
local frame
local thisPage = mw.title.getCurrentTitle()
-- Get the name of the subpage a certain distance away.
-- e.g. if the current subpage is /Archive 27, getSubpageName(3) returns 'Archive 30'
local function getSubpageName(offset)
local startIdx, endIdx, archiveNum = mw.ustring.find(thisPage.subpageText, '^Archive ([0-9]+)')
if archiveNum then
return 'Archive ' .. (archiveNum + offset)
else
return thisPage.subpageText + offset
end
end
-- Get a formatted link to the subpage a certain distance away, or nil
-- if that subpage does not exist.
local function getSubpageLink(offset)
local subpageName = getSubpageName(offset)
local page = mw.title.new(thisPage.baseText .. '/' .. subpageName, thisPage.namespace)
if page.exists then
return '[[../' .. subpageName .. '|' .. subpageName .. ']]'
else
return nil
end
end
local function getLinksText()
local arrowSpacer = ' '
local linkSpacer = ' '
if mw.ustring.len(thisPage.subpageText) <= 4 then
-- If page names are short, we want more space. But why the mix of regular, non-breaking, and em spaces?
local emSpace = frame:expandTemplate({title = 'Unicode', args = {mw.ustring.char(8195)}})
arrowSpacer = ' ' .. emSpace .. ' '
linkSpacer = ' ' .. emSpace .. ' ' .. emSpace .. ' '
end
local s = ''
for offset = -5, -3 do
local link = getSubpageLink(offset)
if link then
if offset == -3 then
s = s .. link .. linkSpacer
else
s = s .. link .. ' ←' .. arrowSpacer
end
break
end
end
for offset = -2, -1 do
local link = getSubpageLink(offset)
if link then
s = s .. link .. linkSpacer
end
end
s = s .. '<span style="font-size:115%;">[[' .. thisPage.fullText .. '|' .. getSubpageName(0) .. ']]</span>'
for offset = 1, 2 do
local link = getSubpageLink(offset)
if link then
s = s .. linkSpacer .. link
end
end
for offset = 5, 3, -1 do
local link = getSubpageLink(offset)
if link then
if offset == 3 then
s = s .. linkSpacer .. link
else
s = s .. arrowSpacer .. '→ ' .. link
end
break
end
end
return s
end
local function getMessage()
if args[1] == '1' then
return ''
else
local msg = '----\n'
if args.text then
msg = msg .. args.text
else
msg = msg .. "This is an '''[[Help:Archiving a talk page|archive]]''' of past discussions"
if args.period then
msg = msg .. " for the period '''" .. args.period .. "'''"
end
msg = msg .. ". '''Do not edit the contents of this page.''' If you wish to start a new discussion or revive an old one, please do so on the "
msg = msg .. "[[" .. thisPage.rootPageTitle.fullText .. "|current talk page]]."
end
return msg
end
end
local function _aan()
frame = mw.getCurrentFrame()
-- For testing purposes, allow passing in the page name as a param.
if args.title then
thisPage = mw.title.new(args.title)
else
thisPage = mw.title.getCurrentTitle()
end
local image = args.image
if not image then
image = '[[File:' .. (args.icon or 'Replacement filing cabinet.svg') .. '|40x40px|alt=|link=]]'
end
local mbox = frame:expandTemplate({title = 'tmbox', args = {
image = image,
imageright = args.imageright,
style = args.style or 'width:80%;margin-left:auto;margin-right:auto;',
textstyle = args.textstyle or 'text-align:center;',
text = getLinksText() .. '\n' .. getMessage()
}})
return mbox .. '__NONEWSECTIONLINK__ __NOEDITSECTION__'
end
function p.aan(frame)
local origArgs
-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
-- ParserFunctions considers the empty string to be false, so to preserve the previous
-- template behavior, change any empty arguments to nil, so Lua will consider
-- them false too.
args = {}
for k, v in pairs(origArgs) do
if v ~= '' then
args[k] = v
end
end
return _aan()
end
return p