Module:Import table and Module:Import table/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
newline after column break |
No edit summary |
||
Line 7: | Line 7: | ||
local rawlabel |
local rawlabel |
||
if label then |
if label then |
||
rawlabel = |
rawlabel = mw.ustring.match(label,'%[%[([^%|%]]+)%|') or mw.ustring.match(label,'%[%[([^%|%]]+)%]%]') |
||
if rawlabel then |
if rawlabel then |
||
qid = resolveEntity(rawlabel) |
qid = resolveEntity(rawlabel) |
||
Line 20: | Line 20: | ||
local tidy = mw.ustring.gsub(string,"%<ref.+%<%/ref%>","") -- remove any references with <ref .. </ref> |
local tidy = mw.ustring.gsub(string,"%<ref.+%<%/ref%>","") -- remove any references with <ref .. </ref> |
||
tidy = mw.ustring.gsub(tidy,"%<ref.+%/%>","") -- remove any references with <ref .. /> |
tidy = mw.ustring.gsub(tidy,"%<ref.+%/%>","") -- remove any references with <ref .. /> |
||
tidy = mw.ustring.gsub(tidy,"^%s*%|","") -- remove | character at start |
|||
tidy = mw.text.trim(tidy) -- trim spaces |
tidy = mw.text.trim(tidy) -- trim spaces |
||
return tidy |
return tidy |
||
Line 48: | Line 49: | ||
end |
end |
||
local content = mw.title.new(args.page):getContent() -- read page specified |
local content = mw.title.new(args.page):getContent() -- read page specified |
||
content = |
content = mw.ustring.match(content,"%{%|(.+)%|%}") -- keep table only |
||
content = |
content = mw.ustring.gsub(content,"||","\n|") -- use \n| for column breaks |
||
local rows = mw.text.split(content,"|-\n" |
local rows = mw.text.split(content,"%|%-\n") -- split table into rows, prev %|%-[^\n]*\n |
||
table.remove(rows,1) -- remove table definition |
table.remove(rows,1) -- remove table definition |
||
table.remove(rows,1) -- remove heading row |
--table.remove(rows,1) -- remove heading row |
||
local output = "" |
local output = "" |
||
local v2 = "" |
local v2 = "" |
||
for rn,row in ipairs(rows) do |
for rn,row in ipairs(rows) do |
||
local columns = mw.text.split(row,"\n|") -- split table rom into columns |
local columns = mw.text.split(row,"\n|") -- split table rom into columns |
||
table.remove(columns,1) -- remove content before the first \n| character |
--table.remove(columns,1) -- remove content before the first \n| character |
||
local label = columns[1] |
local label = columns[1] |
||
if label then |
if label then |
||
label = tidystring(label) |
label = tidystring(label) |
||
local qid = mw.ustring.match(label,"Q%d+") -- check if QID is specified in first column |
|||
local qid |
|||
qid,label = resolveqid(label) -- resolve qid if first column is link |
|||
if not qid then |
if not qid then |
||
qid = |
qid,label = resolveqid(label) -- resolve qid if first column is link |
||
end |
end |
||
local entity |
local entity |
||
Line 76: | Line 76: | ||
v2 = v2 .. qid .. tab .. 'Den' .. tab .. '"' .. mw.wikibase.getLabel(common["P31"]) |
v2 = v2 .. qid .. tab .. 'Den' .. tab .. '"' .. mw.wikibase.getLabel(common["P31"]) |
||
if common["P17"] then -- add country |
if common["P17"] then -- add country |
||
v2 = v2 .. |
v2 = v2 .. " in " |
||
if common["P131"] then |
if common["P131"] then -- add region too |
||
v2 = v2 .. mw.wikibase.getLabel(common["P131"]) .. ", " |
v2 = v2 .. mw.wikibase.getLabel(common["P131"]) .. ", " |
||
end |
end |
||
v2 = v2 .. mw.wikibase.getLabel(common["P17"]) |
v2 = v2 .. mw.wikibase.getLabel(common["P17"]) |
||
elseif common["P376"] then -- add planet |
|||
v2 = v2 .. " on " .. mw.wikibase.getLabel(common["P376"]) |
|||
end |
end |
||
v2 = v2 .. '"' .. eol |
v2 = v2 .. '"' .. eol |
||
Line 112: | Line 114: | ||
end |
end |
||
elseif config[cn][1] == "year" then |
elseif config[cn][1] == "year" then |
||
local val = |
local val = mw.ustring.match(col,"%d%d%d%d") |
||
if val then |
if val then |
||
v2 = addtov2(config[cn][2],"+" ..val .. "-00-00T00:00:00Z/9") |
v2 = addtov2(config[cn][2],"+" ..val .. "-00-00T00:00:00Z/9") |
||
end |
end |
||
elseif config[cn][1] == "quantity" then |
elseif config[cn][1] == "quantity" then |
||
local val = |
local val = mw.ustring.gsub(col,",","") -- remove any commas |
||
val = |
val = mw.ustring.match(val,"%d+%.?%d*") -- extract value, possibly from inside convert template |
||
if val then |
if val then |
||
if |
if mw.ustring.upper(mw.ustring.sub(config[cn][3],1,1)) == "Q" then |
||
config[cn][3] = |
config[cn][3] = mw.ustring.sub(config[cn][3],2) |
||
end |
end |
||
v2 = addtov2(config[cn][2],val .. "U" .. config[cn][3]) |
v2 = addtov2(config[cn][2],val .. "U" .. config[cn][3]) |
||
Line 130: | Line 132: | ||
end |
end |
||
elseif config[cn][1] == "coord" then |
elseif config[cn][1] == "coord" then |
||
local val = mw.ustring.match(col,"%{%{[Cc]oord.*%}%}") |
|||
⚫ | |||
if val then |
|||
val = mw.getCurrentFrame():preprocess(col) |
|||
v2 = addtov2(config[cn][2],"@" .. coord2text(val,"lat") .. "/" .. coord2text(val,"long")) |
v2 = addtov2(config[cn][2],"@" .. coord2text(val,"lat") .. "/" .. coord2text(val,"long")) |
||
end |
|||
elseif config[cn][1] == "image" then |
|||
local val = mw.ustring.match(col,"%[%[File%:([^%|%]]+).*%]%]") |
|||
⚫ | |||
v2 = addtov2(config[cn][2],'"' .. val .. '"') |
|||
end |
end |
||
end |
end |