Difference between revisions of "Module:Test"
Jump to navigation
Jump to search
(61 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
cf = mw.getCurrentFrame() | cf = mw.getCurrentFrame() | ||
return "Hello, world! from " .. mw.allToString(cf.args[3]) .. "-" .. mw.allToString(cf.args[1]) .."-" ..mw.allToString(cf.args[2]) | return "Hello, world! from " .. mw.allToString(cf.args[3]) .. "-" .. mw.allToString(cf.args[1]) .."-" ..mw.allToString(cf.args[2]) | ||
end | |||
function p.returnHTMLText(a) | |||
pageContent = tostring(mw.getCurrentFrame().args[1]) | |||
local div = mw.html.create( 'syntaxhighlight' ) | |||
div | |||
:attr( 'lang', 'HTML' ) | |||
:wikitext( pageContent ) | |||
return a:preprocess(tostring( div )) | |||
end | |||
function p.returnNowkiText(a) | |||
pageContent = tostring(mw.getCurrentFrame().args[1]) | |||
local div = mw.html.create( 'nowiki' ) | |||
div | |||
:wikitext( pageContent ) | |||
return a:preprocess(tostring( div )) | |||
end | |||
function p.luaSourceCodeText(a) | |||
pageContent = tostring(mw.getCurrentFrame().args[1]) | |||
local div = mw.html.create( 'syntaxhighlight' ) | |||
div | |||
:attr( 'lang', 'lua' ) | |||
:wikitext( pageContent ) | |||
return a:preprocess(tostring( div )) | |||
end | |||
function p.originalText(a) | |||
return mw.getCurrentFrame().args[1] | |||
end | |||
function p.reverseResult(a) | |||
str = mw.getCurrentFrame().args[1] | |||
text = string.reverse(str) | |||
return a:preprocess(text) | |||
end | |||
function p.reverse(a) | |||
str = mw.getCurrentFrame().args[1] | |||
text = string.reverse(str) | |||
return text | |||
end | end | ||
Line 9: | Line 51: | ||
cf = mw.getCurrentFrame() | cf = mw.getCurrentFrame() | ||
-- aString = "<math>\\" .. mw.allToString(cf.args[1]) .. "</math>" | -- aString = "<math>\\" .. mw.allToString(cf.args[1]) .. "</math>" | ||
aString = "<math>\\ | str = mw.getCurrentFrame().args[1] | ||
aString = cf:preprocess("<math>\\"..str.."</math>") | |||
return aString | return aString | ||
end | end | ||
Line 22: | Line 65: | ||
arg1 = cf.args[1] | arg1 = cf.args[1] | ||
if arg1 == "1" then | if arg1 == "1" then | ||
return | return cf.args[2] | ||
elseif arg1 == "2" then | elseif arg1 == "2" then | ||
return | return cf.args[3] | ||
else | else | ||
return "Error" | return "Error" | ||
Line 38: | Line 81: | ||
end | end | ||
function p.arithmetic( | function p.arithmetic(cf) | ||
arg1 = cf.args[1] | arg1 = cf.args[1] | ||
num = 0 + arg1 | arg2 = cf.args[2] | ||
arg3 = cf.args[3] | |||
num = 0 + arg1 + arg2 + arg3 | |||
return num | return num | ||
end | |||
function p.trig(cf) | |||
return math.cos(cf.args[1]) | |||
end | |||
function p.repetition(cf) | |||
aList = { } | |||
aString = "" | |||
count = cf.args[1] + 0 | |||
count2 = cf.args[2] + 0 | |||
while count > 0 | |||
do | |||
table.insert(aList, count) | |||
count = count -1 | |||
end | |||
for name = cf.args[1], cf.args[2] do | |||
table.insert(aList, name) | |||
end | |||
resultString = "" | |||
elementCount = #aList | |||
while elementCount > 1 | |||
do | |||
resultString = resultString .. " " .. aList[elementCount] .. "," | |||
elementCount = elementCount - 1 | |||
end | |||
return resultString | |||
end | |||
function p.pagesInCategory(cf) | |||
cat = cf.args[1] | |||
which = cf.args[2] | |||
params = {"all", "subcats", "files", "pages" } | |||
return mw.site.stats.pagesInCategory(cat, which) | |||
end | end | ||
return p | return p |
Latest revision as of 15:28, 9 January 2022
Documentation for this module may be created at Module:Test/doc
p = {}
function p.hello_world(a)
cf = mw.getCurrentFrame()
return "Hello, world! from " .. mw.allToString(cf.args[3]) .. "-" .. mw.allToString(cf.args[1]) .."-" ..mw.allToString(cf.args[2])
end
function p.returnHTMLText(a)
pageContent = tostring(mw.getCurrentFrame().args[1])
local div = mw.html.create( 'syntaxhighlight' )
div
:attr( 'lang', 'HTML' )
:wikitext( pageContent )
return a:preprocess(tostring( div ))
end
function p.returnNowkiText(a)
pageContent = tostring(mw.getCurrentFrame().args[1])
local div = mw.html.create( 'nowiki' )
div
:wikitext( pageContent )
return a:preprocess(tostring( div ))
end
function p.luaSourceCodeText(a)
pageContent = tostring(mw.getCurrentFrame().args[1])
local div = mw.html.create( 'syntaxhighlight' )
div
:attr( 'lang', 'lua' )
:wikitext( pageContent )
return a:preprocess(tostring( div ))
end
function p.originalText(a)
return mw.getCurrentFrame().args[1]
end
function p.reverseResult(a)
str = mw.getCurrentFrame().args[1]
text = string.reverse(str)
return a:preprocess(text)
end
function p.reverse(a)
str = mw.getCurrentFrame().args[1]
text = string.reverse(str)
return text
end
function p.greek_letter()
cf = mw.getCurrentFrame()
-- aString = "<math>\\" .. mw.allToString(cf.args[1]) .. "</math>"
str = mw.getCurrentFrame().args[1]
aString = cf:preprocess("<math>\\"..str.."</math>")
return aString
end
function p.rawstring()
cf = mw.getCurrentFrame()
return mw.allToString(cf.args[1])
end
function p.selector()
cf = mw.getCurrentFrame()
arg1 = cf.args[1]
if arg1 == "1" then
return cf.args[2]
elseif arg1 == "2" then
return cf.args[3]
else
return "Error"
end
end
function p.multiArgument()
cf = mw.getCurrentFrame()
arg1 = cf.args[1]
arg2 = cf.args[2]
arg3 = cf.args[3]
return arg1 .. " ," .. arg2 .. " ," .. arg3
end
function p.arithmetic(cf)
arg1 = cf.args[1]
arg2 = cf.args[2]
arg3 = cf.args[3]
num = 0 + arg1 + arg2 + arg3
return num
end
function p.trig(cf)
return math.cos(cf.args[1])
end
function p.repetition(cf)
aList = { }
aString = ""
count = cf.args[1] + 0
count2 = cf.args[2] + 0
while count > 0
do
table.insert(aList, count)
count = count -1
end
for name = cf.args[1], cf.args[2] do
table.insert(aList, name)
end
resultString = ""
elementCount = #aList
while elementCount > 1
do
resultString = resultString .. " " .. aList[elementCount] .. ","
elementCount = elementCount - 1
end
return resultString
end
function p.pagesInCategory(cf)
cat = cf.args[1]
which = cf.args[2]
params = {"all", "subcats", "files", "pages" }
return mw.site.stats.pagesInCategory(cat, which)
end
return p