Modulo:Pampanid nga agraman kadagiti panangilasin ti kontrol ti autoridad/pagipadasan

Manipud iti Wikipedia, ti nawaya nga ensiklopedia
Dokumentasion ti modulo

Panagusar[urnosen ti taudan]

{{#invoke:Pampanid nga agraman kadagiti panangilasin ti kontrol ti autoridad|autoDetect}}

Kitaen pay[urnosen ti taudan]

Dagiti pagssurotan a kategoria[urnosen ti taudan]

require('strict')
local p = {}
local ac_conf = require('Modulo:Kontrol ti autoridad').conf
local rmCats = require('Modulo:Lapdan ti katkategoria').main
local currentTitle = mw.title.getCurrentTitle()
local title = currentTitle.text

-- Local Utility Functions
local function whichTOC( frame )
	-- standardize TOC behavior via {{CatAutoTOC}}
	return frame:expandTemplate{ title = 'CatAutoTOC', args = { align = 'center' } }
end

local function redCatCheck( cat ) --cat == 'Blah' (not 'Category:Blah', '[[Category:Blah]]', etc.)
	if cat and cat ~= '' and mw.title.new(cat, 14).exists == false then
		return '[[Kategoria:Pampanid nga agraman kadagiti nasilpuan iti nalabbasit a kategoria ti kontrol ti autoridad]]'
	end
	return ''
end

local function addCat( cat, id )
	if id and id ~= '' then
		return '[[Kategoria:'..cat..'|'..id..']]'..redCatCheck(cat)
	else
		return '[[Kategoria:'..cat..']]'..redCatCheck(cat)
	end
end

--For use in [[Category:Articles with authority control information]], i.e. on [[Category:Articles with VIAF identifiers]]
local function wp( 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]..' (panangilasin)'
			local link    = '[['..linktarget..'|'..conf[1]..']]'
			local wdpl    = ':d:Property:P'..conf[2]
			local example = 'Agparang ti panangilasin ti '.. conf[1]..' a kas '..rmCats(conf[3](conf[5]))..' iti seksion ti '..conf[4]..'.'
			local txCatExplain = frame:expandTemplate{ title = 'Palawag ti kategoria', args = {'kadagiti artikulo nga agraman kadagiti panangilasin ti '..link..'. '..example..' Pangngaasi a saan nga agnayon kadagiti [[:en:Wikipedia:Categorization#Subcategorization|subkategoria]].'} }
			local txCatMore    = frame:expandTemplate{ title = 'Kat adu pay', args = {'Wikipedia:Kontrol ti autoridad', wdpl} }
			local txEmptyCat   = frame:expandTemplate{ title = 'Mabalin nga awan linaon a kategoria' }
			local txWPCat      = frame:expandTemplate{ title = 'Kategoria ti Wikipedia', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = whichTOC( frame )
			local wpCat = 'Dagiti artikulo nga agraman kadagiti pakaammo ti kontrol ti autoridad'
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..'Dagiti panid iti daytoy a kategoria ket nasken laeng koma nga inayon babaen ti [[Modulo:Kontrol ti autoridad]].'..addCat(wpCat, id)
			return outString
		end
	end
	return ''
end

--For use in [[Category:Articles with faulty authority control information]], i.e. on [[Category: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]..' (panangilasin)'
			local wdpl       = ':d:Property:P'..conf[2]
			local txCatMore  = frame:expandTemplate{ title = 'Kat adu pay', args = {'Wikipedia:Kontrol ti autoridad', linktarget, wdpl} }
			local txEmptyCat = frame:expandTemplate{ title = 'Mabalin nga awan linaon a kategoria' }
			local txWPCat    = frame:expandTemplate{ title = 'Kategoria ti Wikipedia', args = { hidden = 'yes', tracking = 'yes' } }
			local txDirtyCat = frame:expandTemplate{ title = 'Polluted category' }
			local txTOC = whichTOC( frame )
			local idCat = 'Dagiti artikulo nga agraman kadagiti panangilasin ti '..id..' '
			local wpfCat = 'Dagiti artikulo nga agraman kadagiti naperdi a panangilasin ti kontrol ti autoridad'
			local outString = txCatMore..txEmptyCat..txWPCat..txDirtyCat..txTOC..'\n'..
							'Dagiti panid iti daytoy a kategoria ket nasken laeng koma nga inayon babaen ti [[Modulo:Kontrol ti autoridad]].'..
							addCat(idCat)..addCat(wpfCat, id)
			return outString
		end
	end
	return ''
end

-- Main/External Call
function p.autoDetect( frame )
	if currentTitle.namespace == 14 then --cat space
		local wpfaultyID = mw.ustring.match(title, 'Dagiti artikulo nga agraman kadagiti naperdi a panangilasin ti ([%w%.%- ]+)')
		local wpID       = mw.ustring.match(title, 'Dagiti artikulo nga agraman kadagiti panangilasin ti ([%w%.%- ]+)')
		if 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 '[[Kategoria:Pampanid nga agraman kadagiti panangilasin ti kontrol ti autoridad ti di ammo a kategoria]]'
		end
	end
	return ''
end

return p