Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  



1.1  From wikitext  





1.2  From Lua  







2 Examples  














Module:Highest archive number






العربية
تۆرکجه


Dagbanli
فارسی
ि
Ilokano
Kurdî
Latviešu


Qaraqalpaqsha

سنڌي
کوردی
Српски / srpski
 

Türkçe
Українська
اردو
Tiếng Vit
 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
Meta-Wiki
Wikibooks
Wikiversity
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 


This module finds the highest archive number for a given set of numbered archive pages. The only input required is the prefix of the archive set. For example, for Talk:France/Archive 1, Talk:France/Archive 2, etc., the prefix would be "Talk:France/Archive ".

The module uses an exponential search algorithm, so it will make relatively few expensive function calls even for large numbers of archives. (The expensive function call is necessary to determine whether an individual archive exists.) For 1-10 archive pages, the module typically uses 4-6 expensive function calls; for 20-100 archives, it uses 6-12 calls; and for hundreds of archives, it uses 12-20 calls.

Because the module uses an exponential search, no gaps are allowed in the archive numbers; if there are any gaps, then the module may return the number of any archive page that exists where the following archive page does not exist. However, archive numbers do not have to start at 1; if they start at a higher number, you can specify this number in the start parameter.

Usage

From wikitext

From wikitext this module is usually used via the {{highest archive number}} template. However, it is also possible to use it directly from invoke with the syntax {{#invoke:highest archive number|main|prefix|start=start}}.

From Lua

Load the module with the following code:

local mHAN = require('Module:Highest archive number')

You can then use it like this:

mHAN._main(prefix, start)

The prefix variable is the prefix of the archive set.

Examples

#invoke code Lua code Result
{{#invoke:highest archive number|main|Wikipedia:Administrators' noticeboard/IncidentArchive}} mHAN._main("Wikipedia:Administrators' noticeboard/IncidentArchive") 1161
{{#invoke:highest archive number|main|Talk:Byzantine Empire/Archive }} mHAN._main("Talk:Byzantine Empire/Archive ") 16
{{#invoke:highest archive number|main|Wikipedia talk:WikiProject Chemicals/Archive |start=2005}} mHAN._main("Wikipedia talk:WikiProject Chemicals/Archive ", 2005) 2024

-- 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

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Highest_archive_number&oldid=920255204"

Category: 
Modules subject to page protection
Hidden category: 
Wikipedia template-protected modules
 



This page was last edited on 8 October 2019, at 15:47 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki