Modulo:Avviso archivio
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Avviso archivio/man (modifica · cronologia)
Sandbox: Modulo:Avviso archivio/sandbox · Sottopagine: lista · Test: Modulo:Avviso archivio/test
Modulo a supporto del template {{Avviso archivio}}.
--[[
* Modulo a supporto del template Avviso archivio.
]]--
require('strict')
local getArgs = require('Modulo:Arguments').getArgs
-- =============================================================================
-- classe TitleBuilder
-- =============================================================================
local TitleBuilder = {
currTitle = mw.title.getCurrentTitle(),
existingBasePageTitle = nil,
splitTitle = nil
}
function TitleBuilder:new()
local self = {}
local lazyFields = {
existingBasePageTitle = TitleBuilder.getExistingBasePageTitle,
splitTitle = TitleBuilder.getSplitTitle
}
setmetatable(self, {
__index = function (t, key)
if lazyFields[key] then
return lazyFields[key](self)
else
return TitleBuilder[key]
end
end
})
self.number = nil
self.subpageText = nil
return self
end
function TitleBuilder:getExistingBasePageTitle()
local basePageTitle = self.currTitle.basePageTitle
while TitleBuilder.existingBasePageTitle == nil do
if basePageTitle and basePageTitle.exists then
TitleBuilder.existingBasePageTitle = basePageTitle
elseif not basePageTitle or basePageTitle == basePageTitle.basePageTitle then
TitleBuilder.existingBasePageTitle = self.currTitle
else
basePageTitle = basePageTitle.basePageTitle
end
end
return TitleBuilder.existingBasePageTitle
end
function TitleBuilder:getSplitTitle()
if TitleBuilder.splitTitle == nil then
local pre, post = self.currTitle.prefixedText:match('^(.-)(%d+)$')
TitleBuilder.splitTitle = { pre = pre, post = post }
end
return TitleBuilder.splitTitle
end
function TitleBuilder:setSubpageText(subpageText)
self.subpageText = subpageText
return self
end
function TitleBuilder:setNumber(distance)
if self.splitTitle.post then
local currNumber = tonumber(self.splitTitle.post)
if currNumber + distance >= 1 then
self.number = currNumber + distance
end
end
return self
end
function TitleBuilder:build()
local title
if self.subpageText then
title = self.existingBasePageTitle:subPageTitle(self.subpageText)
else
local titleTexts = {}
if self.number and self.splitTitle.pre and self.splitTitle.post then
local newPost = tostring(self.number)
local pad0 = string.rep('0', #self.splitTitle.post - #newPost)
table.insert(titleTexts, self.splitTitle.pre .. pad0 .. newPost)
table.insert(titleTexts, self.splitTitle.pre .. newPost)
end
for _, titleText in ipairs(titleTexts) do
local possibleTitle = mw.title.new(titleText)
if possibleTitle.exists then
title = possibleTitle
break
end
end
end
if title then
local wlLabel
if #title.text > #self.existingBasePageTitle.text + 1 then
wlLabel = title.text:sub(#self.existingBasePageTitle.text + 2)
else
wlLabel = title.subpageText
end
local customTitleFields = {
wikilink = string.format('[[%s|%s]]', title.prefixedText, wlLabel)
}
return setmetatable(customTitleFields, { __index = title })
end
end
-- =============================================================================
-- Funzioni esportate
-- =============================================================================
local p = {}
-- Genera i link di navigazione tra le pagine di archiviazione
function p.navlinks(frame)
local args = getArgs(frame, { parentOnly = true })
local noRedLinks = args.noredlinks == 'y'
local wikilinks = {}
local wikilinkConf = {
{ subpageText = args.prima, distance = -1 },
{ subpageText = args.dopo, distance = 1 }
}
for i, item in ipairs(wikilinkConf) do
local titleBuilder = TitleBuilder:new()
if item.subpageText then
titleBuilder:setSubpageText(item.subpageText)
else
titleBuilder:setNumber(item.distance)
end
local title = titleBuilder:build()
if title and (noRedLinks == false or title.exists) then
wikilinks[i] = title.wikilink
end
end
if next(wikilinks) then
local div = mw.html.create('div')
div
:css('margin', 'auto')
:css('min-width', '20em')
:css('width', 'fit-content')
:wikitext(frame:expandTemplate{
title = 'Precedente e successivo',
args = wikilinks
})
return tostring(div)
end
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.