🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/Module:User:Zackmann08/unknown_links
Jump to content

Module:User:Zackmann08/unknown links

From Wikipedia, the free encyclopedia
-- Module to display a list of unknown articles

	local templates = {
		 'aircraft',
		 'ancient site',
		 'animanga',
		 'badminton event',
		 'basketball league season',
		 'Belgium municipality',
		 'building',
		 'bus company',
		 'cheese',
		 'chef',
		 'church',
		 'college sports team season',
		 'company',
		 'country',
		 'cricket ground',
		 'criminal',
		 'cycling race report',
		 'dog breed',
		 'drink',
		 'economy',
		 'election',
		 'family',
		 'FIBA tourney',
		 'figure skater',
		 'football club',
		 'football club season',
		 'football league season',
		 'French commune',
		 'Gaelic games biography',
		 'government cabinet',
		 'Grand Lodge',
		 'hromada',
		 'ice hockey biography',
		 'international baseball tournament',
		 'international football competition',
		 'Italian comune',
		 'landform',
		 'legislative election',
		 'library',
		 'military person',
		 'military conflict',
		 'mobile phone',
		 'motorcycle',
		 'musical artist',
		 'newspaper',
		 'noble',
		 'officeholder',
		 'official post',
		 'organization',
		 'performing arts company',
		 'person',
		 'philosopher',
		 'protected area',
		 'radio show',
		 'recurring event',
		 'religious biography',
		 'restaurant',
		 'royalty',
		 'rugby team',
		 'rugby biography',
		 'rugby union tour',
		 'Russian inhabited locality',
		 'Russian district',
		 'school',
		 'settlement',
		 'skier',
		 'social media personality',
		 'sportsperson',
		 'sports season',
		 'swimmer',
		 'Switzerland municipality',
		 'university',
		 'venue',
		 'winery',
		 '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.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 > 100 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)
	mw.log(mw.site.stats.pagesInCategory( 'Convert errors', 'pages' ))
	table.sort(templates)
	local text = ''
	local count = p.getCount(frame, templates)
	local list = p.getList(frame, templates)
	local color = 'lightgray'
	local collapsed = ''
	if count>0 then 
		color = 'red' 
		collapsed = 'no'
	end
	-- text = text .. frame:expandTemplate{title='collapse top', args =
	-- 	{ title = 'Should be empty', bg = color, expand = collapsed }
	-- }
	-- text = text .. '\n'
	text = text .. frame:expandTemplate{
	 	title='blist',
	 	args = list
	 }
	-- text = text .. '\n'
	-- text = text .. frame:expandTemplate{title='collapse bottom', args = {}}
	return text
end
return p