From Wikipedia, the free encyclopedia
Content deleted Content added
|
 |
|||
| Line 6: | Line 6: | ||
|
function p.main(frame) |
function p.main(frame) |
||
|
local args = getArgs(frame) |
local args = getArgs(frame) |
||
|
|
= frame[“”] |
||
|
mw.logObject( |
mw.logObject() |
||
|
col = frame[“col”] or 2 |
col = frame[“col”] or 2 |
||
|
max = 0 |
max = 0 |
||
| Line 20: | Line 20: | ||
|
function p.import(args) |
function p.import(args) |
||
|
— 1. get the wikitext of the target page (hard coded right now) |
— 1. get the wikitext of the target page (hard coded right now) |
||
|
if |
if == then |
||
|
page = “User:13akoors/sandbox” |
page = “User:13akoors/sandbox” |
||
|
elseif |
elseif == then |
||
|
page = “User:13akoors/sandbox” |
page = “User:13akoors/sandbox” |
||
|
elseif |
elseif == then |
||
|
page = “User:13akoors/sandbox” |
page = “User:13akoors/sandbox” |
||
|
else |
else |
||
| Line 100: | Line 100: | ||
|
–{{#invoke:YourModule|import|page=List_of_Countries_by_population}} |
–{{#invoke:YourModule|import|page=List_of_Countries_by_population}} |
||
|
— this works in debug =p.import({ |
— this works in debug =p.import({=}) |
||
|
— this works in debug =p.main({ |
— this works in debug =p.main({=,col=2,”DC”,”DS”,”GBA”,”GBC”}) |
||
Latest revision as of 04:23, 19 September 2025
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame)
ct = frame["ct"]
mw.logObject(ct)
col = frame["col"] or 2
max = 0
for i, j in ipairs(args) do
max = max + 1
end
return p.import(args)
-- return p._main(args)
end
function p.import(args)
-- 1. get the wikitext of the target page (hard coded right now)
if ct == 1 then
page = "User:13akoors/sandbox"
elseif ct == 2 then
page = "User:13akoors/sandbox"
elseif ct == 3 then
page = "User:13akoors/sandbox"
else
return "No chart variant specified"
end
local content = mw.title.makeTitle( 'User', '13akoors/sandbox' ):getContent()
-- 2. extract the first table block
local twiki = content:match("<%!%-%- import%-%->(.-)<%!%-%- /import%-%->")
if not twiki then
return "No table found on page: " .. page
end
local input = {}
-- 3. iterate each row (lines starting with |)
for row in twiki:gmatch("%|(.-)\n") do
local cells = {}
-- split on cell separators (converts single "|" to \t and splits on that)
local temp = row:gsub("|","\t",1)
for cell in temp:gmatch("[^\t]+") do
table.insert(cells, mw.text.trim(cell))
end
input[cells[1]] = cells[2]
end
mw.logObject(input)
return p._main(args)
end
function p._main(args)
local output = "<table class=\"wikitable\" style=\"width:100%;margin:0px;background:transparent;\"cellpadding=\"0\";cellspacing=\"0\">"
local key = 1
while key <= max do
local coloutput = "<tr>"
for l=1,col do
if key <= max then
coloutput = coloutput.."<td>"..args[key].."</td>"
key = key + 1
else
coloutput = coloutput.."<td></td>"
key = key + 1
end
end
output = output..coloutput.."</tr>"
end
mw.log(output)
output = output.."</table>"
return output
end
function p.out(args)
local output = "<table class=\"wikitable\" style=\"width:100%;margin:0px;background:transparent;\"cellpadding=\"0\";cellspacing=\"0\">"
local key = 1
while key <= max do
local coloutput = "<tr>"
for l=1,col do
if key <= max then
coloutput = coloutput.."<td>"..args[key].."</td>"
key = key + 1
else
coloutput = coloutput.."<td></td>"
key = key + 1
end
end
output = output..coloutput.."</tr>"
end
mw.log(output)
output = output.."</table>"
return output
end
return p
--{{#invoke:YourModule|import|page=List_of_Countries_by_population}}
-- this works in debug =p.import({ct=1})
-- this works in debug =p.main({ct=1,col=2,"DC","DS","GBA","GBC"})


