Module:Namespacedata

From RobotX
Jump to navigation Jump to search

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

Usage

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

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

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

Example

(Main) (0) ·User (2) ·Special (-1) ·Media (-2) ·Template (10) ·Gadget (2300) ·Gadget definition (2302) ·File (6) ·Help (12) ·Summary (92) ·Module (828) ·MediaWiki (8) ·Category (14) ·Project (4) ·Data (486) ·Translations (1198) ·Thread (90) ·



-- 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