Module:Orphaned data pages
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Orphaned data pages/doc
local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs -- for processing arguments
local cf = require("Module:Custom_functions")
local ibf = require("Module:Infobox_functions")
local p = {}
function p.species()
local data_page_prefix = "Species"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data" , category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = prefix}
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, main_pages)
if #orphaned_data_pages > 0 then
-- italicize sci names
orphaned_data_pages_link_text = cf.species_italicizer(orphaned_data_pages)
local processed_orphans = {}
for i = 1, #orphaned_data_pages do
processed_orphans[i] = "[[" .. orphaned_data_pages[i] .. "|" .. orphaned_data_pages_link_text[i] .. "]]"
end
-- process output into a bulleted list
local output = "* " .. table.concat(processed_orphans, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
function p.geography()
local data_page_prefix = "Geography"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data" , category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = prefix}
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, main_pages)
if #orphaned_data_pages > 0 then
orphaned_data_pages = cf.element_sandwicher(orphaned_data_pages, "[[", "]]")
-- process output into a bulleted list
local output = "* " .. table.concat(orphaned_data_pages, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
function p.geography_new()
local data_page_prefix = "Geography"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data", category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = data_page_category}
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- Check the content of each page in main_pages for the "{{Data:" string
local pages_without_data_string = {}
for _, page in ipairs(main_pages) do
local content = mw.title.new(page).getContent()
if not string.find(content, "{{Data:") then
table.insert(pages_without_data_string, page)
end
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, pages_without_data_string)
if #orphaned_data_pages > 0 then
orphaned_data_pages = cf.element_sandwicher(orphaned_data_pages, "[[", "]]")
-- process output into a bulleted list
local output = "* " .. table.concat(orphaned_data_pages, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
function p.organization()
local data_page_prefix = "Organization"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data" , category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = prefix}
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, main_pages)
if #orphaned_data_pages > 0 then
orphaned_data_pages = cf.element_sandwicher(orphaned_data_pages, "[[", "]]")
-- process output into a bulleted list
local output = "* " .. table.concat(orphaned_data_pages, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
function p.parent_org()
local data_page_prefix = "Parent organization"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data" , category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = prefix}
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, main_pages)
if #orphaned_data_pages > 0 then
orphaned_data_pages = cf.element_sandwicher(orphaned_data_pages, "[[", "]]")
-- process output into a bulleted list
local output = "* " .. table.concat(orphaned_data_pages, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
function p.resource()
local data_page_prefix = "Resource"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data" , category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = prefix}
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- small band-aid so data and main page will find each other for "ELocust" since the Data page is lowercase but the forward-facing is uppercase (wiki page can't start with lowercase letter)
local string_to_edit = "eLocust3 digital tools"
local string_to_replace = "ELocust3 digital tools"
for i, v in ipairs(data_pages) do
if v == string_to_edit then
data_pages[i] = string_to_replace
end
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, main_pages)
if #orphaned_data_pages > 0 then
orphaned_data_pages = cf.element_sandwicher(orphaned_data_pages, "[[", "]]")
-- process output into a bulleted list
local output = "* " .. table.concat(orphaned_data_pages, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
function p.person()
local data_page_prefix = "Person"
local modded_prefix = data_page_prefix .. "%-"
local data_page_category = data_page_prefix .. " data"
-- The way I have it set up I have to get the main namespace names from 2 different categories"
local data_pages = mw.ext.dpl.getPagenames{namespace = "Data" , category = data_page_category}
local main_pages = mw.ext.dpl.getPagenames{namespace = "Main", category = prefix}
local main_pages_2 = mw.ext.dpl.getPagenames{namespace = "Main", category = "Historical person"}
-- join the two queries together
for _, page in ipairs(main_pages_2) do
table.insert(main_pages, page)
end
-- run loop to process text
for index , page in ipairs(data_pages) do
data_pages[index] = string.gsub(page, modded_prefix, "")
end
-- Check if each element in array a is present in b and collect matching elements
local orphaned_data_pages = cf.in_a_not_b(data_pages, main_pages)
if #orphaned_data_pages > 0 then
orphaned_data_pages = cf.element_sandwicher(orphaned_data_pages, "[[", "]]")
-- process output into a bulleted list
local output = "* " .. table.concat(orphaned_data_pages, "\n* ") .. "\n"
return output
else
return "All data pages seem to be connected correctly."
end
end
return p