10,731
edits
TheNightAvl (talk | contribs) No edit summary Tag: Reverted |
TheNightAvl (talk | contribs) No edit summary Tag: Reverted |
||
Line 22: | Line 22: | ||
-- Alternative to mw.ustring.gsub that is neater to call in code | -- Alternative to mw.ustring.gsub that is neater to call in code | ||
-- and can handle multiple replacements at once. | -- and can handle multiple replacements at once. | ||
local function replace(str, | local function replace(str, gsubs) | ||
local res = | local res = str | ||
for from, to in gsubs do | |||
res = tostring(mw.ustring.gsub(res, from, to)) | |||
end | end | ||
return res | return res | ||
Line 65: | Line 62: | ||
local p_out_cats = {} | local p_out_cats = {} | ||
for _, p_cat in ipairs(p_categories) do | for _, p_cat in ipairs(p_categories) do | ||
table.insert(p_out_cats, replace(p_cat, "%%l" | table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%u"] = l2_data.name})) | ||
end | end | ||
table.insert(out_patterns, to_pattern(replace(p_lua, "%%l" | table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["%%u"] = sanitize(l2_data.name)}), p_out_cats)) | ||
end | end | ||
end | end | ||
Line 73: | Line 70: | ||
local p_out_cats = {} | local p_out_cats = {} | ||
for _, p_cat in ipairs(p_categories) do | for _, p_cat in ipairs(p_categories) do | ||
table.insert(p_out_cats, replace(p_cat, "%%l" | table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name})) | ||
end | end | ||
table.insert(out_patterns, to_pattern(replace(p_lua, "%%l" | table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name)}), p_out_cats)) | ||
end | end | ||
end | end | ||
Line 84: | Line 81: | ||
local p_out_cats = {} | local p_out_cats = {} | ||
for _, p_cat in ipairs(p_categories) do | for _, p_cat in ipairs(p_categories) do | ||
table.insert(p_out_cats, replace(p_cat, "%%l" | table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%c"] = l_code})) | ||
end | end | ||
table.insert(out_patterns, to_pattern(replace(p_lua, "%%c" | table.insert(out_patterns, to_pattern(replace(p_lua, {["%%c"] = l_code}), p_out_cats)) | ||
end | end | ||
end | end | ||
Line 94: | Line 91: | ||
local p_out_cats = {} | local p_out_cats = {} | ||
for _, p_cat in ipairs(p_categories) do | for _, p_cat in ipairs(p_categories) do | ||
table.insert(p_out_cats, replace(p_cat, "^%%pos" | table.insert(p_out_cats, replace(p_cat, {["^%%pos"] = capitalize(pos), ["%%pos"] = pos})) | ||
end | end | ||
table.insert(out_patterns, to_pattern(replace(p_lua, "^%%pos" | table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%pos"] = capitalize(pos), ["%%pos"] = pos}), p_out_cats)) | ||
end | end | ||
end | end | ||
Line 104: | Line 101: | ||
for _, p_data in ipairs(mw.loadData("Module:auto cat/data")) do | for _, p_data in ipairs(mw.loadData("Module:auto cat/data")) do | ||
local p_template, p_categories = p_data[1], p_data[2] | local p_template, p_categories = p_data[1], p_data[2] | ||
local p_lua = replace(sanitize(p_template), "%%s" | local p_lua = replace(sanitize(p_template), {["%%s"] = "(..-)"}) | ||
if mw.ustring.find(p_template, "%%l") ~= nil then | if mw.ustring.find(p_template, "%%l") ~= nil then | ||
hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil) | hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil) | ||
Line 123: | Line 120: | ||
local _, _, s_match = mw.ustring.find(category_name, p_lua) | local _, _, s_match = mw.ustring.find(category_name, p_lua) | ||
for _, p_category in ipairs(p_categories) do | for _, p_category in ipairs(p_categories) do | ||
out = out .. "[[Category:" .. (is_s and replace(p_category, "%%s" | out = out .. "[[Category:" .. (is_s and replace(p_category, {["%%s"] = s_match}) or p_category) .. "]]" | ||
end | end | ||
return out | return out |