Modul:Halaman dengan pengenalan kawalan kewibawaan

Pendokumenan untuk modul ini boleh diciptakan di Modul:Halaman dengan pengenalan kawalan kewibawaan/doc

require('strict')
local p = {}
local ac_conf = require('Module:Authority control/config').config
local rmCats = require('Module:Suppress categories').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 '[[Kategori:Halaman dengan kategori kawalan kewibawaan berpautan merah]]'
	end
	return ''
end

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

--For use in [[Kategori: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.idlink or conf[1]..' (identifier)'
			local link    = '[['..linktarget..'|'..conf[1]..']]'
			local wdpl    = ':d:Property:P'..conf.property
			--local example = 'The '..conf[1]..' identifier appears as '.. rmCats(conf[3](conf[5]))..' in the '..conf[4]..' section.'
			local txCatExplain = frame:expandTemplate{ title = 'Category explanation', args = {'rencana dengan pengenalan '..link..'.'..' Harap tidak menambah [[Wikipedia:Kategori|subkategori]].'} }
			local txCatMore    = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Kawalan kewibawaan', wdpl} }
			local txEmptyCat   = frame:expandTemplate{ title = 'Kategori mungkin kosong' }
			local txWPCat      = frame:expandTemplate{ title = 'Kategori Wikipedia', args = { hidden = 'yes', tracking = 'yes' } }
			local txTOC = whichTOC( frame )
			local wpCat = 'Rencana dengan maklumat kawalan kewibawaan'
			local outString = txCatExplain..txCatMore..txEmptyCat..txWPCat..txTOC..'\n'..'Halaman dalam kategori ini hanya boleh ditambah oleh [[Modul:Authority control]].'..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.idlink or conf[1]..' (identifier)'
			local wdpl       = ':d:Property:P'..conf.property
			local txCatMore  = frame:expandTemplate{ title = 'Cat more', args = {'Wikipedia:Kawalan kewibawaan', linktarget, wdpl} }
			local txEmptyCat = frame:expandTemplate{ title = 'Kategori mungkin kosong' }
			local txWPCat    = frame:expandTemplate{ title = 'Kategori Wikipedia', args = { hidden = 'yes', tracking = 'yes' } }
			local txDirtyCat = frame:expandTemplate{ title = 'Polluted category' }
			local txTOC = whichTOC( frame )
			local idCat = 'Rencana dengan pengenalan '..id..''
			local wpfCat = 'Rencana dengan maklumat kawalan kewibawaan salah'
			local outString = txCatMore..txEmptyCat..txWPCat..txDirtyCat..txTOC..'\n'..
							'Halaman dalam kategori ini hanya boleh ditambah oleh [[Modul:Authority control]].'..
							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, 'Rencana dengan pengenalan ([%w%.%- ]+) salah')
		local wpID       = mw.ustring.match(title, 'Rencana dengan pengenalan ([%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 '[[Kategori:Halaman dengan kategori pengenalan kawalan kewibawaan tidak diketahui]]'
		end
	end
	return ''
end

return p