Automoderated users, Autopatrolled users, Bureaucrats, Comment administrators, Confirmed users, Moderators, Rollbackers, Administrators
213,518
edits
No edit summary |
Tag: Undo |
||
(34 intermediate revisions by 2 users not shown) | |||
Line 2:
local pageorder = {
}
local crowners = {
["trope"] = { "Animation", "Animated Films", "Anime", "Anime and Manga", "Board Games", "Comics", "Comic Books",
"Fan Works", "
"
"
"Opera", "Professional Wrestling", "Puppet Shows", "Radio", "Tabletop Games", "Tabletop RPGs",
"Television", "TV",
"Theatre", "Theater", "Toys",
"Webcomics", "Video Games", "Visual Art", "Visual Novels",
Line 30 ⟶ 32:
["creator"] = "Crowners"
}
-- localize functions
local insert = table.insert
local concat = table.concat
local find = string.find
local len = string.len
local sub = string.sub
local rep = string.rep
local listlevel = { '*', '**', '***', '****', '*****' }
function sp.menu ( frame )
-- create variant top level page variables
local mainpage = page;
if template == "index" then
template = "trope"
crowners["trope"] = {}
mainpage = ":" .. page
page = page:gsub("Category:", "", 1)
end
local pageslash = page..'/'
local tree = build_tree(page, subpage_list)
-- initialize result with Main link
local linkout = { '* [[' .. mainpage .. '|<span id="tm-main"></span>Main]]\n' }
local crownerout = { }
local otherout = { }
local missingout = { }
for _, subpage in ipairs(pageorder[template]) do
text = build_list( { [subpage] = tree[subpage] }, pageslash, 1 )
if text ~= '' then
insert(linkout, text)
else
insert(missingout, subpage)
tree[subpage] = nil
end
for _, subpage in ipairs(crowners[template]) do
text = build_list( { [subpage] = tree[subpage] }, pageslash, 2 )
if text ~= '' then
insert(crownerout, text)
else
insert(missingout, subpage)
end
tree[subpage] = nil
end
--deal with the leftover subpages
if next(tree) then
local ordered_keys = {}
for k in pairs(tree) do
insert(ordered_keys, k)
end
table.sort(ordered_keys)
for i = 1, #ordered_keys do
local subpage = ordered_keys[i]
text = build_list( { [subpage] = tree[subpage] }, pageslash, 2 )
if text ~= '' then
insert(otherout, text)
end
end
end
local jsdata = '<div id="tm-data" style="display:none" '
.. 'data-toplevelpage="' .. page .. '" '
.. 'data-wanted="' .. concat( missingout, "	" ) .. '" '
.. 'data-templatetype="' .. template .. '" '
.. '></div>'
local crowner_link = next(crownerout)
and '* [[#top|<span id="tm-' .. crownername[template].. '"></span>'..crownername[template]..']]\n'
or ''
local wikipedia_link = haswp
and "* [[wikipedia:" .. wppage .. '|<span id="tm-Wikipedia"></span>Wikipedia]]\n'
or ''
local all_sp_link = '* [[Special:PrefixIndex/' .. pageslash .. '|<span id="tm-Allothers"></span>All Subpages]]\n'
return concat(linkout)
.. crowner_link
.. concat(crownerout)
.. wikipedia_link
.. all_sp_link
.. concat(otherout)
.. '* <strong><span id="tm-New"></span>Create New</strong><ul id="tm-wantedpages"></ul>\n'
.. jsdata
end
function sp.tree ( frame )
local page = frame.args[1] or frame:callParserFunction('TOPLEVELPAGE')
local allsptxt = frame:callParserFunction('SUBPAGES', { page, sep = "|" })
local tree =
if page:match("^Category:") then page = ":"..page end
return "; [["..page.."]]\n" .. build_list( tree, page..'/', 1 )
end
function build_tree ( page, subpage_list )
local path_tree = { }
local pagelenoffset = len(page) + 2
for _, fullpath in ipairs(subpage_list) do
local path = sub(fullpath, pagelenoffset)
local list = split(path, '/')
local lastdir = path_tree
for i, dir in ipairs(list) do
if lastdir[dir] == nil then lastdir[dir] = { } end
lastdir = lastdir[dir]
end
end
return path_tree
end
function build_list ( tree, prefix, level )
local libase = listlevel[level] or rep('*', level)
local ul =
local ordered_sp = {}
for page in pairs(tree) do
insert(ordered_sp, page)
end
table.sort(ordered_sp)
for i = 1, #ordered_sp do
local page = ordered_sp[i]
local branch = tree[page]
local li
if level <= 2 then
li = libase .. " [["..prefix..page..'|<span id="tm-'..page..'"></span>'..page..']]\n'
else
li = libase ..' [['..prefix..page..'|'..page..']]\n'
end
insert(ul, li)
if next(branch) then
local nextprefix = (prefix..page..'/')
insert(ul, build_list(branch, nextprefix, level+1))
end
end
function split(str, sSeparator, nMax, bRegexp)
end
|