Module:Pagination: Difference between revisions
From Growtopia
Jump to navigationJump to search
>HashJona No edit summary |
>HashJona No edit summary |
||
| Line 83: | Line 83: | ||
-- rawValue = mw.ustring.gsub(rawValue, "^%s*(.-)%s*$", "%1") | -- rawValue = mw.ustring.gsub(rawValue, "^%s*(.-)%s*$", "%1") | ||
-- rawValue = mw.ustring.gsub(rawValue, "%z\194\160", "") -- or other patterns | -- rawValue = mw.ustring.gsub(rawValue, "%z\194\160", "") -- or other patterns | ||
local numeric = (mw.ustring.gsub( frame.args.total, "[^%d%.%-]+", "")) or 0 | |||
return "Debug: '" .. numeric .. "'" | |||
local numeric = (mw.ustring.gsub(args.total, "[^%d%.%-]+", "")) or 0 | |||
return "'" .. numeric .. "'" | |||
end | end | ||
return p | return p | ||
Revision as of 19:53, 8 March 2025
Documentation for this module may be created at Module:Pagination/doc
local p = {}
function p.pagination(frame)
local args = frame.args
local paramName = mw.text.trim(args.param) or "offset"
local offsetVal = tonumber(mw.text.trim(args.offset or "0")) or 0
local countVal = tonumber(mw.text.trim(args.count or "0")) or 0
local totalVal = tonumber(mw.text.trim(args.total or "0")) or 0
local debug = args.debug or "0"
local prevOffset = math.max(0, offsetVal - countVal)
local nextOffset = offsetVal + countVal
local lastOffset = 0
if countVal > 0 then
lastOffset = math.floor((totalVal - 1) / countVal) * countVal
if lastOffset < 0 then
lastOffset = 0
end
end
local out = {}
local function w(line) table.insert(out, line) end
if debug == "1" then
w('{| class="wikitable" style="margin:1em auto;"')
w('|-')
w('! colspan="2" | Debug Information')
w('|-')
w('| param')
w('| ' .. paramName .. ' <small>(default: offset)</small>')
w('|-')
w('| offset')
w('| ' .. offsetVal .. ' <small>(default: 0)</small>')
w('|-')
w('| count')
w('| ' .. countVal .. ' <small>(default: 0)</small>')
w('|-')
w('| total')
w('| ' .. totalVal .. ' <small>(default: 0)</small>')
w('|}')
end
w('<div class="category-page__pagination" style="display:flex; justify-content: space-between; width:100%">')
w('<div>')
if offsetVal > 0 then
local firstLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=0"
})
w(string.format('[%s <span class="wds-button wds-is-text">First</span>]', firstLink))
local prevLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=" .. prevOffset
})
w(string.format('[%s <span class="category-page__pagination-prev wds-button wds-is-secondary">< Previous</span>]', prevLink))
end
w('</div><div>')
if (offsetVal + countVal) < totalVal then
local nextLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=" .. nextOffset
})
w(string.format('[%s <span class="category-page__pagination-prev wds-button wds-is-secondary">Next ></span>]', nextLink))
local lastLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=" .. lastOffset
})
w(string.format('[%s <span class="wds-button wds-is-text">Last</span>]', lastLink))
end
w('</div></div>')
return table.concat(out, '\n')
end
function p.test(frame)
local args = frame.args
-- rawValue = mw.ustring.gsub(rawValue, "^%s*(.-)%s*$", "%1")
-- rawValue = mw.ustring.gsub(rawValue, "%z\194\160", "") -- or other patterns
local numeric = (mw.ustring.gsub( frame.args.total, "[^%d%.%-]+", "")) or 0
return "Debug: '" .. numeric .. "'"
end
return p