Module:Archive list and Module:Archive list/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
Add leavefirstcellblank per edit request |
rv |
||
Line 1: | Line 1: | ||
⚫ | |||
-- This module implements {{archive list}} in Lua, and adds a few |
|||
-- new features. |
|||
⚫ | |||
-- integer. |
|||
local function processNumArg( num ) |
local function processNumArg( num ) |
||
if num then |
if num then |
||
Line 17: | Line 13: | ||
end |
end |
||
-- Checks whether a page exists, going through pcall |
-- Checks whether a page exists, going through pcall in case we are over the |
||
-- |
-- expensive function limit. |
||
local function checkPageExists( title ) |
local function checkPageExists( title ) |
||
if not title then |
if not title then |
||
Line 37: | Line 33: | ||
end |
end |
||
-- Checks every nth archive to see if it exists, and returns the |
-- 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 |
||
⚫ | |||
-- necessary to do this in batches because each check is an |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local function checkArchives( prefix, n, start ) |
local function checkArchives( prefix, n, start ) |
||
local i = start |
local i = start |
||
Line 54: | Line 49: | ||
end |
end |
||
-- Return the biggest archive number, using checkArchives() |
-- 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. |
||
-- expensive function limit. |
|||
local function getBiggestArchiveNum( prefix, start, max ) |
local function getBiggestArchiveNum( prefix, start, max ) |
||
-- Return the value for max if it is specified. |
-- Return the value for max if it is specified. |
||
Line 80: | Line 74: | ||
end |
end |
||
-- Get the archive link prefix (the title of the archive pages |
-- Get the archive link prefix (the title of the archive pages minus the number). |
||
-- minus the number). |
|||
local function getPrefix( root, prefix, prefixSpace ) |
local function getPrefix( root, prefix, prefixSpace ) |
||
local ret = root or mw.title.getCurrentTitle().prefixedText |
local ret = root or mw.title.getCurrentTitle().prefixedText |
||
Line 96: | Line 89: | ||
end |
end |
||
-- Get the number of archives to put on one line. Set to |
-- Get the number of archives to put on one line. Set to math.huge if there |
||
-- |
-- should be no line breaks. |
||
local function getLineNum( links, nobr, isLong ) |
local function getLineNum( links, nobr, isLong ) |
||
local linksToNum = tonumber( links ) |
local linksToNum = tonumber( links ) |
||
Line 128: | Line 121: | ||
-- Get the link prefix. |
-- Get the link prefix. |
||
local ret = '' |
local ret = '' |
||
if isLong==true then |
if isLong==true then -- Default of old template for long is 'Archive ' |
||
if type(prefix) == 'string' then |
if type(prefix) == 'string' then |
||
if prefix == 'none' then -- 'none' overrides to empty prefix |
if prefix == 'none' then -- 'none' overrides to empty prefix |
||
Line 141: | Line 134: | ||
ret = 'Archive ' |
ret = 'Archive ' |
||
end |
end |
||
else --type is not long |
else -- type is not long |
||
if type(prefix) == 'string' then |
if type(prefix) == 'string' then |
||
ret = prefix |
ret = prefix |
||
Line 254: | Line 247: | ||
end |
end |
||
end |
end |
||
if glargs.isLong == true then --Long version is a table |
if glargs.isLong == true then -- Long version is a table |
||
table.insert(ret, "</td></tr></table>") |
table.insert(ret, "</td></tr></table>") |
||
end |
end |
||
Line 265: | Line 258: | ||
return false |
return false |
||
elseif auto == 'long' then |
elseif auto == 'long' then |
||
return true |
|||
else |
else |
||
return false |
return false |
||
Line 296: | Line 289: | ||
end |
end |
||
-- A wrapper function to make getBiggestArchiveNum() available from |
-- A wrapper function to make getBiggestArchiveNum() available from #invoke. |
||
-- #invoke. |
|||
local function _count( args ) |
local function _count( args ) |
||
local prefix = getPrefix( args.root, args.prefix, args.prefixspace ) |
local prefix = getPrefix( args.root, args.prefix, args.prefixspace ) |
||
Line 321: | Line 313: | ||
end |
end |
||
-- Ignore blank values for parameters other than "links", |
-- Ignore blank values for parameters other than "links", which functions |
||
-- |
-- differently depending on whether it is blank or absent. |
||
-- blank or absent. |
|||
local args = {} |
local args = {} |
||
for k, v in pairs( origArgs ) do |
for k, v in pairs( origArgs ) do |