Module:Sandbox/iantresman/sandbox/titlesubscripts

local p = {}

local properties = { "id", "interwiki", "namespace", "fragment", "nsText", "subjectNsText", "text", "prefixedText", "fullText", "rootText", "baseText", "subpageText", "canTalk", "exists", "fileExists", "isContentPage", "isExternal", "isLocal", "isRedirect", "isSpecialPage", "isSubpage", "isTalkPage", "contentModel", "basePageTitle", "rootPageTitle", "talkPageTitle", "subjectPageTitle" }

local methods = { -- "isSubpageOf", -- This method is commented out to avoid errors - it expects a table as input, not a string. "inNamespace", "inNamespaces", "hasSubjectNamespace", "subPageTitle", "partialUrl", "fullUrl", "localUrl", "canonicalUrl", -- "getContent" -- Commenting this out as dumping the entire page content in the output is confusing. :) But try uncommenting it and see what happens. }

local currentTitle = mw.title.getCurrentTitle

function p.main(frame) result = "" for _, property in ipairs(properties) do result = result .. "\n# " .. property .. ": " .. tostring(currentTitle[property]) end -- currentTitle[method](currentTitle) works because it emulates Lua's colon syntax. This syntax is often -- used in implementing Lua's version of object-oriented programming. Take a look at -- http://www.lua.org/pil/16.html for a good explanation. for _, method in ipairs(methods) do result = result .. "\n# " .. method .. ": " .. tostring(currentTitle[method](currentTitle, "Template")) -- "Template" is used to prevent errors when the namespace methods are called. end return result end

return p