Editing
Module:Highest archive number
From Thetacola Wiki
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- This module finds the highest existing archive number for a set of talk -- archive pages. local expSearch = require('Module:Exponential search') local p = {} local function raiseStartNumberError(start) error(string.format( 'Invalid start number "%s" supplied to [[Module:Highest archive number]] (must be an integer)', tostring(start) ), 3) end local function pageExists(page) local success, exists = pcall(function() return mw.title.new(page).exists end) return success and exists end function p._main(prefix, start) -- Check our inputs if type(prefix) ~= 'string' or not prefix:find('%S') then error('No prefix supplied to [[Module:Highest archive number]]', 2) end if start ~= nil and (type(start) ~= "number" or math.floor(start) ~= start) then raiseStartNumberError(start) end start = start or 1 -- Do an exponential search for the highest archive number local result = expSearch(function (i) local archiveNumber = i + start - 1 local page = prefix .. tostring(archiveNumber) return pageExists(page) end, 10) if result == nil then -- We didn't find any archives for our prefix + start number return nil else -- We found the highest archive, but the number is always 1-based, so -- adjust it for our start number return result + start - 1 end end function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { trim = false, removeBlanks = false, wrappers = 'Template:Highest archive number' }) local prefix = args[1] -- Get the start archive number, if specified. local start = args.start if start == "" then start = nil elseif start then start = tonumber(start) if not start then raiseStartNumberError(args.start) end end return p._main(prefix, start) end return p
Summary:
Please note that all contributions to Thetacola Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Code
(
edit
)
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Ombox
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Module:Arguments
(
edit
)
Module:Effective protection level
(
edit
)
Module:Exponential search
(
edit
)
Module:Highest archive number
(
edit
)
Module:Highest archive number/doc
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:Yesno
(
edit
)
Navigation menu
Page actions
Module
Discussion
Read
Edit source
History
Page actions
Module
Discussion
More
Tools
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Search
Tools
What links here
Related changes
Special pages
Page information