Module:Sandbox/Aidan9382
Appearance
Sandboxes:
- sandbox 1, sandbox 2.1 and sandbox 3, when one just doesn't cut it
- sandboxjson for unique pagetype testing
- sandboxmessy - the literal sandbox
- SafeEnvironmentTesting - somewhat defunct sandbox, still sometimes used for certain tests
Module:Sandbox/Aidan9382 - module coding
Any linter errors here are likely unintentional, and may be fixed
Subpages
Code analysis
Basic code analysis for Module:Sandbox/Aidan9382 | |
---|---|
Scope | Message |
Scope starting line 111 | _pairs is defined but never referenced
|
Scope starting line 111 | _sort is defined but never referenced
|
Scope starting line 184 | i is defined but never referenced
|
Scope starting line 241 | t is defined but never referenced
|
Entire script | 1 local variable called _ was defined but never referenced, likely intentionally
|
Test invokes
This does nothing as of right now. 1748159097
Attempted to access unknown function 'notrealfunction'
parenting frame=Module:Sandbox/Aidan9382 parent1=Module:Sandbox/Aidan9382/doc mw.gct=Sandbox/Aidan9382
Frame arguments:
'1
' = 'a
'
'2
' = 'b
'
'3
' = 'c
'
Frame args: '1' = ' x ' '2' = ' y ' '3' = 'z' '4' = 'w'
getParameters args: 'a' = ' x ' 'c' = 'z' 'b' = ' y '
require('Module:Module wikitext')._addText('{{User:Aidan9382/sandbox/header|nolint=y}}')
require("strict")
local p = {}
function p.main()
return "<div style=text-align:right;font-size:80%>This does nothing as of right now. "..os.time().."</div>"
end
function p.iloveregexold()
local r = "%[?%[?.-:([^{|]+)%]?%]?"
local args = {mw.ustring.match("[[File:Hey.jpg|thumb|left|250px]]",r)}
return table.concat(args," -- ")
end
function p.iloveregex()
--This assumes [[ is present, and that therefore ]] is present
local r = "%[%[%a-:([^{|]+)(.+)%]%]"
local args = {mw.ustring.match("[[File:Hey.jpg|thumb|left|250px|All for [[Module:Excerpt/portals]]|alt=text]]",r)}
return table.concat(args," -- ")
end
function p.parentingLogic(frame)
--Note: Not even sure this thing goes beyond 1 parent, but have overcomplicated code anyways
local parentChain = {}
local newframe = frame
while true do
local parent = newframe:getParent()
if not parent then
break
end
newframe = parent
parentChain[#parentChain+1] = parent
end
local parentText = ""
for i,p in next,parentChain do
parentText = parentText .. " parent"..i.."="..p:getTitle()
end
return "frame="..frame:getTitle()..parentText.." mw.gct="..mw.title.getCurrentTitle().text
end
p["module-use"] = function(frame)
local parentLogicStuff = p.parentingLogic(frame)
local testlogic = "\n\n"
local i = 1
while true do
local c = frame.args["_test"..i]
if c then
testlogic = testlogic .. "_test"..i.."="..c
else
break
end
i = i + 1
end
return parentLogicStuff..testlogic
end
function p.getargs(frame)
local text = "Frame arguments:"
for k,v in pairs(frame.args) do
k,v = tostring(k), tostring(v)
text = text .. "\n\n'<code>" .. mw.text.nowiki(mw.text.unstrip(k)) .. "</code>' = '<code>" .. mw.text.nowiki(mw.text.unstrip(v)) .. "</code>'"
end
return text
end
function p.testGP(frame)
local s1 = "Frame args:"
local s2 = "getParameters args:"
local p1 = frame.args
local p2 = require("Module:GetParameters").getParameters(p1, {"a", "b", "c"})
for k,v in pairs(p1) do
s1 = s1 .. "\n'" .. tostring(k) .. "' = '" .. v .. "'"
end
for k,v in pairs(p2) do
s2 = s2 .. "\n'" .. tostring(k) .. "' = '" .. v .. "'"
end
return s1 .. "\n\n" .. s2 .. "\n\n\n"
end
function p.testframe(options) --For the Debug console - easy way into template entry points
--To be invoked with the wanted arguments and page titles, or none for the default.
--Setting .args after testframe() has been called is allowed but discouraged over simply
--calling the function with provided arguments so as to match the real functionality
local options = options or {}
local base = mw.getCurrentFrame()
local childArgs = options.args or {}
local parentArgs = options.parentArgs or childArgs
local childTitle = options.title or base:getTitle()
local parentTitle = options.parentTitle
local parentFrame = base:newChild({title=parentTitle, args=parentArgs})
local childFrame = parentFrame:newChild({title=childTitle, args=childArgs})
--Hide the extra parents, which would be unexpected outside of a debug setting
parentFrame.getParent = function() return nil end
--This 2nd hook is required, or else childFrame:getParent() somehow returns
--the unmodified parent frame, which doesn't have the getParent hook. :/
childFrame.getParent = function() return parentFrame end
return childFrame
end
--[[ Note
Scribunto really doesn't want or like you doing things like what this function
aims to do (basically "hook" _G), and the outputs are completely not what you
would expect from the below code. Unsure how much of this is exactly "intended"
--]]
local GE_logs = {}
local GE_messages = {}
function p.globalExperiments()
if rawget(_G, "_ranGE") then
return
end
rawset(_G, "_ranGE", true)
local _tostring = tostring
local _type = type
local _next = next
local _pairs = pairs
local _rawset = rawset
local scanned = {}
local _sort = table.sort
local function notelog(message)
if GE_logs[message] then
GE_logs[message] = GE_logs[message] + 1
else
GE_logs[message] = 1
GE_messages[#GE_messages+1] = message
end
end
local function recursive(t, path)
scanned[t] = true
for a,b in _next,t do
--for a,b in _pairs(t) do
if _type(b) == "table" and not scanned[b] then
recursive(b, path .. _tostring(a) .. ".")
elseif _type(b) == "function" then
_rawset(t, a, function(...)
notelog("(GHook) Just accessed " .. path .. _tostring(a))
return b(...)
end)
--notelog("(GHook) Hooked " .. path .. _tostring(a))
end
end
end
recursive(_G, "")
end
function p.dumpGELogs()
table.sort(GE_messages, function(x,y) return GE_logs[x]>GE_logs[y] end)
for _,message in next,GE_messages do
mw.log("(x" .. GE_logs[message] .. ") " .. message)
end
end
function p.magicWordTests(frame)
local args = frame.args
if args.process == "y" then
frame:preprocess("{{DEFAULTSORT:XYZ}}")
elseif args.returnprocess == "y" then
return frame:preprocess("{{DEFAULTSORT:XYZ}}")
else
return "{{DEFAULTSORT:XYZ}}"
end
end
function p.magicWordTests2(frame)
local args = frame.args
if args.process == "y" then
frame:preprocess("{{#assessment:Testing|B|Low}}")
elseif args.returnprocess == "y" then
return frame:preprocess("{{#assessment:Testing|B|Low}}")
else
return "{{#assessment:Testing|B|Low}}"
end
end
function p.substMagic(frame)
local arg = tonumber(frame.args[1]) or 0
return "{{safesubst:#invoke:Sandbox/Aidan9382|substMagic|" .. arg+1 .. "|~~~~}}"
end
function p.SpeedTest(frame)
local text = mw.text.unstripNoWiki(frame.args[1])
local out = ""
for i = 1,tonumber(frame.args[2] or 10) do
local r = tostring(math.random())
out = out .. string.sub(frame:preprocess(text..r),1,-(1+#r)) .. (frame.args[3] or "\n")
end
return out
end
function p.AnalysisTest()
repeat
local x = 5
until x == 5
end
function p.WasteExecutionTime(frame)
local t = tonumber(frame.args[1]) or 0
local start = os.clock()
while os.clock()-start < t do end
return "Wasted " .. (os.clock()-start) .. " seconds"
end
function p.OrganiseUnstandardisedArchivesList(frame)
local RegexToReason = { -- lua-adjusted from query/69710
["/archive_?/?[0-9]+$"]="fully lowercase",
["/ARCHIVE_?/?[0-9]+$"]="fully uppercase",
["/[Aa][Rr][Cc][Hh][Ii][Vv][Ee]/?[0-9]+$"]="bad number seperator",
["/[Aa][Rr][Cc][Hh][Ii][Vv][Ee]_?/?0[0-9]*$"]="starting zero",
["/[Aa][Rr][Cc][Hh][Ii][Vv][Ee][a-zA-Z0-9_]*/[Aa][Rr][Cc][Hh][Ii][Vv][Ee]"]="archive twice",
["/[Aa][Rr][Cc][Hh][Ii][Vv][Ee]$"]="just archive",
["/[Aa][Rr][Cc][Hh][Ii][Vv][Ee]_?/?[^1-9s]$"]="non-numbered archive",
["/[Aa][Rr][Cc][Hh][Ii][Vv][Ee][Ss]/_[0-9]+$"]="ClueBot III error"
}
local content = frame.args[1]
local out = ""
for line in content:gmatch(".-\n") do
--todo: make it a wikitable
local page = string.sub(line, 26, -4)
local found = false
for regex, reason in next,RegexToReason do
if string.find(page, regex) then
out = line + " -> " + reason
found = true
break
end
end
if not found then
out = line + " -> unknown reason"
end
end
return out
end
function p:namecall()
return self
end
return setmetatable(p,{
__index=function(t,k)
mw.log("Attempted to access unknown function '"..tostring(k).."' from Module:Sandbox/Aidan9382\n"..debug.traceback())
return function()
return "<span class=\"error\">Attempted to access unknown function '"..tostring(k).."'</span>"
--local frame = mw.getCurrentFrame()
--local traceback = frame:extensionTag("syntaxhighlight", debug.traceback(), {lang="text"})
--return "<span class=\"error\">Attempted to access unknown function '"..tostring(k).."'</span>\n"..traceback
end
end
})