Module:Process Query Output 3: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 33: | Line 33: | ||
query_output_tbl[page_name] = match | query_output_tbl[page_name] = match | ||
end | end | ||
end | |||
ordered_array_of_page_name_positions = {} | |||
--check that the concatenation of the parts equals the whole: | |||
for i, page_name in ipairs(trimmed_page_names_array) do | |||
pos1, pos2 = mw.ustring.find(full_query_arg, page_name) | |||
ordered_array_of_page_name_positions[tostring(pos1)] = page_name | |||
end | |||
table.sort(ordered_array_of_page_name_positions) | |||
local concatenated_parts = "" | |||
for k, v in pairs(ordered_array_of_page_name_positions) do | |||
concatenated_parts = concatenated_parts .. " " .. query_output_tbl[v] .. ", " | |||
end | |||
concatenated_parts = mw.ustring.sub(concatenated_parts, 1, -3) | |||
local advisory = "" | |||
if concatenated_parts ~= full_query_arg then | |||
advisory = "some part is missing" | |||
else | |||
advisory = "separated data equals the original" | |||
end | end | ||
| Line 42: | Line 62: | ||
concatenated_string_2 = concatenated_string_2 .. "</ul>" | concatenated_string_2 = concatenated_string_2 .. "</ul>" | ||
return concatenated_string .. concatenated_string_2 | return concatenated_string .. concatenated_string_2 .. "<ul><li>" .. advisory .. "</li></ul>" .. "<ul><li>" .. concatenated_parts .. "</li></ul>" | ||
Revision as of 01:22, 4 December 2025
Documentation for this module may be created at Module:Process Query Output 3/doc
local p = {}
function p.processData(frame)
local pages_only_arg = frame.args["pages_only"]
local full_query_arg = frame.args["full_query"]
--local vartype = type(plainlistString)
local page_names_array = mw.text.split(pages_only_arg, ",")
local trimmed_page_names_array = {}
for _, value in ipairs(page_names_array) do
table.insert(trimmed_page_names_array, mw.text.trim(value))
end
local concatenated_string = "<ul>"
for i, v in ipairs(trimmed_page_names_array) do
concatenated_string = concatenated_string .. "<li>" .. i .. ": " .. v .. "</li>"
end
concatenated_string = concatenated_string .. "</ul>"
query_output_tbl = {}
for i, page_name in ipairs(trimmed_page_names_array) do
match = mw.ustring.match(full_query_arg, page_name .. "%s" .. "(%b())")
-- if for some reason (for example, there is an unmatched "(" in the text for one of the fields) no match was found for one of the pages,
-- the page is listed and a note indicates the missing data:
if match == nil then
query_output_tbl[page_name] = '<span class="error-advisory">Data for page [[' .. page_name .. "]] could not be added to the list.</span>"
else
query_output_tbl[page_name] = match
end
end
ordered_array_of_page_name_positions = {}
--check that the concatenation of the parts equals the whole:
for i, page_name in ipairs(trimmed_page_names_array) do
pos1, pos2 = mw.ustring.find(full_query_arg, page_name)
ordered_array_of_page_name_positions[tostring(pos1)] = page_name
end
table.sort(ordered_array_of_page_name_positions)
local concatenated_parts = ""
for k, v in pairs(ordered_array_of_page_name_positions) do
concatenated_parts = concatenated_parts .. " " .. query_output_tbl[v] .. ", "
end
concatenated_parts = mw.ustring.sub(concatenated_parts, 1, -3)
local advisory = ""
if concatenated_parts ~= full_query_arg then
advisory = "some part is missing"
else
advisory = "separated data equals the original"
end
local concatenated_string_2 = "<ul>"
for k, v in pairs(query_output_tbl) do
concatenated_string_2 = concatenated_string_2 .. "<li>" .. k .. ": " .. v .. "</li>"
end
concatenated_string_2 = concatenated_string_2 .. "</ul>"
return concatenated_string .. concatenated_string_2 .. "<ul><li>" .. advisory .. "</li></ul>" .. "<ul><li>" .. concatenated_parts .. "</li></ul>"
end
return p