Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Archives: Difference between revisions

Template page
Content deleted Content added
Copied from Wikipedia
 
:rockball_player:
 
Line 1: Line 1:
{{talk other|<templatestyles src="Module:Message box/tmbox.css"/>|<templatestyles src="Module:Message box/ombox.css"/>|demospace={{{demospace|}}}}}
-------------------------------------------------------------------------------
<table id="archivebox" role="presentation"<!-- Remove the implicit inherent semantics associated with a table element and make it equivalent to a div element --> class="{{talk other|tmbox tmbox-notice|ombox ombox-notice|demospace={{{demospace|}}}}} {{#ifeq:{{{banner|{{{large}}}}}}|yes||mbox-small}} {{#ifeq:{{{collapsed}}}|yes|mw-collapsible mw-collapsed|{{#ifeq:{{{collapsible}}}|yes|mw-collapsible}}}} noprint {{{class|}}}" style="text-align: center; padding: 1em; {{#if:{{{box-width|}}}|width:{{{box-width}}};}} {{#ifeq:{{{banner|{{{large}}}}}}|yes|min-width:80%;}} {{{style|}}}" aria-labelledby="archives-heading"<!-- The meaning of this "div" element is contained by this ID. --> aria-description="{{{aria-description|form containing {{#if:{{{noarchives|}}}||links to all this page's archive subpages and}} {{#if:{{{search}}}||a textbox to search this page's archive subpages}}}}}"><!-- If the correct keys/setting in assistive tech are used, the description will give more info. -->
-- Automatic archive navigator
<tr>
--
{{#ifeq:{{{banner|{{{large}}}}}}|yes
-- This module produces a talk archive banner, together with an automatically-
|<!-- Banner style: image in a rowspan cell (if present) -->
-- generated list of navigation links to other archives of the talk page in
{{#ifeq:{{{image|}}}|none||
-- question. It implements {{Archive}}.
<td rowspan="{{#expr:1+{{#ifeq:{{{search}}}|no|0|1}}+{{#if:{{{list|{{{1|}}}}}}|1|0}}+{{#if:{{{age|}}}{{{target|}}}|1|0}}}}" class="mbox-image" style="width:52px;" id="archives-icon" aria-hidden="true"><!-- Hide all icons. They give _no_ info to accessibility tech nor readers with visual impairment --><!--
-------------------------------------------------------------------------------
-->{{#invoke:InfoboxImage|InfoboxImage|alt=|image={{{image|Replacement filing cabinet.svg}}}|size={{{image-size|}}}|sizedefault=40px}}

</td>
local yesno = require('Module:Yesno')
{{#if:{{{noarchives|}}}|</tr>}}

}}
-------------------------------------------------------------------------------
|<!-- Box style: header row, with image (if present) -->
-- Helper functions
<td style="padding:0.6em 0 0.25em;">
-------------------------------------------------------------------------------
<div style="{{#ifeq:{{{image|}}}|none||width:100%; overflow:hidden;}}">{{#ifeq:{{{image|}}}|none||<div id="archives-icon" aria-hidden="true">{{#invoke:InfoboxImage|InfoboxImage|alt=|image={{{image|Replacement filing cabinet.svg}}}|size={{{image-size|}}}|sizedefault=40px}}</div><br/>}}<span id="archives-heading"><b>{{{title|Archives}}}</b></span></div>

</tr>{{#if:{{{noarchives|}}}||<tr>}}
local function makeWikilink(page, display)
}}
if display then
{{#if:{{{noarchives|}}}||<td class="plainlinks {{#ifeq:{{{banner|{{{large}}}}}}|yes|mbox-text}}"><!--
return string.format('[[%s|%s]]', page, display)
-->{{#ifeq:{{{banner|{{{large}}}}}}|yes|<div class="archives-prevent-banner-paragraphs"><span id="archives-heading">{{{title|Archives}}}</span>&#58;&#32;}}{{#switch:{{#if:{{{list|}}}|no|{{{auto|{{#if:{{{1|}}}|no|{{#if:{{{inlinelist|}}}|inlinelist}} }} }}} }}
else
|#default={{#ifeq:{{{index|}}}|none||{{#ifexist:{{#rel2abs:./{{{index|Archive index}}}}}|[[{{#rel2abs:./{{{index|Archive index}}}}}|Index]]&#32;|{{#ifexist:User:ClueBot III/Master Detailed Indices/{{FULLPAGENAME}}|[[User:ClueBot III/Master Detailed Indices/{{FULLPAGENAME}}|Index]]&#32;}} }}
return string.format('[[%s]]', page)
}}{{#ifexist:{{#rel2abs:{{#if:{{{archivelist|}}}|{{{archivelist}}}|./archivelist}} }}
end
|<div style="text-align:left;">{{ {{#rel2abs:{{{archivelist|./archivelist}}}}} }}</div>
end
|{{Archive list

|{{#if:{{{root|}}}|root|DISABLE1}}={{{root}}}
local function escapePattern(s)
|{{#ifeq:{{{banner|{{{large}}}}}}|yes|DISABLE2|auto}}={{{auto|long}}}
-- Escape punctuation in a string so it can be used in a Lua pattern.
|nobr={{#ifeq:{{{banner|{{{large}}}}}}|yes|yes|no}}
s = s:gsub('%p', '%%%0')
|{{#if:{{{prefix|}}}|prefix|DISABLE3}}={{{prefix|}}}
return s
|{{#if:{{{start|}}}|start|DISABLE4}}={{{start|}}}
end
}}

}}
local function makeTable(width)
|inlinelist={{{inlinelist|}}}
local archiveTable = mw.html.create('table')
|no=<!--no output-->}}{{#if:{{{nobot|}}}||{{#if:{{Th/abp|bot|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}|{{#if:{{{tooltip|}}}|<!--Compact tooltip version of archive configuration summary-->
archiveTable
<div style="position: relative; top: 2px; {{#ifeq:{{{banner|{{{large}}}}}}|yes|float: right;|margin-bottom: 1ex;}} font-size: 90%; margin-left: 1em;">{{Tooltip|Auto-archiving<!--
:css({
-->{{#if:{{Th/abp|age|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}|&#32;period}}<!--
['max-width'] = width,
-->|{{Automatic archives blurb|root={{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|}}}|nowikitext=y}} }}<!--
['margin'] = '0 auto 0.5em',
-->{{#if:{{Th/abp|age|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}|{{colon}} '''{{human readable duration|{{Th/abp|age|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}|{{Th/abp|units|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}<!---->}}'''}}<!--
['text-align'] = 'center'
-->&nbsp;[[File:Information icon4.svg|16px|link=Help:Archiving a talk page#Automated archiving|alt=]]</div>}} }} }}
})
{{#ifeq:{{{banner|{{{large}}}}}}|yes|</div>|<!--This div should only be opened in the banner display.-->}}</td><!--List/1 MUST be separate from all other tags-->
-- Set width so that the table doesn't spill out on narrower skins
</tr>{{#if:{{{list|{{{1|}}}}}}
-- or when zooming in. It has to be defined multiple times because
|<tr><td class="plainlinks" style="padding:0px 10px; {{#ifeq:{{{banner|{{{large}}}}}}|yes||text-align:left;}}">
-- "stretch" is experimental.
{{{list|{{{1|}}}}}}<!--Parameters MUST be on newline or some wikimarkup will fail-->
:cssText('width:100%;width:-moz-available;width:-webkit-fill-available;width:stretch')
</td></tr>}}
return archiveTable
}}<!--end #if noarchives
end
-->{{#ifeq:{{{search}}}|no||<tr><td style="padding-bottom:11px"><div id="archives-inputbox-id"<!-- This is so they can be targeted by custom CSS for accessibility reasons. --> class="archives-inputbox-css" role="search"<!-- The search role is a landmark role that can be added to the container element that encompasses all of the elements that combined to form the search feature --> aria-label="talk archive"<!-- If there is more than one search landmark role in a document, provide a label for each landmark. a declaration of role="search" with an aria-label="Sitewide search" may be announced redundantly as, "sitewide search search".

so give it the label "talk archive"--> aria-description="search results will load on a new page"<!-- If the correct keys/setting in assistive tech are used, the description will give more info. -->>{{#tag:inputbox|
-- Check to see if the page is likely an annual archive. No talk pages exist
bgcolor=transparent
-- before 2001. Some pages have the next year created in advance.
type=fulltext
local function isYearlyArchive(num)
prefix={{if empty|{{{searchprefix|}}}|{{{root|}}}|{{FULLPAGENAME}}/}}
local currentYear = tonumber(os.date("%Y"))
break={{#ifeq:{{{banner|{{{large}}}}}}|yes|{{{search-break|no}}}|{{{search-break|yes}}}}}
return num and num >= 2001 and num <= currentYear + 1 -- possible years
width={{#ifeq:{{{banner|{{{large}}}}}}|yes||{{#if:{{{search-width|}}}|{{{search-width}}}|22}} }}
end
searchbuttonlabel={{{search-button-label|{{{button-label|Search archives}}}}}}
local function detectArchiveFormat(title, args)
placeholder={{{placeholder|Search term}}}<!-- If the correct keys/setting in assistive tech are used, the description will give more info. -->
-- Check if next/previous are set. Some archives swap between annual and
}}</div>
-- sequential archives at some point and will need to accept whatever an
</td></tr>
-- editor says the next/previous link should be for these kind of weird
}}{{#if:{{{age|}}}{{{archive_age|}}}{{{target|}}}{{Th/abp|bot|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}|<tr><td {{#ifeq:{{{banner|{{{large}}}}}}|yes|colspan=2 }} style="padding:0px 10px; font-size:11.9px; {{#ifeq:{{{banner|{{{large}}}}}}|yes|text-align:center;}}">
-- or unsual orders.
{{#if: {{{nobot|}}}{{{tooltip|}}}||
if args and (args.prev or args.next) then
----
return nil, nil, nil
{{#if:{{{target|}}}{{Th/abp|bot|{{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|1}}}}}|This page has {{#if: {{{target|}}} |'''[[{{#rel2abs:{{{target}}}}}|archives]]'''.&#32;|archives.&#32;}}{{Automatic archives blurb|root={{{root|{{FULLPAGENAME}}}}}|cfg={{{cfg|}}}}}
end
}} }}
}}</td></tr>
-- Check if "/Archive 2" exists to prevent false positives on noticeboards
{{#ifeq:{{#if:{{{auto|}}}|auto|{{#if:{{{1|}}}|no|¬}} }}-{{{editbox|yes}}}|no-yes
local archiveBase = title.baseText
|{{#ifexist:{{#rel2abs:{{{archivelist|./archivelist}}}}}|<tr><td><small class="plainlinks">[{{fullurl:{{#rel2abs:{{{archivelist|./archivelist}}}}}|action=edit&preload=Template:Archives/Preload}} Edit this box]</small></td></tr>}}
local archive2Title = mw.title.new(archiveBase .. "/Archive 2")
}}
if archive2Title and archive2Title.exists then
</table><noinclude>{{User:MiszaBot/config <!-- for page top canonical display only -->
return nil, nil, nil -- Exit early for sequential archives
|archive = Template:Archives/
end
|counter = 3

|minthreadsleft = 4
-- How is the year formatted?
|minthreadstoarchive = 2
local patterns = {
|algo = old(90d)
{pattern = "^(.-)/Archive (%d+)$", prefix = nil}, -- "Talk:Base page/Archive YYYY"
}}{{Documentation}}
-- "nil" triggers the default. There is some kind of quirk with how
</noinclude>
-- the module give spaces that Template:Yearly archive list cannot
-- read with either a space or the HTML space entity
{pattern = "^(.-)/Archive(%d+)$", prefix = "/Archive"}, -- "Talk:Base page/ArchiveYYYY"
{pattern = "^(.-)/Archive/(%d+)$", prefix = "/Archive/"}, -- "Talk:Base page/Archive/YYYY"
{pattern = "^(.-)/Archives/(%d+)$", prefix = "/Archives/"}, -- "Talk:Base page/Archives/YYYY"
{pattern = "^(.-)/(%d+)$", prefix = "/"} -- "Talk:Base page/YYYY"
}

for _, p in ipairs(patterns) do
local basePage, archiveNum = title.prefixedText:match(p.pattern)
archiveNum = tonumber(archiveNum)
if basePage and isYearlyArchive(archiveNum) then
return basePage, true, p.prefix
end
end
return nil, nil, nil
end



-------------------------------------------------------------------------------
-- Navigator class
-------------------------------------------------------------------------------

local Navigator = {}
Navigator.__index = Navigator

function Navigator.new(args, cfg, currentTitle)
local obj = setmetatable({}, Navigator)
-- Set inputs
obj.args = args
obj.cfg = cfg
obj.currentTitle = currentTitle

-- Archive prefix
-- Decode HTML entities so users can enter things like "Archive&#32;" from
-- wikitext.
obj.archivePrefix = obj.args.prefix or obj:message('archive-prefix')
obj.archivePrefix = mw.text.decode(obj.archivePrefix)

-- Current archive number
do
local pattern = string.format(
'^%s([1-9][0-9]*)$',
escapePattern(obj.archivePrefix)
)
obj.currentArchiveNum = obj.currentTitle.subpageText:match(pattern)
obj.currentArchiveNum = tonumber(obj.currentArchiveNum)
end
-- Highest archive number
obj.highestArchiveNum = require('Module:Highest archive number')._main(
obj.currentTitle.nsText ..
':' ..
obj.currentTitle.baseText ..
'/' ..
obj.archivePrefix,
obj.currentArchiveNum
)

return obj
end

function Navigator:message(key, ...)
local msg = self.cfg[key]
if select('#', ...) > 0 then
return mw.message.newRawMessage(msg, ...):plain()
else
return msg
end
end

function Navigator:getNamespacePreposition()
-- Most talk archives are about a subject. Some will be "with" an editor
-- or "on" a noticeboard.
-- Function to get the namespace preposition
-- Namespace number where transcluded
local namespaceNumber = mw.title.getCurrentTitle().namespace
-- Preposition from table to make it easy for wikis to translate or ignore
local namespacePrepositionTable = self.cfg['namespace-prepositions']

-- Default preposition if not exception from above
return namespacePrepositionTable[namespaceNumber] or self.cfg["preposition-default"]
end

function Navigator:makeBlurb()
local args = self.args
local current = self.currentTitle
local ret
-- Skip if user provides their own blurb.
if args.text then
ret = args.text
else
-- Set parent talk page.
local parentTalkPage = current.basePageTitle
local talkPageTitle
local pageUnderDiscussion
-- If the parent talk page exists (and it's not the root talk page)
-- we should link to it in both the "main talk page" and
-- "discussions about" parts of the blurb.
if args.prefix or (parentTalkPage.exists and parentTalkPage.isRedirect == false and current.baseText ~= current.rootText) then
talkPageTitle = parentTalkPage.fullText
pageUnderDiscussion = talkPageTitle
-- If it doesn't, set "main talk page" to the root talk page
-- and "discussions about" to the root subject.
else
talkPageTitle = current.nsText .. ':' .. parentTalkPage.rootText
-- Set page under discussion.
pageUnderDiscussion = current.subjectNsText .. ':' .. current.rootText
-- Prepend colon for non-mainspace pages.
if current.subjectNsText ~= '' then
pageUnderDiscussion = ':' .. pageUnderDiscussion
end
end
-- Check current namespace for blurb.
local namespace = 'main'
if current.isTalkPage == true then
namespace = 'talk'
end
-- What kind of blurb to use in the message box?
local function getBlurbKey(args)
if args.type == 'index' then
-- For manually-indexed archives only
return 'blurb-index', args.type
elseif args.type == 'annual' then
-- Grab the year of the current archive.
return 'blurb-annual', mw.getCurrentFrame():expandTemplate {
title = 'Title year', args = { page = current.fullText }
}
elseif args.period then
return 'blurb-period', args.period
else
return 'blurb-noperiod', ''
end
end

-- Generate a blurb from Module:Archive/config
local blurbKey, argValue = getBlurbKey(args)
local namespacePreposition = self:getNamespacePreposition()
ret = self:message(blurbKey, talkPageTitle, pageUnderDiscussion, argValue, namespace, namespacePreposition)

end
return ret
end

function Navigator:makeMessageBox()
local args = self.args
local image
if args.image then
image = args.image
else
local icon = args.icon or self:message('default-icon')
image = string.format(
'[[File:%s|%s|alt=|link=]]',
icon,
self:message('image-size')
)
end

-- Hardcode tmbox style on the template's page.
-- PS: Needs to be changed if the template is renamed!
local mainTemplatePage = ''
if self.currentTitle.fullText == 'Template:Archive' then
mainTemplatePage = 'talk'
end
local mbox = require('Module:Message box').main('mbox', {
demospace = args.demospace or mainTemplatePage,
image = image,
imageright = args.imageright,
style = args.style or '',
textstyle = args.textstyle or 'text-align:center',
text = self:makeBlurb(),
})

return mbox
end

function Navigator:getArchiveNums()
-- Returns an array of the archive numbers to format.
local noLinks = tonumber(self.args.links) or self:message('default-link-count')
noLinks = math.floor(noLinks)
-- If |noredlinks is "yes", true or absent, don't allow red links. If it is
-- 'no' or false, allow red links.
local allowRedLinks = yesno(self.args.noredlinks) == false
local current = self.currentArchiveNum
local highest = self.highestArchiveNum

if not current or not highest or noLinks < 1 then
return {}
elseif noLinks == 1 then
return {current}
end

local function getNum(i, current)
-- Gets an archive number given i, the position in the array away from
-- the current archive, and the current archive number. The first two
-- offsets are consecutive; the third offset is rounded up to the
-- nearest 5; and the fourth and subsequent offsets are rounded up to
-- the nearest 10. The offsets are calculated in such a way that archive
-- numbers will not be duplicated.
if -2 <= i and i <= 2 then
return current + i
elseif -3 <= i and i <= 3 then
return current + 2 - (current + 2) % 5 + (i / 3) * 5
elseif 4 <= i then
return current + 7 - (current + 7) % 10 + (i - 3) * 10
else
return current + 2 - (current + 2) % 10 + (i + 3) * 10
end
end

local nums = {}

-- Archive nums lower than the current page.
for i = -1, -math.floor((noLinks - 1) / 2), -1 do
local num = getNum(i, current)
if num <= 1 then
table.insert(nums, 1, 1)
break
else
table.insert(nums, 1, num)
end
end

-- Current page.
if nums[#nums] < current then
table.insert(nums, current)
end

-- Higher archive nums.
for i = 1, math.ceil((noLinks - 1) / 2) do
local num = getNum(i, current)
if num <= highest then
table.insert(nums, num)
elseif allowRedLinks and (i <= 2 or i <= 3 and num == nums[#nums] + 1) then
-- Only insert one red link, and only if it is consecutive.
table.insert(nums, highest + 1)
break
elseif nums[#nums] < highest then
-- Insert the highest archive number if it isn't already there.
table.insert(nums, highest)
break
else
break
end
end

return nums
end

function Navigator:makeArchiveLinksWikitable()
local args = self.args
local lang = mw.language.getContentLanguage()
local nums = self:getArchiveNums()
local noLinks = #nums
-- Skip number processing if |prev and |next are defined.
if args.prev or args.next then
local archives = {}
if args.prev then archives[#archives + 1] = mw.title.new(args.prev) end
archives[#archives + 1] = self.currentTitle
if args.next then archives[#archives + 1] = mw.title.new(args.next) end
local table = makeTable('30em')
for _, title in ipairs(archives) do
if tostring(title) == self.currentTitle.prefixedText then
table:tag("td"):wikitext(string.format(
'<span style="font-size:115%%;">%s</span>',
makeWikilink(title.fullText, title.subpageText)
))
else
table:tag("td"):wikitext(
makeWikilink(title.fullText, title.subpageText)
)
end
end
return tostring(table)
end
if noLinks < 1 then
return ''
end

-- Make the table of links.
local links = {}
local isCompact = noLinks > 7
local currentIndex
for i, num in ipairs(nums) do
local subpage = self.archivePrefix .. tostring(num)
local display
if isCompact then
display = tostring(num)
else
display = self:message('archive-link-display', num)
end
local link = makeWikilink('../' .. subpage, display)
if num == self.currentArchiveNum then
link = string.format('<span style="font-size:115%%;">%s</span>', link)
currentIndex = i
end
table.insert(links, link)
end

-- Add the arrows.
-- We must do the forwards arrow first as we are adding elements to the
-- links table. If we did the backwards arrow first the index for the
-- current archive would be wrong.
currentIndex = currentIndex or math.ceil(#links / 2)
for i = currentIndex + 1, #links do
if nums[i] - nums[i - 1] > 1 then
table.insert(links, i, lang:getArrow('forwards'))
break
end
end
for i = currentIndex - 1, 1, -1 do
if nums[i + 1] - nums[i] > 1 then
table.insert(links, i + 1, lang:getArrow('backwards'))
break
end
end

-- Output the wikitable.
local width
if noLinks <= 3 then
width = string.format('%dem', noLinks * 10)
elseif noLinks <= 7 then
width = string.format('%dem', (noLinks + 3) * 5)
else
width = '37em'
end
local table = makeTable(width)
for _, s in ipairs(links) do
table:tag("td"):wikitext(s)
end
return tostring(table)
end

function Navigator:__tostring()
local args = self.args
local boxComponents
-- Is |omit filled? If not, make the whole box.
if args.omit == nil then

-- Check for annual archives
local currentTitle = self.currentTitle
local yearlyBase, isYearly, yearlyPattern = detectArchiveFormat(currentTitle, args)

if isYearly then
-- Use a yearly archive format
local linksYearlyListSeparator = "&#32;" -- Space separator
local linksYearlyList = mw.getCurrentFrame():expandTemplate {
title = 'Yearly archive list',
args = {
root = yearlyBase,
sep = linksYearlyListSeparator,
prefix = yearlyPattern
}
}
boxComponents = self:makeMessageBox() .. '\n' ..
'<div style="font-size:115%; width:100%; word-spacing:1em; text-align:center;">' .. linksYearlyList .. '</div>'
else
-- Default numbered archive format
boxComponents = self:makeMessageBox() .. '\n' .. self:makeArchiveLinksWikitable()
end -- We're omitting the banner, so we should only make the links table.
elseif args.omit == 'banner' then
boxComponents = self:makeArchiveLinksWikitable()
-- We're omitting the archives, so we should only make the banner.
elseif args.omit == 'archives' then
boxComponents = self:makeMessageBox()
end

-- Allow for demo pages to be edited freely.
if not args.demospace then
boxComponents = boxComponents .. ' __NONEWSECTIONLINK__ __NOEDITSECTION__ __ARCHIVEDTALK__'
end

return boxComponents
end

-------------------------------------------------------------------------------
-- Exports
-------------------------------------------------------------------------------

local p = {}

function p._exportClasses()
return {
Navigator = Navigator
}
end

function p._aan(args, cfg, currentTitle)
cfg = cfg or mw.loadData('Module:Archive/config')
currentTitle = currentTitle or mw.title.getCurrentTitle()
local aan = Navigator.new(args, cfg, currentTitle)
return tostring(aan)
end

function p.aan(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Archive',
})
return p._aan(args)
end

return p

Latest revision as of 05:35, 11 February 2026