Modul:Pages with authority control identifiers

Saking Wikipédia

Dokuméntasi antuk modul puniki prasida kakardi ring Modul:Pages with authority control identifiers/doc

require('Module:No globals')

local p = {}
local ac_conf = require('Module:Authority control').conf
local rmCats = require('Module:Suppress categories').main
local currentTitle = mw.title.getCurrentTitle()
local title = currentTitle.text
local isCat = (currentTitle.namespace == 14)

--[[==========================================================================]]
--[[                         Local Utility Functions                          ]]
--[[==========================================================================]]

local function whichTOC( frame )
	--local pageCount = mw.site.stats.pagesInCategory(title, 'pages')
	--if pageCount > 1200 then
	--	return frame:expandTemplate{ title = 'Large category TOC' }
	--elseif pageCount > 100 then
	--	return frame:expandTemplate{ title = 'Category TOC', args = { align = 'center' } }
	--end
	--return ''
	
	-- standardize TOC behavior via {{CatAutoTOC}}
	return frame:expandTemplate{ title = 'CatAutoTOC', args = { align = 'center' } }
end

local function redCatCheck( catName ) --catName == 'Blah', not 'Category:Blah', not '[[Kategori:Blah]]'
	if catName and catName ~= '' and mw.title.new(catName, 14).exists == false then
		return '[[Kategori:Kaca sareng kategori pengawasan otoritas belum dibuat]]'
	end
	return ''
end
local function getExample(conf, id)
	if id == "WORLDCATID" then
		return "[https://www.worldcat.org/identities/lccn-n78039510 WorldCat]"
	else
		return rmCats(conf[3](conf[5]))
	end
end
--[[==========================================================================]]
--[[                    Local Category-Specific Functions                     ]]
--[[==========================================================================]]

--For indirect use on [[Kategori:<catType> with multiple identifiers]],
--   i.e. on [[Kategori:Wikipedia articles with multiple identifiers]]
local function multiple( frame, catType, pre, post )
	local txCatMore  = frame:expandTemplate{ title = 'Cat more', args = { 'Wikipédia:Pengawasan otoritas' } }
	local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
	local txWPCat    = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
	local txQ        = frame:expandTemplate{ title = 'Q', args = { 'Q7245' } }
	local txWdpl1    = frame:expandTemplate{ title = 'Wikidata property link', args = { 'P213' } }
	local txWdpl2    = frame:expandTemplate{ title = 'Wikidata property link', args = { 'P244' } }
	local txTOC      = whichTOC( frame )
	local ex = 'Conto, '..txQ..' madué ID ganda untuk '..txWdpl1..', '..txWdpl2..', dll.<br/>'
	local only = 'Kaca ring kategori niki seharusnya hanya ditambahkan melalui [[Modul:Authority control]].'
	if catType and catType == 'pages' then
		txEmptyCat = ''
		txWPCat = frame:expandTemplate{ title = 'Wikipedia category' }
		ex = ''
		only = ''
	end
	local outString = txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..ex..only
	return (pre or '')..outString..(post or '')
end

--For use in [[Kategori:Pages with authority control information]],
--   i.e. on [[Kategori:Pages with VIAF identifiers]]
local function pages( frame, id )
	if id == 'multiple' then
		local pagesCat = 'Kaca sareng informasi pengawasan otoritas'
		local pagesCatFull = '[[Kategori:'..pagesCat..']]'..redCatCheck(pagesCat)
		return multiple( frame, 'pages', '', pagesCatFull )
	end
	for _, conf in pairs( ac_conf ) do
		if conf.category == id or conf[1] == id then
			local linktarget = conf.link or conf[1] .. ' (identifier)'
			local wdpl = ':d:Property:P'..conf[2]
			local txCatMore = frame:expandTemplate{ title = 'Cat more', args = {'Wikipédia:Pengawasan otoritas', linktarget, wdpl} }
			local txWPCat   = frame:expandTemplate{ title = 'Wikipedia category' }
			local pagesCat  = 'Kaca sareng informasi pengawasan otoritas'
			local outString = txCatMore..txWPCat..'\n'..
							'[[Kategori:'..pagesCat..'|'..id..']]'..redCatCheck(pagesCat)
			return outString
		end
	end
	return ''
end

--For use in [[Kategori:Miscellaneous pages with authority control information]],
--   i.e. on [[Kategori:Miscellaneous pages with VIAF identifiers]]
local function misc( frame, id )
	if id == 'multiple' then
		local link = id
		local txCatExplain = frame:expandTemplate{ title = 'Category explanation', 
				args = { 'halaman, selain halaman pengguna utama atau artikel Wikipedia, yang menggunakan {{[[Templat:Authority control|Authority control]]}} dengan penanda '..link..'.' } }
		local idCat   = 'Kaca sareng penanda '..id..''
		local miscCat = 'Kaca sareng informasi pengawasan otoritas'
		local idCatFull   = '[[Kategori:'..idCat..']]'..redCatCheck(idCat)
		local miscCatFull = '[[Kategori:'..miscCat..'|'..id..']]'..redCatCheck(miscCat)
		return multiple( frame, 'misc', txCatExplain, idCatFull..miscCatFull )
	end
	for _, conf in pairs( ac_conf ) do
		if conf.category == id or conf[1] == id then
			local linktarget = conf.link or conf[1] .. ' (identifier)'
			local link = '[['..linktarget..'|'..conf[1]..']]'
			local example = ' Pengidentifikasi ' .. conf[1].. ' ditampilkan sebagai '..getExample(conf,id)..' dalam bagian '..conf[4]..'.'
			local wdpl = ':d:Property:P'..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. '..example } }
			local txCatMore  = frame:expandTemplate{ title = 'Cat more', args = {'Wikipédia:Pengawasan otoritas', wdpl} }
			local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat    = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = whichTOC( frame )
			local idCat = 'Kaca sareng penanda '..id..''
			local miscCat = 'Kaca sareng informasi pengawasan otoritas'
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..
							'Kaca ring kategori niki seharusnya hanya ditambahkan melalui [[Modul:Authority control]].'..
							'[[Kategori:'..idCat..']]'..redCatCheck(idCat)..
							'[[Kategori:'..miscCat..'|'..id..']]'..redCatCheck(miscCat)
			return outString
		end
	end
	return ''
end

--For use in [[Kategori:User pages with authority control information]],
--   i.e. on [[Kategori:User pages with VIAF identifiers]]
local function user( frame, id )
	if id == 'multiple' then
		local idCat   = 'Kaca sareng penanda '..id..''
		local userCat = 'Halaman pengguna dengan informasi pengawasan otoritas'
		local idCatFull   = '[[Kategori:'..idCat..']]'..redCatCheck(idCat)
		local userCatFull = '[[Kategori:'..userCat..'|'..id..']]'..redCatCheck(userCat)
		return multiple( frame, 'user', '', idCatFull..userCatFull )
	end
	for _, conf in pairs( ac_conf ) do
		if conf.category == id or conf[1] == id then
			local linktarget = conf.link or conf[1] .. ' (identifier)'			local wdpl = ':d:Property:P'..conf[2]
			local txCatMore  = frame:expandTemplate{ title = 'Cat more', args = {'Wikipédia:Pengawasan otoritas', linktarget, wdpl} }
			local txEmptyCat = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat    = frame:expandTemplate{ title = 'Wikipedia category', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC      = whichTOC( frame )
			local idCat   = 'Kaca sareng penanda '..id..''
			local userCat = 'Kaca pengguna sareng informasi pengawasan otoritas'
			local outString = txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..
							'Kaca ring kategori niki seharusnya hanya ditambahkan melalui [[Modul:Authority control]].'..
							'[[Kategori:'..idCat..']]'..redCatCheck(idCat)..
							'[[Kategori:'..userCat..'|'..id..']]'..redCatCheck(userCat)
			return outString
		end
	end
	return ''
end

--For use in [[Kategori:Wikipedia articles with authority control information]],
--   i.e. on [[Kategori:Wikipedia articles with VIAF identifiers]]
local function wp( frame, id )
	if id == 'multiple' then
		local link = id
		local txCatExplain = frame:expandTemplate{ title = 'Category explanation', args = {'Suratan sareng penanda '..link..'. Mohon jangan tambahkan [[Wikipédia:Kategorisasi|subkategori]] di sini'} }
		local idCat = 'Kaca sareng penanda '..id..''
		local wpCat = 'Suratan Wikipédia sareng informasi pengawasan otoritas'
		local idCatFull = '[[Kategori:'..idCat..']]'..redCatCheck(idCat)
		local wpCatFull = '[[Kategori:'..wpCat..'|'..id..']]'..redCatCheck(wpCat)
		return multiple( frame, 'wp', txCatExplain, idCatFull..wpCatFull )
	end
	for _, conf in pairs( ac_conf ) do
		if conf.category == id or conf[1] == id then
			local linktarget = conf.link or conf[1] .. ' (identifier)'			local link = '[['..linktarget..'|'..conf[1]..']]'
			local wdpl = ':d:Property:P'..conf[2]
			local example = '  ' .. conf[1].. ' ditampilkan sebagai '..getExample(conf, id)..' pada bagian '..conf[4]..'.'
			local txCatExplain = frame:expandTemplate{ title = 'Category explanation', args = {'Suratan sareng penanda '..link..'.'..example..' Mohon jangan tambahkan [[Wikipédia:Kategorisasi|subkategori]] di sini'} }
			local txCatMore    = frame:expandTemplate{ title = 'Cat more', args = {'Wikipédia:Pengawasan otoritas', wdpl} }
			local txEmptyCat   = frame:expandTemplate{ title = 'Possibly empty category' }
			local txWPCat      = frame:expandTemplate{ title = 'Katégori Wikipédia', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = whichTOC( frame )
			local idCat = 'Kaca sareng penanda '..id..''
			local wpCat = 'Suratan Wikipédia sareng informasi pengawasan otoritas'
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..
							'Kaca ring kategori niki seharusnya hanya  ditambahkan oleh [[Modul:Authority control]].'..
							'[[Kategori:'..idCat..']]'..redCatCheck(idCat)..
							'[[Kategori:'..wpCat..'|'..id..']]'..redCatCheck(wpCat)
			return outString
		end
	end
	return ''
end

--For use in [[Kategori:Wikipedia articles with faulty authority control information]],
--   i.e. on [[Kategori:Wikipedia articles with faulty VIAF identifiers]]
local function wpfaulty( frame, id )
	for _, conf in pairs( ac_conf ) do
		if conf.category == id or conf[1] == id then
			local linktarget = conf.link or conf[1] .. ' (identifier)'
			local wdpl = ':d:Property:P'..conf[2]
			local txCatMore  = frame:expandTemplate{ title = 'Cat more', args = {'Wikipédia:Pengawasan otoritas', linktarget, wdpl} }
			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 = whichTOC( frame )
			local idCat = 'Kaca sareng penanda '..id..''
			local wpfCat = 'Suratan Wikipédia sareng informasi pengawasan otoritas bermasalah'
			local outString = txCatMore..txEmptyCat..txWPCat..txDirtyCat..txTOC..'\n'..
							'Kaca ring kategori niki seharusnya hanya ditambahkan oleh [[Modul:Authority control]].'..
							'[[Kategori:'..idCat..']]'..redCatCheck(idCat)..
							'[[Kategori:'..wpfCat..'|'..id..']]'..redCatCheck(wpfCat)
			return outString
		end
	end
	return ''
end

--[[==========================================================================]]
--[[                            Main/External Call                            ]]
--[[==========================================================================]]
function p.autoDetect( frame )
	if isCat then
		local pagesID    = mw.ustring.match(title, 'Kaca sareng penanda ([%w%.%- ]+)')
		local miscID     = mw.ustring.match(title, 'Kaca sareng penanda ([%w%.%- ]+)')
		local userID     = mw.ustring.match(title, 'Halaman pengguna dengan penanda ([%w%.%- ]+)')
		local wpfaultyID = mw.ustring.match(title, 'Suratan Wikipédia sareng penanda ([%w%.%- ]+) bermasalah')
		local wpID       = mw.ustring.match(title, 'Suratan Wikipédia sareng penanda ([%w%.%- ]+)')
		
		if     pagesID    then return pages( frame, pagesID )
		elseif miscID     then return misc( frame, miscID )
		elseif userID     then return user( frame, userID )
		elseif wpfaultyID then return wpfaulty( frame, wpfaultyID ) --must be before wpID check, in case they both match
		elseif wpID       then return wp( frame, wpID )             --to keep the regex simple
		else   return '[[Kategori:Kaca sareng kategori pengawasan otoritas tidak diketahui]]'
		end
	end
	return ''
end

return p