Модул:AutomaticArchiveNavigator — разлика између измена
Пређи на навигацију
Пређи на претрагу
Документација модула
(+) |
м (1 измена увезена) |
||
| (Нису приказане 2 међуизмене 2 корисника) | |||
| Ред 1: | Ред 1: | ||
-- | -- | ||
-- This module | -- This module implements {{Automatic archive navigator}} | ||
-- | |||
local p = {} | |||
local args | |||
local frame | |||
local thisPage | |||
-- | |||
local | |||
function | -- Get a formatted link to the subpage a certain distance away, or nil | ||
-- if that subpage does not exist. e.g. If the current subpage is | |||
-- /Archive 27, then getSubpageLink(3) returns a link to Archive 30. | |||
local function getSubpageLink(offset) | |||
local subpageName | |||
local startIdx, endIdx, archiveNum = mw.ustring.find(thisPage.subpageText, '^Archive ([0-9]+)') | |||
if archiveNum then | |||
subpageName = 'Archive ' .. (archiveNum + offset) | |||
elseif tonumber(thisPage.subpageText) then | |||
subpageName = thisPage.subpageText + offset | |||
else | |||
return nil -- Couldn't parse out a subpage number | |||
end | |||
local page = mw.title.new(thisPage.baseText .. '/' .. subpageName, thisPage.namespace) | |||
if page.exists then | |||
return '[[../' .. subpageName .. '|' .. subpageName .. ']]' | |||
else | |||
return nil | |||
end | |||
end | end | ||
function | 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 .. '|' .. thisPage.subpageText .. ']]</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 | end | ||
function | local function getMessage() | ||
if args[1] == '1' then | |||
return '' | |||
else | |||
local msg = '----\n' | |||
if args.text then | |||
msg = msg .. args.text | |||
else | |||
msg = msg .. "Ова страна је '''[[Help:Archiving a talk page|архива]]''' ранијих расправа" | |||
if args.period then | |||
msg = msg .. " for the period '''" .. args.period .. "'''" | |||
end | |||
msg = msg .. ". '''Не мењајте садржај ове странице.''' Ако желите да покренете нову расправу или оживите стару урадите то на " | |||
msg = msg .. "[[" .. thisPage.rootPageTitle.fullText .. "|актуелној страници за разговор]]." | |||
end | |||
return msg | |||
end | |||
end | end | ||
function | 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 | 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 | end | ||
return p | return p | ||
Тренутна верзија на датум 5. фебруар 2021. у 13:49
| Овај Луа модул се користи на > 800 страница, тако да ће промене на њему бити широко примећене. Молимо да било какве измене тестирате на подстраницама модула /песак или /тестови. Размислите и о постављању расправе о променама које намеравате да унесете на страници за разговор пре њиховог примењивања. |
--
-- This module implements {{Automatic archive navigator}}
--
local p = {}
local args
local frame
local thisPage
-- Get a formatted link to the subpage a certain distance away, or nil
-- if that subpage does not exist. e.g. If the current subpage is
-- /Archive 27, then getSubpageLink(3) returns a link to Archive 30.
local function getSubpageLink(offset)
local subpageName
local startIdx, endIdx, archiveNum = mw.ustring.find(thisPage.subpageText, '^Archive ([0-9]+)')
if archiveNum then
subpageName = 'Archive ' .. (archiveNum + offset)
elseif tonumber(thisPage.subpageText) then
subpageName = thisPage.subpageText + offset
else
return nil -- Couldn't parse out a subpage number
end
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 .. '|' .. thisPage.subpageText .. ']]</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 .. "Ова страна је '''[[Help:Archiving a talk page|архива]]''' ранијих расправа"
if args.period then
msg = msg .. " for the period '''" .. args.period .. "'''"
end
msg = msg .. ". '''Не мењајте садржај ове странице.''' Ако желите да покренете нову расправу или оживите стару урадите то на "
msg = msg .. "[[" .. thisPage.rootPageTitle.fullText .. "|актуелној страници за разговор]]."
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