Module:Sandbox/Frame
Appearance
Tests
[edit]Code | {{#invoke:Sandbox/Frame|#key=<!-- xyzzy -->#|a|b|c|2=B|4=D|d|49=!|{{=}}={{=}}|{{!}}={{!}}|=|<nowiki/>=<nowiki/>|WhatLinksHere={{Special:WhatLinksHere/Module:Sandbox/Frame}}}}
|
---|---|
Result | package args (0) = frame:getTitle() = "Module:Sandbox/Frame" frame = table#1 { ["args"] = table#2 { metatable = table#3 "a", "B", "c", "d", [49] = "!", [""] = "", ["="] = "=", ["WhatLinksHere"] = "'\"`UNIQ--item-3--QINU`\"'", ["|"] = "|", ["'\"`UNIQ--nowiki-00000001-QINU`\"'"] = "'\"`UNIQ--nowiki-00000002-QINU`\"'", }, ["argumentPairs"] = function#1, ["callParserFunction"] = function#2, ["expandTemplate"] = function#3, ["extensionTag"] = function#4, ["getArgument"] = function#5, ["getParent"] = function#6, ["getTitle"] = function#7, ["newChild"] = function#8, ["newParserValue"] = function#9, ["newTemplateParserValue"] = function#10, ["preprocess"] = function#11, } frame:getParent():getTitle() = "Module:Sandbox/Frame/doc" frame:getParent() = table#1 { ["args"] = table#2 { metatable = table#3 }, ["argumentPairs"] = function#1, ["callParserFunction"] = function#2, ["expandTemplate"] = function#3, ["extensionTag"] = function#4, ["getArgument"] = function#5, ["getParent"] = function#6, ["getTitle"] = function#7, ["newChild"] = function#8, ["newParserValue"] = function#9, ["newTemplateParserValue"] = function#10, ["preprocess"] = function#11, } pkg == require(frame:getTitle()) = false invoke key = "#key=#" invoke ParserFunction testpackage args (0) = frame:getTitle() = "Module:Sandbox/Frame" frame = table#1 { ["args"] = table#2 { metatable = table#3 "abc", ["def"] = "1", }, ["argumentPairs"] = function#1, ["callParserFunction"] = function#2, ["expandTemplate"] = function#3, ["extensionTag"] = function#4, ["getArgument"] = function#5, ["getParent"] = function#6, ["getTitle"] = function#7, ["newChild"] = function#8, ["newParserValue"] = function#9, ["newTemplateParserValue"] = function#10, ["preprocess"] = function#11, } frame:getParent():getTitle() = "Module:Sandbox/Frame" frame:getParent() = table#1 { ["args"] = table#2 { metatable = table#3 "a", "B", "c", "d", [49] = "!", [""] = "", ["="] = "=", ["WhatLinksHere"] = "'\"`UNIQ--item-3--QINU`\"'", ["|"] = "|", ["'\"`UNIQ--nowiki-00000001-QINU`\"'"] = "'\"`UNIQ--nowiki-00000002-QINU`\"'", }, ["argumentPairs"] = function#1, ["callParserFunction"] = function#2, ["expandTemplate"] = function#3, ["extensionTag"] = function#4, ["getArgument"] = function#5, ["getParent"] = function#6, ["getTitle"] = function#7, ["newChild"] = function#8, ["newParserValue"] = function#9, ["newTemplateParserValue"] = function#10, ["preprocess"] = function#11, } pkg == require(frame:getTitle()) = false invoke key = "{{<#rtest#>}}" |
Notes
[edit]wikitext parameters
[edit]- parameters can be numbered or named
- numbered parameters can be implicitly or explicitly numbered
- named parameters are case-sensitive, can contain spaces and underscores and can be empty; can contain almost anything including punctuation and strip markers so long a some things are properly escaped such as:
{{=}}
,{{!}}
- parameters cannot begin or end with a space (although arguments to implicitly numbered parameters can contain leading and trailing spaces)
- explicitly numbered parameters must be normalized (i.e., no leading zero padding, etc.) positive integers or they will be considered named parameters
page titles
[edit]- mw:Manual:$wgLegalTitleChars
- the first character often is case-insensitively forced to uppercase (based on
$wgCapitalLinks
) - reserved characters include:
#<>[]|{}
(wikitext markup), ASCII control characters 0–31 and 127, Unicode U+FFFD, HTML character entities - cannot contain three or more continuous
~
tildes as these have wikitext markup meaning - cannot begin with a namespace name including the empty article namespace consisting of a single
:
colon - cannot begin with an interwiki or interlanguage prefix
- namespace, interwiki and interlanguage prefixes are case-insensitive
- cannot be
.
or..
; or begin with./
or../
; or contain/./
or/../
; or end with/.
or/..
/
is a reserved character when subpages are enabled for a namespace_
characters are treated as spaces- cannot begin or end with a space
- cannot contain consecutive spaces
- cannot contain
%
percent-encoded hexadecimal digits
- the first character often is case-insensitively forced to uppercase (based on
- mw:Manual:PAGENAMEE encoding
- Compare differences with:
{{PAGENAME}}
,{{PAGENAMEE}}
,{{urlencode:}}
and{{anchorencode:}}
- Compare differences with:
- mw:Manual:Page table#Schema summary
page_namespace
is stored asint(11)
page_title
is stored asvarbinary(255)
Subpages
[edit]local require = require
require[[strict]]
local mw, title = require[[mw]], require[[mw.title]]
local _G, table, math, string = require[[_G]], require[[table]], require[[math]], require[[string]]
table.unpack = _G.unpack -- Lua 5.2 compat
local results = setmetatable({}, {__index = table})
local pargsn = _G.select('#', ...)
do
local pa = "package args (" .. pargsn .. ") = "
if 0 < pargsn then
pa = pa .. ...
end
for i = 2, pargsn do
pa = pa .. ", " .. _G.select(i, ...)
end
results:insert(pa)
end
local frame = mw.getCurrentFrame()
do
local flabel, f = "frame", frame
while f do
results:insert(flabel .. ":getTitle()" .. " = " .. mw.dumpObject(f:getTitle()))
results:insert(flabel .. " = " .. mw.dumpObject(f))
flabel, f = flabel .. ":getParent()", f:getParent()
end
end
local ipn = frame:getTitle()
local ititle = title.new(ipn)
local rtestkey = '{{<#rtest#>}}'
--[=[
Can get weird recurisve errors if package use is attempted here during
package initialization and before it is complete, e.g., via:
"require"
"callParserFunction #invoke"
"Lua error in package.lua at line 95: loop or previous error loading module"
"Unstrip depth limit exceeded (20)
]=]
local p = {}
return setmetatable(p, {
__call = function(pkg, ...)
return
end,
__index = function(pkg, key)
local rpkg = require(ipn)
results:insert("pkg == require(frame:getTitle())" .. " = " .. mw.dumpObject(pkg == rpkg))
results:insert("invoke key" .. " = " .. mw.dumpObject(key))
return function(...)
if _G.select('#', ...) ~= 1 or ... ~= frame then
return -- ignore non-invoke calls; could throw error
end
if key ~= rtestkey then
results:insert("invoke ParserFunction test")
results:insert(frame:callParserFunction{name = '#invoke:' .. ititle.text, args = {rtestkey, "abc", def = 1}})
results:insert("invoke ParserFunction parent test")
results:insert(frame:getParent():callParserFunction{name = '#invoke:' .. ititle.text, args = {rtestkey, "abc", def = 1}})
local cframe = frame:newChild{title = ititle:subPageTitle('doc'), args = {"def", abc = 1}}
local pcframe = frame:getParent():newChild{title = ititle:subPageTitle('doc'), args = {"xyz", zyx = 1}}
--[=[ Direct calling is interesting but causes a frame mismatch with mw.getCurrentFrame()
results:insert("start non-invoke call testing...")
results:insert("call on same package test")
results:insert((pkg[rtestkey](cframe)))
results:insert((pkg[rtestkey](pcframe)))
results:insert("call on required package test")
results:insert((rpkg[rtestkey](cframe)))
results:insert((rpkg[rtestkey](pcframe)))
results:insert("end non-invoke call testing")
]=]
results:insert("invoke ParserFunction child test")
results:insert(cframe:callParserFunction{name = '#invoke:' .. ititle.text, args = {rtestkey, "abc", def = 1}})
results:insert("invoke ParserFunction parent child test")
results:insert(pcframe:callParserFunction{name = '#invoke:' .. ititle.text, args = {rtestkey, "abc", def = 1}})
end
return frame:callParserFunction{name = '#tag:pre', args = {results:concat('\n')}}
end
end
})