Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Qwerfjkl
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!
local p = {} -- Checks whether a page exists, going through pcall -- in case we are over the expensive function limit. local function checkPageExists( title ) if not title then error('No title passed to checkArchiveExists', 2) end local noError, titleObject = pcall(mw.title.new, title) if not noError then -- If we are over the expensive function limit then assume -- that the page doesn't exist. return false else if titleObject then return titleObject.exists else return false -- Return false if given a bad title. end end end -- Checks every nth archive to see if it exists, and returns the -- number of the first archive that doesn't exist. It is -- necessary to do this in batches because each check is an -- expensive function call, and we want to avoid making too many -- of them so as not to go over the expensive function limit. local function checkArchives( prefix, n, start ) local i = start local exists = true while exists do exists = checkPageExists( prefix .. tostring( i ) ) if exists then i = i + n end end return i end -- Return the biggest archive number, using checkArchives() -- and starting in intervals of 1000. This should get us a -- maximum of 500,000 possible archives before we hit the -- expensive function limit. local function getBiggestArchiveNum( prefix, start ) start = start or 1 local check1000 = checkArchives( prefix, 1000, start ) if check1000 == start then return 0 -- Return 0 if no archives were found. end local check200 = checkArchives( prefix, 200, check1000 - 1000 ) local check50 = checkArchives( prefix, 50, check200 - 200 ) local check10 = checkArchives( prefix, 10, check50 - 50 ) local check1 = checkArchives( prefix, 1, check10 - 10 ) return check1 end p.main = function (frame) return getBiggestArchiveNum('User:Qwerfjkl/sandbox/', 1) end return p
Summary:
Please note that all contributions to Stockhub 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
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Qwerfjkl/doc
(
edit
)