2,788
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local | local function hydrate_patterns() | ||
function hydrate_patterns() | |||
local languages = mw.loadData("Module:languages/data") | local languages = mw.loadData("Module:languages/data") | ||
local out_patterns = {} | local out_patterns = {} | ||
for | for _, p_data in ipairs(mw.loadData("Module:auto cat/data")) do | ||
local p_template, p_results = p_data[1], p_data[2] | |||
local p_lua = mw.ustring.gsub(tostring(mw.ustring.gsub(p_template, "%-", "%-")), "%%s", "(..-)") | local p_lua = mw.ustring.gsub(tostring(mw.ustring.gsub(p_template, "%-", "%-")), "%%s", "(..-)") | ||
if mw.ustring.find(p_template, "%%l") ~= nil then | if mw.ustring.find(p_template, "%%l") ~= nil then | ||
Line 13: | Line 11: | ||
local p_out_results = {} | local p_out_results = {} | ||
for _, p_result in ipairs(p_results) do table.insert(p_out_results, tostring(mw.ustring.gsub(p_result, "%%l", l_data.name))) end | for _, p_result in ipairs(p_results) do table.insert(p_out_results, tostring(mw.ustring.gsub(p_result, "%%l", l_data.name))) end | ||
out_patterns | table.insert(out_patterns, {"^"..mw.ustring.gsub(p_lua, "%%l", tostring(mw.ustring.gsub(l_data.name, "%-", "%-"))).."$", p_out_results}) | ||
end | end | ||
elseif mw.ustring.find(p_template, "%%c") ~= nil then | elseif mw.ustring.find(p_template, "%%c") ~= nil then | ||
Line 21: | Line 19: | ||
table.insert(p_out_results, tostring(mw.ustring.gsub(tostring(mw.ustring.gsub(p_result, "%%c", l_code)), "%%l", l_data.name))) | table.insert(p_out_results, tostring(mw.ustring.gsub(tostring(mw.ustring.gsub(p_result, "%%c", l_code)), "%%l", l_data.name))) | ||
end | end | ||
out_patterns | table.insert(out_patterns, {"^"..mw.ustring.gsub(p_lua, "%%c", l_code).."$", p_out_results}) | ||
end | end | ||
else | else | ||
out_patterns | table.insert(out_patterns, {"^"..p_lua.."$", p_results}) | ||
end | end | ||
end | end | ||
Line 30: | Line 28: | ||
end | end | ||
function process_category(category_name, p_lua, p_categories) | local function process_category(category_name, p_lua, p_categories) | ||
local out = "" | local out = "" | ||
local is_s, _, _, s_match = mw.ustring.find(p_lua, "%%s") ~= nil | local is_s, _, _, s_match = mw.ustring.find(p_lua, "%%s") ~= nil | ||
Line 41: | Line 39: | ||
function export.auto_cat(category_name) | function export.auto_cat(category_name) | ||
local lua_patterns = hydrate_patterns() | local lua_patterns = hydrate_patterns() | ||
for | for _, p_data in ipairs(lua_patterns) do | ||
local p_lua, p_categories = p_data[1], p_data[2] | |||
if mw.ustring.find(category_name, p_lua) ~= nil then | if mw.ustring.find(category_name, p_lua) ~= nil then | ||
return process_category(category_name, p_lua, p_categories) | return process_category(category_name, p_lua, p_categories) | ||
Line 47: | Line 46: | ||
end | end | ||
return "[[Category: | return "[[Category:Category pages not matched by auto cat]]" | ||
end | end | ||