Module:Namespacedata

From MediaWiki.org
Jump to navigation Jump to search
Module documentation

Outputs a simple list of subject, content or talk namespaces . Useful for documentation or showcasing of these namespaces.

Usage[edit]

{{#invoke:Namespacedata|main|subject}}

{{#invoke:Namespacedata|main|talk}}

{{#invoke:Namespacedata|main|content}}

Example[edit]

(Main) (0) ·User (2) ·Special (-1) ·Media (-2) ·Topic (2600) ·Template (10) ·Gadget (2300) ·Gadget definition (2302) ·Thread (90) ·File (6) ·Help (12) ·Summary (92) ·Module (828) ·Newsletter (5500) ·MediaWiki (8) ·Manual (100) ·Extension (102) ·API (104) ·Category (14) ·Translations (1198) ·Data (486) ·Skin (106) ·Project (4) ·


-- Shows local namespace names
local p = {}
local mapping = {["content"] = "contentNamespaces", ["subject"] = "subjectNamespaces", ["talk"] = "talkNamespaces"}

function p.main(frame)
	local workingFrame, namespaces = frame
	if frame and frame:getParent() and workingFrame then
		workingFrame = frame:getParent();
		namespaces = workingFrame.args[1] or frame.args[1] 
	end
	
	local output = ""
	local queryNamespaces = mw.site[mapping[namespaces]] 
	if (not queryNamespaces ) then
		 return 
	end
	
	for i, v in pairs (queryNamespaces) do
		output = output  .. (v.displayName or v.canonicalName)  .." (".. i ..") ·"
	end
	mw.logObject(queryNamespaces)
	return output
end

return p