Modulo:Adda dagiti subpanid ti ns

Permanente a nasalakniban a modulo
Manipud iti Wikipedia, ti nawaya nga ensiklopedia
Dokumentasion ti modulo

Daytoy a modulo ket birukenna no ti naited a nagan ti espasio ket mabalin nga addaan kadagiti subpanid.

Panagusar

Manipud ti wikitext

Manipud ti wikitext daytoy a modulo ket nasken a mausar babaen ti plantilia ti {{adda dagiti subpanid ti ns}}. Pangngaasi a kitaen ti panid ti plantilia para iti dokumentasion.

Manipud ti Lua

Kadawyan a kadagiti modulo ti Lua ket nasken nga agusar iti mw.site.namespaces[namespace].hasSubpages imbes a daytoy a modulo. Ngem no adda iti nasayaat a rason, daytoy ket mabalin a maserrekan a kas daytoy:

Ikaraga ti modulo:

local mNsHasSubpages = require('Modulo:Adda dagiti subpanid ti ns')

Ti pakaammo ti subpanid ket mabirukan iti annong ti ._main :

mNsHasSubpages._main(ns, frame)
  • ns ket isu tinagan ti espasio, bilang, wenno nagan ti panid. Daytoy ket kasisigud iti agdama a nagan ti espasio.
  • frame daytoy ket ti banag ti kuadro a mabalin a pakatawagan ti frame:callParserFunction no nasken. Daytoy ket pagpilian ken para iti internal a panagusar.

-- Daytoy a modulo ket isayangkatna ti [[Plantilia:Adda dagiti subpanid ti ns]].
-- While the template is fairly simple, this information is made available to
-- Lua directly, so using a module means that we don't have to update the
-- template as new namespaces are added.

local p = {}

function p._main(ns, frame)
	-- Get the current namespace if we were not passed one.
	if not ns then
		ns = mw.title.getCurrentTitle().namespace
	end

	-- Look up the namespace table from mw.site.namespaces. This should work
	-- for a majority of cases.
	local nsTable = mw.site.namespaces[ns]

	-- Try using string matching to get the namespace from page names.
	-- Do a quick and dirty bad title check to try and make sure we do the same
	-- thing as {{NAMESPACE}} in most cases.
	if not nsTable and type(ns) == 'string' and not ns:find('[<>|%[%]{}]') then
		local nsStripped = ns:gsub('^[_%s]*:', '')
		nsStripped = nsStripped:gsub(':.*$', '')
		nsTable = mw.site.namespaces[nsStripped]
	end

	-- If we still have no match then try the {{NAMESPACE}} parser function,
	-- which should catch the remainder of cases. Don't use a mw.title object,
	-- as this would increment the expensive function count for each new page
	-- tested.
	if not nsTable then
		frame = frame or mw.getCurrentFrame()
		local nsProcessed = frame:callParserFunction('NAMESPACE', ns)
		nsTable = nsProcessed and mw.site.namespaces[nsProcessed]
	end
	
	return nsTable and nsTable.hasSubpages
end

function p.main(frame)
	local ns = frame:getParent().args[1]
	if ns then
		ns = ns:match('^%s*(.-)%s*$') -- trim whitespace
		ns = tonumber(ns) or ns
	end
	local hasSubpages = p._main(ns, frame)
	return hasSubpages and 'wen' or ''
end

return p