Jump to content

Module:User:Zackmann08/unknown links

From Wikipedia, the free encyclopedia

-- Module to display a list of unknown articles

	local templates = {
		'academic',
		'aircraft occurrence',
		'aircraft',
		'airport',
		'ancient site',
		'animanga',
		'architect',
		'art historian',
		'artist',
		'artwork',
		'astronaut',
		'aviator',
		'badminton player',
		'basketball league season',
		'Belgium municipality',
		'brewery',
		'bridge type',
		'bridge',
		'Buddhist temple',
		'building',
		'bus company',
		'casino',
		'cheese',
		'chef',
		'Christian leader',
		'church',
		'civilian attack',
		'classical composer',
		'clergy',
		'comedian',
		'company',
		'computing device',
		'country',
		'cricket ground',
		'criminal organization',
		'criminal',
		'cycling race report',
		'dam',
		'dancer',
		'desalination plant',
		'distillery',
		'dog breed',
		'drink',
		'economist',
		'economy',
		'election',
		'engineer',
		'F1 driver',
		'factory',
		'family',
		'FIBA tourney',
		'figure skater',
		'film',
		'fishery',
		'food',
		'forest',
		'French commune',
		'Gaelic games biography',
		'game',
		'glacier',
		'government cabinet',
		'gridiron football team season',
		'gymnast',
		'Hindu temple',
		'historic site',
		'hospital',
		'housing project',
		'hromada',
		'ice hockey biography',
		'institute',
		'international baseball tournament',
		'international football competition',
		'Italian comune',
		'laboratory',
		'landform',
		'legislative election',
		'legislature',
		'library',
		'lighthouse',
		'malware',
		'medical person',
		'military conflict',
		'military installation',
		'military person',
		'mill building',
		'mobile phone',
		'model',
		'monastery',
		'monument',
		'motorcycle',
		'mountain',
		'museum',
		'musical artist',
		'name',
		'newspaper',
		'NRHP',
		'noble',
		'officeholder',
		'official post',
		'organization',
		'pageant titleholder',
		'park',
		'person',
		'philosopher',
		'pirate',
		'poker player',
		'police officer',
		'presenter',
		'prison',
		'protected area',
		'racing driver',
		'recurring event',
		'religious biography',
		'religious building',
		'restaurant',
		'room',
		'royalty',
		'rugby biography',
		'rugby team',
		'rugby union tour',
		'Russian district',
		'Russian inhabited locality',
		'school',
		'scientist',
		'settlement',
		'shopping mall',
		'skier',
		'social media personality',
		'solar eclipse',
		'sports announcer',
		'sports season',
		'sports team',
		'sportsperson',
		'spy',
		'swimmer',
		'Switzerland municipality',
		'telescope',
		'theologian',
		'transmitter',
		'tunnel',
		'university',
		'urban development project',
		'venue',
		'weather event',
		'windmill',
		'WRC driver',
		'zoo'
	}

require('strict')

local p = {}

function p.getText(text)
	text = text:gsub("^%l", string.upper)
	text = text:gsub("^(%w+%s+%w*).*", "%1")
	return text
end

function p.getList(frame, templates)
	local text = {}
	for index = 1, #templates do
		local title = 'Pages using infobox '..templates[index]..' with unknown parameters'
		if not mw.title.new('Category:'..title).exists then
			table.insert(text, frame:expandTemplate{
				title='Error',
				args = {'[[:Category:'..title .. ']] is not a valid category'}
			})
		end
		if p.getSoloCount(frame, templates[index])>0 then
			table.insert(text, frame:expandTemplate{
				title='User:Zackmann08/cc',
				args = {'Pages using infobox '..templates[index]..' with unknown parameters', p.getText(templates[index])}
			})
		end
	end
	return text
end

function p.getSoloCount(frame, template)
	return tonumber(frame:expandTemplate{
			title='cconly',
			args = {'Pages using infobox '..template..' with unknown parameters'}
		})
end

function p.getCount(frame, templates)
	local count = 0
	for index = 1, #templates do
		count = count + p.getSoloCount(frame, templates[index])
	end
	return count
end
-- Main function

function p.conflicting(frame)
	local offset = frame.args[1] or 0
	local title = 'User:Zackmann08/conflicting.json'
	local data = mw.text.jsonDecode(mw.title.new(title):getContent())
	local array = data["*"][1]["a"]["*"]
	local text = ''
	local list = {}
	
	for i = 1+offset, math.min(1000+offset, #array) do
		local title = mw.ustring.gsub(array[i]["title"], '_', ' ')
		local count = mw.site.stats.pagesInCategory(title, 'pages')
		if  count > 100 then
			table.insert(list, '[[:Category:'..title..']] ('..count..')')
		end
	end
	
	text = 'Using [https://petscan.wmcloud.org/?psid=44764551 this query] on [[User:Zackmann08/conflicting.json]]<br>'
	text = text..'There are currently a total of '..table.getn(array)..' conflicting categories!<br>'
	text = text..'This page is displaying '..table.getn(list)..' of them.<br>'
	text = text..'Modify this template at [[Module:User:Zackmann08/unknown links]]<br>'
	return text..frame:expandTemplate{
	 	title='blist',
	 	args = list
	 }
end

function p.unknowns(frame)
	local offset = frame.args[1] or 0
	local title = 'User:Zackmann08/unknowns.json'
	local data = mw.text.jsonDecode(mw.title.new(title):getContent())
	local array = data["*"][1]["a"]["*"]
	local text = ''
	local list = {}
	
	for i = 1+offset, math.min(500+offset, #array) do
		local title = mw.ustring.gsub(array[i]["title"], '_', ' ')
		local count = mw.site.stats.pagesInCategory(title, 'pages')
		if  count > 50 then
			table.insert(list, '[[:Category:'..title..']] ('..count..')')
		end
	end
	
	text = 'Using [https://petscan.wmcloud.org/?psid=39322871 this query] on [[User:Zackmann08/unknowns.json]]<br>'
	text = text..'There are currently a total of '..table.getn(array)..' unknown categories!<br>'
	text = text..'This page is displaying '..table.getn(list)..' of them.<br>'
	text = text..'Modify this template at [[Module:User:Zackmann08/unknown links]]<br>'
	return text..frame:expandTemplate{
	 	title='blist',
	 	args = list
	 }
end

function p.main(frame)
	table.sort(templates)
	local text = ''
	local count = p.getCount(frame, templates)
	local list = p.getList(frame, templates)
	text = text .. frame:expandTemplate{
	 	title='blist',
	 	args = list
	 }
	return text
end
return p