FANDOM


-- <pre>
 
-- TODO:
-- add event categories
-- add skill categories
-- add minigame categories
 
local p = {}
 
local category_map = {
	-- Combat styles
	['Melee weapons'] = 'Melee weapon images',
	['Magic weapons'] = 'Magic weapon images',
	['Ranged weapons'] = 'Ranged weapon images',
	['Melee armour'] = 'Melee armour images',
	['Magic armour'] = 'Magic armour images',
	['Ranged armour'] = 'Ranged armour images',
	['Hybrid armour'] = 'Hybrid armour images',
	['Typeless armour'] = 'Typeless armour images',
	['Typeless weapons'] = 'Typeless weapon images',
 
	-- Standard metals
	['Adamant'] = 'Adamant item images',
	['Black'] = 'Black item images',
	['Blurite'] = 'Blurite item images',
	['Bronze'] = 'Bronze item images',
	['Dragon metal'] = 'Dragon item images',
	['Iron'] = 'Iron item images',
	['Mithril'] = 'Mithril item images',
	['Rune'] = 'Rune item images',
	['Steel'] = 'Steel item images',
	['White knight equipment'] = 'White item images',
 
	-- Dungeoneering metals
	['Argonite '] = 'Argonite item images',
	['Bathus '] = 'Bathus item images',
	['Fractite '] = 'Fractite item images',
	['Gorgonite '] = 'Gorgonite item images',
	['Katagon '] = 'Katagon item images',
	['Kratonite '] = 'Kratonite item images',
	['Marmaros '] = 'Marmaros item images',
	['Novite '] = 'Novite item images',
	['Primal '] = 'Primal item images',
	['Promethium '] = 'Promethium item images',
	['Zephyrium '] = 'Zephyrium item images',
 
	-- Dungeoneering leathers
	['Archleather '] = 'Archleather item images',
	['Dromoleather '] = 'Dromoleather item images',
	['Gallileather '] = 'Gallileather item images',
	['Megaleather '] = 'Megaleather item images',
	['Paraleather '] = 'Paraleather item images',
	['Protoleather '] = 'Protoleather item images',
	['Sagittarian '] = 'Sagittarian item images',
	['Spinoleather '] = 'Spinoleather item images',
	['Stegoleather '] = 'Stegoleather item images',
	['Subleather '] = 'Subleather item images',
	['Tyrannoleather '] = 'Tyrannoleather item images',
 
	-- Dungeoneering cloths
	['Blightleaf '] = 'Blightleaf item images',
	['Bryll '] = 'Bryll item images',
	['Celestial '] = 'Celestial item images',
	['Duskweed '] = 'Duskweed item images',
	['Ectograss '] = 'Ectograss item images',
	['Roseblood '] = 'Roseblood item images',
	['Runic '] = 'Runic item images',
	['Salve '] = 'Salve item images',
	['Soulbell '] = 'Soulbell item images',
	['Spiritbloom '] = 'Spiritbloom item images',
	['Wildercress '] = 'Wildercress item images',
 
	-- Slots
	['Body slot items'] = 'Body slot item images',
	['Cape slot items'] = 'Cape slot item images',
	['Feet slot items'] = 'Feet slot item images',
	['Hand slot items'] = 'Hand slot item images',
	['Head slot items'] = 'Head slot item images',
	['Legwear slot items'] = 'Legwear slot item images',
	['Neck slot items'] = 'Neck slot item images',
	['Ammunition slot items'] = 'Ammunition slot item images',
	['Off-hand slot items'] = 'Off-hand slot item images',
	['Off-hand slot weapons'] = 'Off-hand slot item images',
	['Rings'] = 'Ring slot item images',
	['Weapon slot items'] = 'Weapon slot item images',
	['Pocket slot items'] = 'Pocket slot item images',
	['Auras'] = 'Aura images',
 
	-- Misc
	['Vanity items'] = 'Vanity item images',
	['Quest items'] = 'Quest item images',
	['Potions'] = 'Potion images',
	['Keys'] = 'Key images',
	['Texts and tomes'] = 'Text and tome images',
	['Seeds'] = 'Seed images',
	['Food'] = 'Food images',
	['Herbs'] = 'Herb images',
	['Dungeoneering herbs'] = 'Herb images',
	['Dungeoneering items'] = 'Dungeoneering item images',
	['Urns'] = 'Urn images',
	['Item sets'] = 'Item set images',
	['Summoning scrolls'] = 'Summoning scroll images',
	['Summoning pouches'] = 'Summoning pouch images',
	['Sinkholes'] = 'Sinkhole images',
	['Flatpacks'] = 'Flatpack images',
	['Stealing Creation'] = 'Stealing Creation images',
	['Logs'] = 'Log images',
}
 
local directCategories = {
	'Potion flasks',
	'Unfinished potions',
	'Item shards',
	'Dyed equipment',
	'Boss pets',
	'Grinning idols',
	'Lamp of the Djinn',
	'Burnt food',
	'Treasure Trails rewards',
	'Experience lamps',
 
	-- errors
	'Licenses with a non-existent subject'
}
 
local formats = {
	list = '* [[:Category:%s|%s]]',
	names = '[[:Category:%s|%s]] ',
	default = '[[Category:%s]]'
}
 
local nilpage = 'random text that wont be a page'
function p.main(frame)
	-- arguments
	-- may need to rework later
	local args = frame:getParent().args
 
	local ttl = mw.title.new(args[1])
 
	if not ttl then
		return '[[Category:Licenses with a non-existent subject]]'
	end
 
	if ttl.isRedirect then
		ttl = frame:preprocess([==[{{safesubst:#dpl:
			|noresultsheader=[[:Category:Licenses with a non-existent subject|ERROR]]
			|namespace=
			|linksfrom=]==]..
				(args[1] or nilpage)..
			[==[
			|ignorecase=true
			|count=1
			|format=,%TITLE%
			}}]==])
	else
		ttl = args[1] or nilpage
	end
	-- get text of the categories to add
	local txt = frame:preprocess([==[{{safesubst:#dpl:
		|noresultsheader=[[:Category:Licenses with a non-existent subject|ERROR]]
		|namespace=
		|title=]==]..
			ttl..
		[==[
		|ignorecase=true
		|addcategories=true
		|count=1
		|format=,%CATLIST%
		}}]==])
 
	-- get desired format from user
	-- default to adding categories
	local frm = mw.text.trim(string.lower(args.format or ''))
	frm = formats[frm] or formats.default
 
	-- table of categories to add
	local tbl = {}
 
	-- for every category listed, find it and add to overall table
	for v in string.gmatch(txt,'%[%[:Category:(.-)%|') do
		local s = string.gsub(v,'_',' ')
		table.insert(tbl,s)
	end
 
	-- get a list of all quest categories
	local quests = frame:preprocess([==[{{safesubst:#dpl:
		|noresultsheader=
		|namespace=Category
		|category=Quest related entities
		|count=
		|format=,%TITLE%¦
		}}]==])
 
	-- trim whitespace
	quests = mw.text.trim(quests)
 
	-- delete unneeded delimiter
	quests = string.gsub(quests,'|$','')
 
	-- split into array
	quests = mw.text.split(quests,'|')
 
	local adddirect = {}
 
	-- set each quest name as a valid category
	for _, v in ipairs(quests) do
		adddirect[v] = true
	end
 
	-- set specified direct to add categories as valid
	for _, v in ipairs(directCategories) do
		adddirect[v] = true
	end
	-- return list
	local ret = {}
 
 
	for _, v in ipairs(tbl) do
		local cat_v = mw.text.trim(v)
		local catmapped = category_map[cat_v]
		-- map all categories to other categories
		if catmapped then
			table.insert(ret,string.format(frm,catmapped,catmapped))
		-- for everything that's in a directadd category, add that exact category
		elseif adddirect[cat_v] then
			table.insert(ret,string.format(frm,cat_v,cat_v))
		end
	end
 
	ret = table.concat(ret,'\n')
 
	return ret
end
 
function p.list(frame)
	local retList = {}
	for w, v in pairs(category_map) do
		table.insert(retList, { w, v })
	end
 
	for _, v in ipairs(directCategories) do
		table.insert(retList, { v, v })
	end
 
	-- get a list of all quest categories
	local quests = frame:preprocess([[{{safesubst:#dpl:
		|noresultsheader=
		|namespace=Category
		|category=Quest related entities
		|count=
		|format=,%TITLE%¦
		}}]])
 
	-- trim whitespace
	quests = mw.text.trim(quests)
 
	-- delete unneeded delimiter
	quests = string.gsub(quests,'|$','')
 
	-- split into array
	quests = mw.text.split(quests,'|')
 
	-- set each quest name as a valid category
	for _, v in ipairs(quests) do
		table.insert(retList, { v, v })
	end
 
    -- sort alphabetically
    table.sort(retList,
        function(a,b)
            local _a = string.lower(a[1])
            local _b = string.lower(b[1])
 
            -- remove articles at front
            _a = string.gsub(_a,'^the ',''):gsub('^an? ','')
            _b = string.gsub(_b,'^the ',''):gsub('^an? ','')
 
            return _a < _b
        end
        )
 
	local ret =
	mw.html.create('table')
		:css('border-collapse','collapse')
		:tag('tr')
			:css('border-bottom','3px solid #000')
			:tag('th')
				:css('border-bottom','inherit')
				:wikitext('Subject category')
			:done()
			:tag('th')
				:css('border-bottom','inherit')
			:done()
			:tag('th')
				:css('border-bottom','inherit')
				:wikitext('Image category')
			:done()
		:done()
 
	for _, v in ipairs(retList) do
		ret	:tag('tr')
				:css({ ['border-bottom'] = '1px dotted #999',
					background = (v[1] == v[2]) and '#C9FFD2' or '' })
				:tag('td')
					:css('border-bottom','inherit')
					:wikitext(string.format('[[:Category:%s|%s]]',v[1],v[1]))
				:done()
				:tag('td')
					:css('border-bottom','inherit')
					:tag('b')
						:wikitext('→')
					:done()
				:done()
				:tag('td')
					:css({ ['text-align'] = 'right',
						['border-bottom'] = 'inherit' })
					:wikitext(string.format('[[:Category:%s|%s]]',v[2],v[2]))
				:done()
			:done()
	end
 
	return ret
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.