Jump to content

Module:Pages with authority control identifiers

Wikipedia se
Badlao 22:29, 18 Juun 2018 tak en>Tom.Reding (+local function wpfaulty) se

Usage

{{#invoke:Pages with authority control identifiers|autoDetect}}

See also

Tracking categories



require('Module:No globals')

local p = {}
local ac = require('Module:Authority control')
local currentTitle = mw.title.getCurrentTitle()
local title = currentTitle.text
local isCat = (currentTitle.namespace == 14)

local function pages( frame, id ) --i.e. on [[Category:Pages with VIAF identifiers]]
	for _, conf in pairs( ac.conf ) do
		if conf[1] == id then
			local link = conf[2] --not used locally yet
			local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control'} }
			local txWPCat = frame:expandTemplate{ title = 'Wikipedia category' }
			local outString = txCatMore..txWPCat..'\n'..
					'[[Category:Pages with authority control information|'..id..']]'
			return outString
		end
	end
	return ''
end

local function misc( frame, id ) --i.e. on [[Category:Miscellaneous pages with VIAF identifiers]]
	for _, conf in pairs( ac.conf ) do
		if conf[1] == id then
			local link = conf[2]
			local txCatExplain = frame:expandTemplate{ title = 'Category explanation', 
					args = { 'pages, other than main user pages or Wikipedia articles, using {{[[Template:Authority control|Authority control]]}} with '..link..' identifiers.' } }
			local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control'} }
			local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = ''
			local pageCount = mw.site.stats.pagesInCategory(title, 'pages')
			if pageCount >= 5000 then
				txTOC = frame:expandTemplate{ title = 'Large category TOC' }
			elseif pageCount > 400 then
				txTOC = frame:expandTemplate{ title = 'Category TOC', args = { align = 'center' } }
			end
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..
					'Pages in this category should only be added by [[Module:Authority control]].'..
					'[[Category:Pages with '..id..' identifiers]]'..
					'[[Category:Miscellaneous pages with authority control information|'..id..']]'
			return outString
		end
	end
	return ''
end

local function user( frame, id ) --i.e. on [[Category:User pages with VIAF identifiers]]
	for _, conf in pairs( ac.conf ) do
		if conf[1] == id then
			local link = conf[2] --not used locally yet
			local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control'} }
			local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = ''
			local pageCount = mw.site.stats.pagesInCategory(title, 'pages')
			if pageCount >= 5000 then
				txTOC = frame:expandTemplate{ title = 'Large category TOC' }
			elseif pageCount > 400 then
				txTOC = frame:expandTemplate{ title = 'Category TOC', args = { align = 'center' } }
			end
			local outString = txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..
					'Pages in this category should only be added by [[Module:Authority control]].'..
					'[[Category:Pages with '..id..' identifiers]]'..
					'[[Category:User pages with authority control information|'..id..']]'
			return outString
		end
	end
	return ''
end

local function wp( frame, id ) --i.e. on [[Category:Wikipedia articles with VIAF identifiers]]
	for _, conf in pairs( ac.conf ) do
		if conf[1] == id then
			local link = conf[2]
			local txCatExplain = frame:expandTemplate{ title = 'Category explanation', args = {'articles with '..link..' identifiers. Please do not add [[Wikipedia:Categorization#Subcategorization|subcategories]].'} }
			local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control'} }
			local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = ''
			local pageCount = mw.site.stats.pagesInCategory(title, 'pages')
			if pageCount >= 5000 then
				txTOC = frame:expandTemplate{ title = 'Large category TOC' }
			elseif pageCount > 400 then
				txTOC = frame:expandTemplate{ title = 'Category TOC', args = { align = 'center' } }
			end
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..
					'Pages in this category should only be added by [[Module:Authority control]].'..
					'[[Category:Pages with '..id..' identifiers]]'..
					'[[Category:Wikipedia articles with authority control information|'..id..']]'
			return outString
		end
	end
	return ''
end

local function wpfaulty( frame, id ) --i.e. on [[Category:Wikipedia articles with faulty authority control identifiers (VIAF)]]
	for _, conf in pairs( ac.conf ) do
		if conf[1] == id then
			local link = conf[2] --not used locally yet
			local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Authority control'} }
			local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
			local txDirtyCat = frame:expandTemplate{ title = 'Polluted category' }
			local txTOC = ''
			local pageCount = mw.site.stats.pagesInCategory(title, 'pages')
			if pageCount >= 5000 then
				txTOC = frame:expandTemplate{ title = 'Large category TOC' }
			elseif pageCount > 400 then
				txTOC = frame:expandTemplate{ title = 'Category TOC', args = { align = 'center' } }
			end
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txDirtyCat..txTOC..'\n'..
					'Pages in this category should only be added by [[Module:Authority control]].'..
					'[[Category:Wikipedia articles with faulty authority control information]]'
			return outString
		end
	end
	return ''
end

function p.autoDetect( frame )
	if isCat then
		local pagesID    = mw.ustring.match(title, 'Pages with ([%w%.%-]+) identifiers')
		local miscID     = mw.ustring.match(title, 'Miscellaneous pages with ([%w%.%-]+) identifiers')
		local userID     = mw.ustring.match(title, 'User pages with ([%w%.%-]+) identifiers')
		local wpID       = mw.ustring.match(title, 'Wikipedia articles with ([%w%.%-]+) identifiers')
		local wpfaultyID = mw.ustring.match(title, 'Wikipedia articles with faulty authority control identifiers %(([%w%.%-]+)%)')

		if     pagesID    then return pages( frame, pagesID )
		elseif miscID     then return misc( frame, miscID )
		elseif userID     then return user( frame, userID )
		elseif wpID       then return wp( frame, wpID )
		elseif wpfaultyID then return wpfaulty( frame, wpfaultyID )
		end
	end
	return ''
end

return p