Module:SandboxTitle

local p = {}

foo = 1

local seen={} local xmsg=""

function dump(t,i) -- normally pass-in i="" as second-arg during first-call... seen[t]=true local s={} local n=0 for k in pairs(t) do		n=n+1 s[n]=k end table.sort(s) for k,v in ipairs(s) do --		print(i,v) xmsg = xmsg .. '<<' .. i .. '>>,<<' .. v .. '>>\n' --		xmsg = xmsg .. 'k\[' .. i .. '\]=\'' .. v .. '\'\n' v=t[v] if type(v)=="table" and not seen[v] then dump(v,i.."\t") end end end local function pc( fcn, args ) -- protected-calls always return true/false first... local ok, result = pcall( fcn, args ) if ok then return result else return 'ERROR...msg=' .. result .. '\n' end end

local function tableToString(t) local key local value local result result = '' for key, value in pairs(t) do       if (tonumber(key) ~= nil) then result = result .. ':table[' .. key .. '] is ' .. value .. '\n' else result = result .. ':table[\'' .. key .. '\'] is ' .. value .. '\n' end end return result end

local function listGlobals local k   local v    local result result = ';listGlobals\n' xmsg = "" dump(_G,"") result = result .. xmsg return result end

function p.canTalk(frame) local k   local v    local result --   local callArgs --   xmsg='dump-table:' local title = mw.title.getCurrentTitle result = ';canTalk\n' xmsg = "" --   return ';canTalk\n:' .. tostring(title.canTalk) .. '\n' --   return ';canTalk\n:' .. tableToString(title) .. '\n' --   return ';canTalk\n:' .. pc(dump,{title,""}) .. '\n' --   callArgs = {""} --   table.insert(callArgs,title) --   callArgs = {title,""} --   return ';canTalk\n:' .. pc(dump,callArgs) .. '\n' --   return ';canTalk\n:' .. dump(title,"") .. '\n' --   return ';canTalk\n:' .. type(title) .. '\n' --   result = result .. pc( listGlobal, nil) .. '\n' result = result .. listGlobal("") .. '\n' return result .. xmsg .. '\n' end function p.baseText(frame) local title = mw.title.getCurrentTitle return ';baseText\n:' .. tostring(title.baseText) .. '\n' --   return ';baseText\n:' .. '\n' end function p.exists(frame) local title = mw.title.getCurrentTitle return ';exists\n:' .. tostring(title.exists) .. '\n' end function p.fileExists(frame) local title = mw.title.getCurrentTitle return ';fileExists\n:' .. tostring(title.fileExists) .. '\n' end function p.fragment(frame) local title = mw.title.getCurrentTitle return ';fragment\n:' .. title.fragment .. '\n' end function p.fullText(frame) local title = mw.title.getCurrentTitle return ';fullText\n:' .. title.fullText .. '\n' end function p.getContent(frame) local text = mw.text.trim(frame.args[1]) local namespace = mw.text.trim(frame.args[2]) local title = mw.title.new(text, namespace) return ';getContent:' .. type(title) .. '\n' --   return ';getContent\n"' .. type(title:getContent) .. '"\n' end function p.id(frame) local title = mw.title.getCurrentTitle; return ';id\n:' .. title.id .. '\n' end function p.inNamespace(frame) -- see:http://community.wikia.com/wiki/Help:Namespace local msg = "" local num = frame.args[1] local title = mw.title.getCurrentTitle; --   msg = ";inNamespace\n:" .. type(frame) if ( num == nil ) then msg = msg .. ";inMainNamespace:\n" msg = msg .. ":" .. tostring(title:inNamespace(0)) .. '\n' else if ( tonumber(num) ~= nil ) then local tf = false msg = msg .. ';inNamespace(' .. num .. '):\n' tf = title:inNamespace(num) if ( tf ) then msg = msg .. ':common-vals: 0=main, 10=template, 828=module' msg = msg .. ' w/_talk at n+1\n' end msg = msg .. ":" .. tostring(tf) .. '\n' else msg = ';inNamespace was called with a non-number arg...\n' end end return msg end --function p.inNamespace(frame) --   local title = mw.title.getCurrentTitle; --   return ';inNamespace\n:' .. tostring(title:inNamespace(0)) .. '\n' --end function p.inNamespaces(frame) local title = mw.title.getCurrentTitle; local isHere = false local i   local j    -- see:http://dev.wikia.com/wiki/Lua_templating/Tips_and_tricks j={110,500,700,828,1200,2000} for i = -2, 15 do       if isHere then break end isHere = title:inNamespace(num) end while not isHere do       i={111,503,701,829,1202,2002} for a,b in next,i,0 do           SROPPED HERE....         end end local nss = { 0-15, 110-111, 500-503, 700-701, 828-829, 1200-1202, 2000-2002 } return ';inNamespaces\n:' .. tostring(title:inNamespaces(0)) .. '\n' end function p.interwiki(frame) local title = mw.title.getCurrentTitle; return ';interwiki\n:' .. title.interwiki .. '\n' end function p.isContentPage(frame) local title = mw.title.getCurrentTitle; return ';isContentPage\n:' .. tostring(title.isContentPage) .. '\n' end function p.isExternal(frame) local title = mw.title.getCurrentTitle; return ';isExternal\n:' .. tostring(title.isExternal) .. '\n' end function p.isLocal(frame) local title = mw.title.getCurrentTitle; return ';isLocal\n:' .. tostring(title.isLocal) .. '\n' end function p.isRedirect(frame) local title = mw.title.getCurrentTitle; return ';isRedirect\n:' .. tostring(title.isRedirect) .. '\n' end function p.isSpecialPage(frame) local title = mw.title.getCurrentTitle; return ';isSpecialPage\n:' .. tostring(title.isSpecialPage) .. '\n' end function p.isSubpage(frame) local title = mw.title.getCurrentTitle; return ';isSubpage\n:' .. tostring(title.isSubpage) .. '\n' end function p.isTalkPage(frame) local title = mw.title.getCurrentTitle; return ';isTalkPage\n:' .. tostring(title.isTalkPage) .. '\n' end function p.isSubpageOf(frame) local title = mw.title.getCurrentTitle; local text = mw.text.trim(frame.args[1]) local namespace = mw.text.trim(frame.args[2]) local title2 = mw.title.new(text, namespace) return ';isSubpageOf\n:' .. tostring(title:isSubpageOf(title2)) .. '\n' end function p.new(frame) local text = mw.text.trim(frame.args[1]) local namespace = mw.text.trim(frame.args[2]) local title = mw.title.new(text, namespace) return ';new\n:' .. title.id .. '\n' end function p.nsText(frame) local title = mw.title.getCurrentTitle; return ';nsText\n:' .. title.nsText .. '\n' end function p.prefixedText(frame) local title = mw.title.getCurrentTitle return ';prefixedText\n:' .. title.prefixedText .. '\n' end function p.rootText(frame) local title = mw.title.getCurrentTitle return ';rootText\n:' .. title.rootText .. '\n' end function p.subjectNsText(frame) local title = mw.title.getCurrentTitle return ';subjectNsText\n:' .. title.subjectNsText .. '\n' end function p.subpageText(frame) local title = mw.title.getCurrentTitle return ';subpageText\n:' .. title.subpageText .. '\n' end function p.text(frame) local title = mw.title.getCurrentTitle return ';text\n:' .. title.text .. '\n' end return p