Module:Large category TOC: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
function p.make(frame) | function p.make(frame) | ||
-- It should be much faster to only process these once, and just re use them as variables | |||
local pageurl = frame:preprocess('{{fullurl:{{FULLPAGENAME}}}}') | local pageurl = frame:preprocess('{{fullurl:{{FULLPAGENAME}}}}') | ||
local toc = frame:preprocess('{{MediaWiki:Toc}}') | local toc = frame:preprocess('{{MediaWiki:Toc}}') | ||
-- Begins the "title" parameter of {{Navigation bar}} with Top of the category (no ?from) and numerals (?from=0) | |||
local title = '<div style="width:100%;">\n<span class="plainlinks">'..toc..':\n['..pageurl..' Top]'.. | local title = '<div style="width:100%;">\n<span class="plainlinks">'..toc..':\n['..pageurl..' Top]'.. | ||
'\n['..pageurl..'?from=0 0-9]' | '\n['..pageurl..'?from=0 0-9]' | ||
-- Add ?from=A through Z to the title bar | |||
for i=1,26,1 do | for i=1,26,1 do | ||
local letter = string.sub(azupper,i,i) | local letter = string.sub(azupper,i,i) | ||
title = title..'\n['..pageurl..'?from='..letter..' '..letter..']' | title = title..'\n['..pageurl..'?from='..letter..' '..letter..']' | ||
end | end | ||
-- Closing tags | |||
title = title..'\n</span>\n</div>' | title = title..'\n</span>\n</div>' | ||
-- Begin the list parameter with ?from=* | |||
local list = '<div style="overflow-x:auto; overflow-y:hidden; width:98%;"><span class="plainlinks">'.. | local list = '<div style="overflow-x:auto; overflow-y:hidden; width:98%;"><span class="plainlinks">'.. | ||
'\n['..pageurl..'?from=* *] •' | '\n['..pageurl..'?from=* *] •' | ||
-- Function to handle all 500+ ?from=Aa-z parameters with a simple loop | |||
local function atoz(letter) | local function atoz(letter) | ||
local azlist = '\n• <b>'..letter..'</b> ' | local azlist = '\n• <b>'..letter..'</b> ' | ||
| Line 31: | Line 33: | ||
return azlist | return azlist | ||
end | end | ||
-- Add ?from=0 through 9 to the list | |||
for i=0,9,1 do | for i=0,9,1 do | ||
list = list..'\n['..pageurl..'?from='..i..' '..i..']' | list = list..'\n['..pageurl..'?from='..i..' '..i..']' | ||
end | end | ||
-- A-Z loop that calls the a-z function | |||
for i=1,26,1 do | for i=1,26,1 do | ||
local letter = string.sub(azupper,i,i) | local letter = string.sub(azupper,i,i) | ||
list = list..atoz(letter) | list = list..atoz(letter) | ||
end | end | ||
-- Close tags | |||
list = list..'\n</span></div>' | list = list..'\n</span></div>' | ||
Revision as of 18:09, 1 July 2014
Documentation for this module may be created at Module:Large category TOC/doc
-- Implements [[Template:Large Category TOC]]
local p = {}
local azupper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
local azlower = 'abcdefghijklmnopqrstuvwxyz'
function p.make(frame)
-- It should be much faster to only process these once, and just re use them as variables
local pageurl = frame:preprocess('{{fullurl:{{FULLPAGENAME}}}}')
local toc = frame:preprocess('{{MediaWiki:Toc}}')
-- Begins the "title" parameter of {{Navigation bar}} with Top of the category (no ?from) and numerals (?from=0)
local title = '<div style="width:100%;">\n<span class="plainlinks">'..toc..':\n['..pageurl..' Top]'..
'\n['..pageurl..'?from=0 0-9]'
-- Add ?from=A through Z to the title bar
for i=1,26,1 do
local letter = string.sub(azupper,i,i)
title = title..'\n['..pageurl..'?from='..letter..' '..letter..']'
end
-- Closing tags
title = title..'\n</span>\n</div>'
-- Begin the list parameter with ?from=*
local list = '<div style="overflow-x:auto; overflow-y:hidden; width:98%;"><span class="plainlinks">'..
'\n['..pageurl..'?from=* *] •'
-- Function to handle all 500+ ?from=Aa-z parameters with a simple loop
local function atoz(letter)
local azlist = '\n• <b>'..letter..'</b> '
for i=1,26,1 do
local lowerletter = string.sub(azlower,i,i)
azlist = azlist..'\n['..pageurl..'?from='..letter..lowerletter..' '..letter..lowerletter..'] '
end
return azlist
end
-- Add ?from=0 through 9 to the list
for i=0,9,1 do
list = list..'\n['..pageurl..'?from='..i..' '..i..']'
end
-- A-Z loop that calls the a-z function
for i=1,26,1 do
local letter = string.sub(azupper,i,i)
list = list..atoz(letter)
end
-- Close tags
list = list..'\n</span></div>'
return frame:expandTemplate{title='Navigation bar',args={color='#f9f9f9;',title=title,list=list}}
end
return p