Jump to content

Module:Sandbox/Lemondoge/SpellcheckerTM

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Lemondoge (talk | contribs) at 03:02, 3 April 2023 (Skeletor will return next week with more [soon-to-be] disturbing (and hopefully functional) modules). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('Module:Module wikitext')._addText("{{Humor}}")

function string:spellChecker(replacements)
    local function adjust_case(first, second, disable_case_transmission)
        if disable_case_transmission then
            return second
        end
        local first_char = first:sub(1, 1)
        if first_char:lower() == first_char then
            return second:lower()
        else
            return second:upper()
        end
    end

    local result = self
    for _, entry in ipairs(replacements) do
        local search, replace = entry[1], entry[2]
        local disable_case_transmission = entry[3]
        local replace_with_case = adjust_case(search, replace, disable_case_transmission)
        result = result:gsub(search, replace_with_case)
        if not disable_case_transmission then
            search = search:lower()
            replace = replace:lower()
            result = result:gsub(search, replace)
        end
    end
    return result
end

local correctSpellingTable = {
	{"Source", "Sauce"},
	{"Classic", "Clbuttic"},
	{"Administrator", "[[WP:ROGUE|Rogue admin]]"},
	{"Editor", "[[WP:ROGUEE|Rogue editor]]"},
	{"Protected version", "[[m:The Wrong Version|Wrong version]]", true},
	{"Jimmy Wales", "[[User:Jimbo Wales|Wikipedia's corrupt dictator]]", true},
	{"(User:)?Jimbo Wales", "[[User:Jimbo Wales|Wikipedia's corrupt dictator]]", true},
	{"Uncyclopedia", "[[Uncyclopedia|a reputable source of objective information]]", true}
}
function p.main(frame)
	return frame:preprocess(frame.args[1]:spellChecker(correctSpellingTable))
end

return p