Module:Process Query Output 3
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 page_names_array = mw.text.split(pages_only_arg, ",")
for i = 1, #page_names_array do
page_names_array[i] = mw.text.trim(page_names_array[i])
end
local concatenated_string = "<ul>"
for i, v in ipairs(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(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(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
concatenated_positions_for_output = "<ul>"
for key, val in pairs(ordered_array_of_page_name_positions) do
concatenated_positions_for_output = concatenated_positions_for_output .. "<li>" .. key .. ": " .. val .. "</li>"
end
concatenated_positions_for_output = concatenated_positions_for_output .. "</ul>"
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 .. v .. " " .. 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 .. concatenated_positions_for_output .. "<ul><li>" .. advisory .. "</li></ul>" .. "<ul><li>" .. concatenated_parts .. "</li></ul><ul><li>" .. full_query_arg .. "</li></ul>"
end
return p